ionic-vhframeworks 4.1.5 → 4.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/router"),require("vhmongo"),require("@ionic-native/image-picker/ngx"),require("@ionic-native/ionic-webview/ngx"),require("@ionic-native/camera/ngx"),require("@capacitor/device"),require("ngx-socket-io"),require("rxjs"),require("@ionic-native/in-app-purchase-2/ngx"),require("@ionic/angular"),require("@angular/common"),require("@angular/platform-browser"),require("ngx-papaparse"),require("@ionic-native/social-sharing/ngx"),require("@ionic-native/file/ngx"),require("xlsx"),require("cleave.js"),require("cleave.js/dist/addons/cleave-phone.i18n"),require("ngx-mqtt"),require("@ionic-native/wifi-wizard-2/ngx"),require("@ionic-native/bluetooth-serial/ngx"),require("dom-to-image"),require("@ngx-translate/core"),require("@angular/common/http"),require("@ionic-native/file/ngx/index"),require("@ionic-native/social-sharing/ngx/index")):"function"==typeof define&&define.amd?define("ionic-vhframeworks",["exports","@angular/core","@angular/router","vhmongo","@ionic-native/image-picker/ngx","@ionic-native/ionic-webview/ngx","@ionic-native/camera/ngx","@capacitor/device","ngx-socket-io","rxjs","@ionic-native/in-app-purchase-2/ngx","@ionic/angular","@angular/common","@angular/platform-browser","ngx-papaparse","@ionic-native/social-sharing/ngx","@ionic-native/file/ngx","xlsx","cleave.js","cleave.js/dist/addons/cleave-phone.i18n","ngx-mqtt","@ionic-native/wifi-wizard-2/ngx","@ionic-native/bluetooth-serial/ngx","dom-to-image","@ngx-translate/core","@angular/common/http","@ionic-native/file/ngx/index","@ionic-native/social-sharing/ngx/index"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["ionic-vhframeworks"]={},t.ng.core,t.ng.router,t.vhmongo,t[" @ionic-native/image-picker/ngx"],t["@ionic-native/ionic-webview/ngx"],t["@ionic-native/camera/ngx"],t["@capacitor/device"],t["ngx-socket-io"],t.rxjs,t["@ionic-native/in-app-purchase-2/ngx"],t["@ionic/angular"],t.ng.common,t.ng.platformBrowser,t["ngx-papaparse"],t["@ionic-native/social-sharing/ngx"],t["@ionic-native/file/ngx"],t.xlsx,t.cleave.js,null,t["ngx-mqtt"],t["@ionic-native/wifi-wizard-2/ngx"],t["@ionic-native/bluetooth-serial/ngx"],t["dom-to-image"],t["@ngx-translate/core"],t.ng.common.http,t["@ionic-native/file/ngx/index"],t["@ionic-native/social-sharing/ngx/index"])}(this,(function(t,e,n,o,i,a,s,r,l,c,u,d,_,p,b,f,h,y,m,v,g,x,q,w,P,D,k,A){"use strict";function S(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var O=S(m),$=S(w);Object.create;function C(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],o=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&o>=t.length&&(t=void 0),{value:t&&t[o++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function j(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var o,i,a=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(o=a.next()).done;)s.push(o.value)}catch(t){i={error:t}}finally{try{o&&!o.done&&(n=a.return)&&n.call(a)}finally{if(i)throw i.error}}return s}function E(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(j(arguments[e]));return t}Object.create;function B(t,e,n){var o="";if("time"===e)o="HH:mm:ss";else if("date"===e)o="dd/MM/YYYY";else if("datetime"===e)o="dd/MM/YYYY HH:mm:ss";else{if("YYYY-MM-dd HH:mm:ss"!==e)return"wrong format";o="YYYY-MM-dd HH:mm:ss"}return _.formatDate(t,o,"en-VI")}var L=function(){function t(t,e,n,o,i){this.platform=t,this.file=e,this.socialSharing=n,this.papa=o,this.dom=i}return t.prototype.deepObjectEqual=function(t,e){var n,o,i=Object.keys(t),a=Object.keys(e);if(i.length!==a.length)return!1;try{for(var s=C(i),r=s.next();!r.done;r=s.next()){var l=r.value,c=t[l],u=e[l],d=this.isObject(c)&&this.isObject(u);if(d&&!this.deepObjectEqual(c,u)||!d&&c!==u)return!1}}catch(t){n={error:t}}finally{try{r&&!r.done&&(o=s.return)&&o.call(s)}finally{if(n)throw n.error}}return!0},t.prototype.isObject=function(t){return null!=t&&null!=t&&"object"==typeof t},t.prototype.ObjectId=function(t){null==t&&(t=24);for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",n="";t>0;)n+=e.charAt(Math.floor(Math.random()*e.length)),t--;return n},t.prototype.importXLSX=function(t){return new Promise((function(e,n){var o=new FileReader;o.readAsArrayBuffer(t),o.onload=function(t){for(var n=o.result,i=new Uint8Array(n),a=new Array,s=0;s!=i.length;++s)a[s]=String.fromCharCode(i[s]);var r=a.join(""),l=y.read(r,{type:"binary"}),c=l.SheetNames[0],u=l.Sheets[c],d=y.utils.sheet_to_json(u,{raw:!0});e(d)}}))},t.prototype.exportXLSX=function(t,e){var n=this;return new Promise((function(o,i){var a={Sheets:{data:y.utils.json_to_sheet(t)},SheetNames:["data"]},s=y.write(a,{bookType:"xlsx",type:"array"}),r=new Blob([s],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8"});if(n.platform.is("desktop")||n.platform.is("mobileweb")){var l=window.document.createElement("a");l.href=window.URL.createObjectURL(r),l.download=e+".xlsx",document.body.appendChild(l),l.click(),document.body.removeChild(l),o(null)}else n.file.writeFile(n.file.dataDirectory,e+".xlsx",r,{replace:!0}).then((function(t){n.socialSharing.share(e+".xlsx",e+".xlsx",t.nativeURL).then((function(){return o(null)})).catch((function(t){console.error(t),i(t)}))}))}))},t.prototype.importCSV=function(t){var e=this,n=t||"";return new Promise((function(t,o){e.papa.parse(n,{complete:function(e){var n=e.data.splice(0,1)[0],o=e.data;t({headerRow:n,csvData:o})}})}))},t.prototype.exportCSV=function(t,e,n){var o=this.papa.unparse({fields:t,data:e}),i=new Blob(["\ufeff",o]),a=window.document.createElement("a");a.href=window.URL.createObjectURL(i),a.download=n+".csv",document.body.appendChild(a),a.click(),document.body.removeChild(a)},t.prototype.waitingStack=function(){return new Promise((function(t,e){setTimeout((function(){t(null)}),0)}))},t.prototype.searchList=function(t,e,n){var o=this;new Array;return e.filter((function(e){for(var i=!1,a=0;a<n.length;a++)e[n[a]]&&(i=i||-1!==o.changeAlias(e[n[a]].toString().toLowerCase()).indexOf(o.changeAlias(t)));return!!i}))},t.prototype.changeAlias=function(t){var e=t;return e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=e.toLowerCase()).replace(/à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ/g,"a")).replace(/è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ/g,"e")).replace(/ì|í|ị|ỉ|ĩ/g,"i")).replace(/ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ/g,"o")).replace(/ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ/g,"u")).replace(/ỳ|ý|ỵ|ỷ|ỹ/g,"y")).replace(/đ/g,"d")).replace(/!|@|%|\^|\*|\(|\)|\+|\=|\<|\>|\?|\/|,|\.|\:|\;|\'|\"|\&|\#|\[|\]|~|\$|_|`|-|{|}|\||\\/g," ")).replace(/ + /g," ")).trim()},t.prototype.createBillCode=function(t){var e=Math.random().toString(36).substr(2,4),n=t?new Date(t):new Date;return(e+(1==(n.getMonth()+1).toString().length?"0"+(n.getMonth()+1).toString():(n.getMonth()+1).toString())+(1==n.getUTCDate().toString().length?"0"+n.getUTCDate().toString():n.getUTCDate().toString())).toUpperCase()},t.prototype.createPaymentCode=function(t){var e=Math.random().toString(36).substr(2,6),n=t?new Date(t):new Date;return(e+(1==(n.getMonth()+1).toString().length?"0"+(n.getMonth()+1).toString():(n.getMonth()+1).toString())+(1==n.getUTCDate().toString().length?"0"+n.getUTCDate().toString():n.getUTCDate().toString())).toUpperCase()},t.prototype.createCardCode=function(t){var e=Math.random().toString(36).substr(2,6),n=t?new Date(t):new Date;return(e+(1==(n.getMonth()+1).toString().length?"0"+(n.getMonth()+1).toString():(n.getMonth()+1).toString())+(1==n.getUTCDate().toString().length?"0"+n.getUTCDate().toString():n.getUTCDate().toString())).toUpperCase()},t.prototype.vhcurrencyunit=function(t){var e=localStorage.getItem("vhsales_currencyFormat");if(e){var n=JSON.parse(String(e)).digitDecimal.value,o=void 0;return 0===n?o="1.0-0":1===n?o="1.1-1":2===n?o="1.2-2":3===n?o="1.3-3":4===n?o="1.4-4":5===n&&(o="1.5-5"),_.formatCurrency(t,"en-VI",_.getCurrencySymbol("","wide"),"",o)}},t.prototype.vhcurrencyunit_symbol=function(t){var e=localStorage.getItem("vhsales_currencyFormat");if(e){var n=JSON.parse(String(e)).digitDecimal.value,o=void 0;0===n?o="1.0-0":1===n?o="1.1-1":2===n?o="1.2-2":3===n?o="1.3-3":4===n?o="1.4-4":5===n&&(o="1.5-5");var i=JSON.parse(String(e)).symbol.text,a=JSON.parse(String(e)).position.value,s="",r="";0===a?s=i+" ":1===a&&(r=" "+i);var l=/\(([^)]+)\)/,c=l.exec(s);c&&(s=c[1]);var u=l.exec(r);return u&&(r=u[1]),s+_.formatCurrency(t,"en-VI",_.getCurrencySymbol("","wide"),"",o)+r}},t.prototype.vhpercent=function(t){return _.formatPercent(t,"en-VI","1.2-2")},t.prototype.vhnumeral=function(t){return new O.default(t,{numeral:!0,numeralThousandsGroupStyle:"thousand"})},t.prototype.vhphoneNumber=function(t){return new O.default(t,{phone:!0,phoneRegionCode:"VN"})},t.prototype.vhYoutubeLink=function(t){return this.dom.bypassSecurityTrustResourceUrl("https://www.youtube.com/embed/"+t)},t.prototype.sortVietnamesebyASC=function(t,e){var n=this;return t.sort((function(t,o){return n.changeAlias(t[e])>n.changeAlias(o[e])?1:-1}))},t.prototype.sortVietnamesebyDESC=function(t,e){var n=this;return t.sort((function(t,o){return n.changeAlias(t[e])<n.changeAlias(o[e])?1:-1}))},t.prototype.sortDatebyASC=function(t,e){return t.sort((function(t,n){return new Date(t[e]).getTime()>new Date(n[e]).getTime()?1:-1}))},t.prototype.sortDatebyDESC=function(t,e){return t.sort((function(t,n){return new Date(t[e]).getTime()<new Date(n[e]).getTime()?1:-1}))},t.prototype.sortStringbyASC=function(t,e){return t.sort((function(t,n){return t[e].toUpperCase()>n[e].toUpperCase()?1:-1}))},t.prototype.sortStringbyDESC=function(t,e){return t.sort((function(t,n){return t[e].toUpperCase()<n[e].toUpperCase()?1:-1}))},t.prototype.sortNumberbyASC=function(t,e){return t.sort((function(t,n){return t[e]>n[e]?1:-1}))},t.prototype.sortNumberbyDESC=function(t,e){return t.sort((function(t,n){return t[e]<n[e]?1:-1}))},t.prototype.getNumberOfDaysInMonth=function(t,e){switch(e){case 1:case 3:case 5:case 7:case 8:case 10:case 12:return 31;case 2:return t%400==0||t%4==0&&t%100!=0?29:28;default:return 30}},t.prototype.Compare=function(t,e,n){return"=="===e?t==n:">"===e?t>n:">="===e?t>=n:"<"===e?t<n:"<="===e?t<=n:void 0},t.prototype.convert_STRING2OBJECT=function(t){try{return JSON.parse(t)}catch(t){return{}}},t.prototype.convert_OBJECT2STRING=function(t){return"object"==typeof t?JSON.stringify(t):""},t}();L.ɵprov=e.ɵɵdefineInjectable({factory:function(){return new L(e.ɵɵinject(d.Platform),e.ɵɵinject(k.File),e.ɵɵinject(A.SocialSharing),e.ɵɵinject(b.Papa),e.ɵɵinject(p.DomSanitizer))},token:L,providedIn:"root"}),L.decorators=[{type:e.Injectable,args:[{providedIn:"root"}]}],L.ctorParameters=function(){return[{type:d.Platform},{type:h.File},{type:f.SocialSharing},{type:b.Papa},{type:p.DomSanitizer}]};var I=function(){function t(t,e){this.vhmongo_firebase=t,this.vhAlgorithm=e}return t.prototype.addAPPdatabase_forFirstTime=function(){var t=this;return new Promise((function(e,n){if("vhsales"===t.vhmongo_firebase.auth().getProjectName()||"bvhsales"===t.vhmongo_firebase.auth().getProjectName())(o=new Array)[0]=t.addSales_branch(),o[1]=t.addSales_id_retail(),o[2]=t.addSales_tax(),o[3]=t.addSales_category_product(),o[4]=t.addSales_supplier(),o[5]=t.addSales_customer(),o[6]=t.addSales_wallet_Cash(),o[7]=t.addSales_incoming_group(),o[8]=t.addSales_spending_group(),Promise.all(o).then((function(){e(null)}),(function(t){e(t)}));else if("vhsmhome"===t.vhmongo_firebase.auth().getProjectName())e(null);else if("vhcafe"===t.vhmongo_firebase.auth().getProjectName()||"bvhcafe"===t.vhmongo_firebase.auth().getProjectName()){var o;(o=new Array)[0]=t.addCafe_branch(),o[1]=t.addSales_id_retail(),o[2]=t.addSales_tax(),o[3]=t.addCafe_category_product(),o[4]=t.addSales_supplier(),o[5]=t.addSales_customer(),o[6]=t.addSales_wallet_Cash(),o[7]=t.addCafe_area_table_GoHome(),o[8]=t.addSales_incoming_group(),o[9]=t.addSales_spending_group(),Promise.all(o).then((function(){e(null)}),(function(t){e(t)}))}else"vhcloudcam"===t.vhmongo_firebase.auth().getProjectName()||"securitycam"===t.vhmongo_firebase.auth().getProjectName()||"bsecuritycam"===t.vhmongo_firebase.auth().getProjectName()?t.vhmongo_firebase.f3rdclouds().createEUtokenFromUtoken().then((function(o){0===o.vcode?t.vhmongo_firebase.f3rdclouds().saveEUtokenToDatabase(o.eutoken).then((function(){e(!0)}),(function(t){n(t)})):e(!1)}),(function(t){n(t)})):("vhcare"===t.vhmongo_firebase.auth().getProjectName()||"vhclouds"===t.vhmongo_firebase.auth().getProjectName()||console.log("Lưu ý, projectname này không khởi tạo giá trị: ",t.vhmongo_firebase.auth().getProjectName()),e(null))}))},t.prototype.addAPPdatabase_forFirstTime_Sales_Cafe=function(){var t=this;return new Promise((function(e,n){if("vhsales"===t.vhmongo_firebase.auth().getProjectName()||"bvhsales"===t.vhmongo_firebase.auth().getProjectName())(o=new Array)[0]=t.addSales_id_retail(),o[1]=t.addSales_tax(),o[2]=t.addSales_category_product(),o[3]=t.addSales_supplier(),o[4]=t.addSales_customer(),o[5]=t.addSales_wallet_Cash(),o[6]=t.addSales_incoming_group(),o[7]=t.addSales_spending_group(),Promise.all(o).then((function(){e(null)}),(function(t){e(t)}));else if("vhcafe"===t.vhmongo_firebase.auth().getProjectName()||"bvhcafe"===t.vhmongo_firebase.auth().getProjectName()){var o;(o=new Array)[0]=t.addSales_id_retail(),o[1]=t.addSales_tax(),o[2]=t.addCafe_category_product(),o[3]=t.addSales_supplier(),o[4]=t.addSales_customer(),o[5]=t.addSales_wallet_Cash(),o[6]=t.addCafe_area_table_GoHome(),o[7]=t.addSales_incoming_group(),o[8]=t.addSales_spending_group(),Promise.all(o).then((function(){e(null)}),(function(t){e(t)}))}else console.log("Lưu ý, projectname này không khởi tạo giá trị: ",t.vhmongo_firebase.auth().getProjectName()),e(null)}))},t.prototype.addSales_id_retail=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().addDocbyID("customers","id_retail",{name:"Retail customer"}).then((function(){e(null)}),(function(t){n(t)}))}))},t.prototype.addSales_tax=function(){var t=this;return new Promise((function(e,n){var o=t.vhmongo_firebase.database().addDoc("taxs",{name:"VAT",value:0,status:!0,default:!0}),i=t.vhmongo_firebase.database().addDoc("taxs",{name:"VAT",value:5,status:!0,default:!1}),a=t.vhmongo_firebase.database().addDoc("taxs",{name:"VAT",value:10,status:!0,default:!1});Promise.all([o,i,a]).then((function(){e(null)}),(function(t){e(t)}))}))},t.prototype.addSales_category_product=function(){var t=this;return new Promise((function(e,n){var o=new Promise((function(e,n){t.vhmongo_firebase.database().addDoc("categorys",{name:"Danh mục sản phẩm",type:1}).then((function(n){t.vhmongo_firebase.database().addDoc("products",{id_category:n._id,allow_sell:!0,barcode:"0123456789",brand:"APPLE",cost_stock_last:0,img:"./assets/img/default/iphone-12-pro-max-512gb.jpg",name:"Iphone 12 Pro Max 512Gb",price:2e7,price_import:18e6,quantity:0,quantity_branch:{},unit:"Cái",warning_number:2,type:1}).then((function(){e(null)}))}))})),i=new Promise((function(e,n){t.vhmongo_firebase.database().addDoc("categorys",{name:"Danh mục dịch vụ",type:2}).then((function(n){t.vhmongo_firebase.database().addDoc("products",{id_category:n._id,allow_sell:!0,barcode:"1122334455",img:"./assets/img/default/bao-duong-ve-sinh-laptop.jpg",name:"Phí bảo dưỡng, vệ sinh laptop",price:1e5,unit:"Cái",type:2}).then((function(){e(null)}))}))})),a=new Promise((function(e,n){t.vhmongo_firebase.database().addDocbyID("categorys","id_category_combo",{name:"Danh mục món kết hợp",type:5}).then((function(){e(null)}),(function(t){n(t)}))}));Promise.all([o,i,a]).then((function(){e(null)}),(function(t){e(t)}))}))},t.prototype.addSales_supplier=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().addDoc("suppliers",{address:"116/18 Thiên Phước, F9, Tân Bình",email:"viethas.info@gmail.com",name:"Công Ty TNHH GPCN VIETHAS",note:"không có",phone:"02838661111",taxcode:"312122525"}).then((function(){e(null)}),(function(t){n(t)}))}))},t.prototype.addSales_customer=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().addDoc("customers",{address:"115 đường TL8, phường Phú Mỹ",date:new Date,datebirth:new Date,debt_enable:!0,district:"Củ chi",email:"vanminh@gmail.com",gender:"Nam",name:"Nguyễn Văn Minh",note:" ",phone:"0971606060",province:"Hồ chí minh"}).then((function(){e(null)}),(function(t){n(t)}))}))},t.prototype.addSales_wallet_Cash=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().addDocbyID("wallets","id_cash",{name:"Cash"}).then((function(){e(null)}),(function(t){n(t)}))}))},t.prototype.addSales_incoming_group=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().addDoc("incoming_groups",{name:"Thu khác",default:!0}).then((function(){e(null)}),(function(t){n(t)}))}))},t.prototype.addSales_spending_group=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().addDoc("spending_groups",{name:"Chi khác",default:!0}).then((function(){e(null)}),(function(t){n(t)}))}))},t.prototype.addSales_wallet=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("wallets",{address:"Hồ chí minh",bank_name:"Ngân Hàng Ngoại Thương",holder:"Trương Thị Thu Hương",name:"Vietcombank",note:"",number:"1940201041052",id_branch:t}).then((function(){n(null)}),(function(t){o(t)}))}))},t.prototype.addSales_branch=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().addDoc("branchs",{name:"Chi nhánh 1",address:t.vhmongo_firebase.auth().getUser().address,countrycode:t.vhmongo_firebase.auth().getUser().countrycode,phone:t.vhmongo_firebase.auth().getUser().phone,email:t.vhmongo_firebase.auth().getUser().email,company:t.vhmongo_firebase.auth().getUser().company,active:!0}).then((function(n){var o=t.addSales_StoreInfo(n._id),i=t.addSales_wallet(n._id);Promise.all([o,i]).then((function(){e(null)}))}),(function(t){n(t)}))}))},t.prototype.addCafe_branch=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().addDoc("branchs",{name:"Chi nhánh 1",address:t.vhmongo_firebase.auth().getUser().address,countrycode:t.vhmongo_firebase.auth().getUser().countrycode,phone:t.vhmongo_firebase.auth().getUser().phone,email:t.vhmongo_firebase.auth().getUser().email,company:t.vhmongo_firebase.auth().getUser().company,active:!0}).then((function(n){var o=t.addSales_StoreInfo(n._id),i=t.addSales_wallet(n._id),a=t.addCafe_area_table(n._id);Promise.all([o,i,a]).then((function(){e(null)}))}),(function(t){n(t)}))}))},t.prototype.addSales_StoreInfo=function(t){var e=this;return new Promise((function(n,o){var i=e.vhmongo_firebase.auth().getStore(),a={name:i.name,phone:i.phone,countrycode:null==i?void 0:i.countrycode,address:i.address,company:i.company,email:i.email,tax_number:"",opentime:"8h:00 AM",closetime:"10h:00 PM",img:"",appsetting_name:"store_info"};a.id_branch=t,e.vhmongo_firebase.database().addDoc("appsettingbranchs",a).then((function(){n(null)}),(function(t){o(t)}))}))},t.prototype.addCafe_category_product=function(){var t=this;return new Promise((function(e,n){var o=new Array;o[0]=new Promise((function(e,n){t.vhmongo_firebase.database().addDoc("categorys",{name:"Danh mục nước pha chế",type:1}).then((function(o){t.vhmongo_firebase.database().addDoc("products",{id_category:o._id,allow_sell:!0,describe:"",img:"./assets/img/default/ca-phe-sua-da.jpg",name:"Cà phê sửa đá",type:1,unit:"Ly",price:25e3,price_import:2e4,time_warning:5,manysize:!1}).then((function(){e(null)}),(function(t){n(t)}))}),(function(t){n(t)}))})),o[1]=new Promise((function(e,n){t.vhmongo_firebase.database().addDoc("categorys",{name:"Danh mục món ăn",type:1}).then((function(o){t.vhmongo_firebase.database().addDoc("products",{id_category:o._id,allow_sell:!0,describe:"",img:"./assets/img/default/com-chien-hai-san.jpg",name:"Cơm chiên hải sản",type:1,unit:"Dĩa",time_warning:15,manysize:!0,subs:[{_id:t.vhAlgorithm.ObjectId(),price:149e3,name:"Size lớn"},{_id:t.vhAlgorithm.ObjectId(),price:99e3,name:"Size nhỏ"}]}).then((function(){e(null)}),(function(t){n(t)}))}),(function(t){n(t)}))})),o[2]=new Promise((function(e,n){t.vhmongo_firebase.database().addDoc("categorys",{name:"Danh mục dịch vụ",type:2}).then((function(n){t.vhmongo_firebase.database().addDoc("products",{id_category:n._id,img:"./assets/img/default/phong-vip.jpg",name:"Phòng VIP",price:1e5,type:2,unit:"Giờ",allow_sell:!0}).then((function(){e(null)}))}))})),o[3]=new Promise((function(e,n){t.vhmongo_firebase.database().addDoc("categorys",{name:"Danh mục nước đóng sẳn",type:3}).then((function(o){t.vhmongo_firebase.database().addDoc("products",{id_category:o._id,describe:"",img:"./assets/img/default/coca-cola.jpg",name:"Coca cola",price_import:15e3,price:2e4,type:3,unit:"Lon",allow_sell:!0,time_warning:10,warning_number:5,quantity:0,quantity_branch:{}}).then((function(){e(null)}),(function(t){n(t)}))}),(function(t){n(t)}))})),o[4]=new Promise((function(e,n){t.vhmongo_firebase.database().addDoc("categorys",{name:"Danh mục nguyên liệu",type:3}).then((function(n){t.vhmongo_firebase.database().addDoc("products",{id_category:n._id,describe:"",img:"./assets/img/default/nuoc-mam-nam-ngu-750ml.jpg",name:"Nguyên liệu mẫu",price_import:2e4,price:3e4,type:3,unit:"Chai",allow_sell:!1,warning_number:5,quantity:0,quantity_branch:{}}).then((function(){e(null)}))}))})),o[5]=new Promise((function(e,n){t.vhmongo_firebase.database().addDocbyID("categorys","id_category_topping",{name:"Danh mục món bán kèm",type:4}).then((function(){e(null)}),(function(t){n(t)}))})),o[6]=new Promise((function(e,n){t.vhmongo_firebase.database().addDocbyID("categorys","id_category_combo",{name:"Danh mục món kết hợp",type:5}).then((function(){e(null)}),(function(t){n(t)}))})),Promise.all(o).then((function(){e(null)}),(function(t){e(t)}))}))},t.prototype.addCafe_area_table_GoHome=function(){var t=this;return new Promise((function(e,n){var o=t.vhmongo_firebase.database().addDocbyID("areas","go_home",{name:"Take away",status:!0}).then((function(){e(null)}),(function(t){n(t)})),i=t.vhmongo_firebase.database().addDocbyID("tables","go_home",{id_area:"go_home",name:"Take away",status:!0}).then((function(){e(null)}),(function(t){n(t)}));Promise.all([o,i]).then((function(){e(!0)}),(function(t){e(t)}))}))},t.prototype.addCafe_area_table=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("areas",{name:"Area 1",status:!0,id_branch:t}).then((function(o){e.vhmongo_firebase.database().addDoc("tables",{id_area:o._id,name:"Table 1",status:!1,id_branch:t}).then((function(){n(null)}))}))}))},t}();I.decorators=[{type:e.Injectable}],I.ctorParameters=function(){return[{type:o.Vhmongo_firebase},{type:L}]};var F=function(){function t(t,e,n){var o=this;this.vhmongo_firebase=t,this.vhForFirstTime=e,this.renderFactory=n,this.mypermission={},this.employees=new Array,this.endusers=new Array,this.appsetting_stations=new Array,this.hwinfo={},this.subjectemployees=new c.Subject,r.Device.getId().then((function(t){var e=o.localStorageGET("hwinfo");null!=e&&null!=e?o.hwinfo=e:(o.hwinfo=Object.assign({},t),o.localStorageSET("hwinfo",o.hwinfo))})),this.renderer=this.renderFactory.createRenderer(null,null)}return t.prototype.signInWithEmailAndPasswordOfEndUser=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.auth().signInWithEmailAndPasswordOfEndUser(t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.onAuthStateChangedOfEndUser=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.auth().onAuthStateChangedOfEndUser().then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.signInWithEmailAndPassword=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.auth().signInWithEmailAndPassword(t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.onAuthStateChanged=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.auth().onAuthStateChanged().then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.signUpOwner_Sales=function(t,e,n,o){var i=this;return new Promise((function(a,s){i.vhmongo_firebase.auth().signUpOwner_Sales(t,e,n,o).then((function(n){console.log("owner1",n),i.signInWithEmailAndPassword_Sales(t,e).then((function(){console.log("owner2",n),i.vhForFirstTime.addAPPdatabase_forFirstTime_Sales_Cafe().then((function(){console.log("owner3",n),a(n),i.signOut()}))}))}),(function(t){s(t)}))}))},t.prototype.signInWithEmailAndPassword_Sales=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.auth().signInWithEmailAndPassword_Sales(t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.onAuthStateChanged_Sales=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.auth().onAuthStateChanged_Sales().then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.signUpOwner_Cafe=function(t,e,n,o){var i=this;return new Promise((function(a,s){i.vhmongo_firebase.auth().signUpOwner_Cafe(t,e,n,o).then((function(n){console.log("owner1",n),i.signInWithEmailAndPassword_Cafe(t,e).then((function(){console.log("owner2",n),i.vhForFirstTime.addAPPdatabase_forFirstTime_Sales_Cafe().then((function(){console.log("owner3",n),a(n),i.signOut()}))}))}),(function(t){s(t)}))}))},t.prototype.signInWithEmailAndPassword_Cafe=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.auth().signInWithEmailAndPassword_Cafe(t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.onAuthStateChanged_Cafe=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.auth().onAuthStateChanged_Cafe().then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.signOut=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.auth().signOut().then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.resetPasswordbyEmail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.auth().sendPasswordResetEmail(t).then((function(){n(!0)})).catch((function(){n(!1)}))}))},t.prototype.getProjectName=function(){return this.vhmongo_firebase.auth().getProjectName()},t.prototype.getUser=function(){return this.vhmongo_firebase.auth().getUser()},t.prototype.getUID=function(){return this.vhmongo_firebase.auth().getUID()},t.prototype.getUUID=function(){return this.hwinfo},t.prototype.getToken=function(){return this.vhmongo_firebase.auth().getToken()},t.prototype.getDBCloudURL=function(){return this.vhmongo_firebase.auth().getDBCloudURL()},t.prototype.getStore=function(){return this.vhmongo_firebase.auth().getStore()},t.prototype.getDBstorage=function(){return this.vhmongo_firebase.auth().getDBstorage()},t.prototype.newDate=function(t){return"firebase-mongo"===this.vhmongo_firebase.auth().getDBstorage()?new Date(t):"firebase"===this.vhmongo_firebase.auth().getDBstorage()?t.toDate():void 0},t.prototype.initializeDB=function(t){},t.prototype.initializeProject=function(t,e,n,o,i,a){if(!(394637==i||932012==i))return null;this.vhmongo_firebase.initializeProject(t,e,n,o,a)},t.prototype.initializeWebAppProject=function(t,e,n){if(!(394637==e||932012==e))return null;this.vhmongo_firebase.initializeWebAppProject(t,n)},t.prototype.runOnMGDBServerVersion=function(t){this.vhmongo_firebase.runOnMGDBServerVersion(t)},t.prototype.runOnCamServerVersion=function(t){this.vhmongo_firebase.runOnCamServerVersion(t)},t.prototype.localStorageSET=function(t,e){"object"==typeof e?localStorage.setItem(this.vhmongo_firebase.auth().getProjectName()+"_"+t,JSON.stringify(e)):localStorage.setItem(this.vhmongo_firebase.auth().getProjectName()+"_"+t,e)},t.prototype.localStorageGET=function(t){return JSON.parse(localStorage.getItem(this.vhmongo_firebase.auth().getProjectName()+"_"+t))},t.prototype.signUpOwner=function(t,e,n,o){var i=this;return new Promise((function(a,s){i.vhmongo_firebase.auth().signUpOwner(t,e,n,o).then((function(n){i.signInWithEmailAndPassword(t,e).then((function(){i.vhForFirstTime.addAPPdatabase_forFirstTime().then((function(){a(n),i.signOut()}))}))}),(function(t){s(t)}))}))},t.prototype.signUpMember=function(t,e,n,o){var i=this;return new Promise((function(a,s){i.vhmongo_firebase.auth().signUpMember(t,e,n,o).then((function(t){a(t)}),(function(t){s(t)}))}))},t.prototype.signUpEndUser=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=Object.assign({},o);r.eucode=Math.random().toString(10).substr(2,11),i.vhmongo_firebase.auth().signUpEndUser(t,e,n,r).then((function(t){a(t)}),(function(t){s(t)}))}))},t.prototype.getLocalMyPermission=function(){return this.mypermission},t.prototype.refreshLocalMyPermission=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDoc("vhpermissions",t.getUser()._id).then((function(n){n&&(t.mypermission=n),e(null)}),(function(t){n(t)}))}))},t.prototype.checkMyPermission=function(t){return"boss"==this.getUser().owner||!!this.getLocalMyPermission()[t]},t.prototype.checkLocalMyPermissionName=function(t){return"boss"==this.getUser().owner||!!this.getLocalMyPermission()[t]},t.prototype.getLocalMyPermissionName=function(t){if("boolean"!=typeof this.getLocalMyPermission()[t])return this.getLocalMyPermission()[t]},t.prototype.updatePermission=function(t,e){var n=this;return new Promise((function(o,i){n.getPermission(t).then((function(a){a?n.vhmongo_firebase.database().updateDoc("vhpermissions",t,e).then((function(t){o(t)}),(function(t){i(t)})):n.vhmongo_firebase.database().addDocbyID("vhpermissions",t,e).then((function(){o(!0)}),(function(t){i(t)}))}),(function(t){i(t)}))}))},t.prototype.getPermission=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("vhpermissions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.publishObservableEventEmployees=function(){this.subjectemployees.next(this.employees)},t.prototype.observableLocalEmployees=function(){return this.subjectemployees},t.prototype.getObservableLocalEmployees=function(){var t=this;return new c.Observable((function(e){t.observableLocalEmployees().subscribe((function(t){e.next(t)})),t.publishObservableEventEmployees()}))},t.prototype.clearLocalEmployeeFromSyncCollection=function(){this.employees=new Array},t.prototype.deleteLocalEmployeeFromSyncCollection=function(t){for(var e=!1,n=0;n<this.employees.length;n++)if(this.employees[n]._id===t){this.employees.splice(n,1),e=!0;break}return e},t.prototype.updateLocalEmployeeFromSyncCollection=function(t,e){for(var n=!1,o=0;o<this.employees.length;o++)if(this.employees[o]._id===t){this.employees[o]=Object.assign(Object.assign({},this.employees[o]),e),n=!0;break}return n},t.prototype.insertlocalEmployeeFromSyncCollection=function(t){var e=!1;return this.getlocalEmployee(t._id)||(this.employees.push(t),e=!0),e},t.prototype.getlocalEmployee=function(t){for(var e=0;e<this.employees.length;e++)if(this.employees[e]._id===t)return this.employees[e];return null},t.prototype.getlocalEmployees=function(){return this.employees},t.prototype.refreshLocalEmployees=function(){return new Promise((function(t,e){t(null)}))},t.prototype.updateEmployee=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("vhemployees",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteEmployee=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("bills",{id_employee:{$eq:t}},{},{},1).then((function(i){0===i.length?e.getEmployee(t).then((function(i){return i?"member"!=i.owner?n(!1):void e.getPermission(t).then((function(i){i&&e.vhmongo_firebase.database().deleteDoc("vhpermissions",t),e.vhmongo_firebase.database().deleteDoc("vhemployees",t).then((function(t){n(t)}),(function(t){o(t)}))}),(function(t){o(t)})):n(!1)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getEmployee=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("vhemployees",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getEmployees=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("vhemployees").then((function(n){t.employees=n,e(n)}),(function(t){n(t)}))}))},t.prototype.updateLocalEndUser=function(t,e){for(var n=0;n<this.endusers.length;n++)if(this.endusers[n]._id===t){this.endusers[n]=Object.assign(Object.assign({},this.endusers[n]),e);break}return!0},t.prototype.getlocalEndUser=function(t){for(var e=0;e<this.endusers.length;e++)if(this.endusers[e]._id===t)return this.endusers[e];return null},t.prototype.getlocalEndUsers=function(){return this.endusers},t.prototype.refreshLocalEndUsers=function(){var t=this;return new Promise((function(e,n){t.getEndUsers().then((function(){e(null)}))}))},t.prototype.updateEndUser=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("vhendusers",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteEndUser=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("bills",{id_employee:{$eq:t}},{},{},1).then((function(i){0===i.length?e.getEndUser(t).then((function(i){return i?"enduser"!=i.owner?n(!1):void e.getPermission(t).then((function(i){i&&e.vhmongo_firebase.database().deleteDoc("vhpermissions",t),e.vhmongo_firebase.database().deleteDoc("vhendusers",t).then((function(t){n(t)}),(function(t){o(t)}))}),(function(t){o(t)})):n(!1)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getEndUser=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("vhendusers",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getEndUsers=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("vhendusers").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.getEndUsers_byFields=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.database().getDocsByFields("vhendusers",t,{},n,o).then((function(t){e(t)}),(function(t){a(t)}))}))},t.prototype.getExistedCurrencyFormat=function(){var t=localStorage.getItem("vhsales_currencyFormat");return t?JSON.parse(String(t)):null},t.prototype.syncExistedCurrencyFormat=function(){localStorage.getItem("vhsales_currencyFormat")||localStorage.setItem("vhsales_currencyFormat",JSON.stringify({symbol:{text:"₫",value:5},position:{text:"1",value:0},digitDecimal:{text:"0",value:0},digitGroup:{text:"123,456",value:1}}))},t.prototype.getExistedTheme=function(){return localStorage.getItem("vh_theme")},t.prototype.setTheme=function(t){for(var e=Array.from(document.body.classList),n=0;n<e.length;n++)e[n].indexOf("-theme")>-1&&e.splice(n,1);document.body.className=e.join(" "),"vh-theme"!=t?(this.renderer.addClass(document.body,t),localStorage.setItem("vh_theme",t)):localStorage.removeItem("vh_theme")},t.prototype.syncExistedTheme=function(){var t=this.getExistedTheme();t&&this.setTheme(t)},t.prototype.changeThemeIcon=function(){var t=this.getExistedTheme();t?document.getElementsByClassName("color "+t)[0].click():document.getElementsByClassName("vh-theme")[0].click()},t.prototype.changeTheme=function(t,e){var n,o;try{for(var i=C(e.target.parentElement.children),a=i.next();!a.done;a=i.next()){a.value.innerHTML=""}}catch(t){n={error:t}}finally{try{a&&!a.done&&(o=i.return)&&o.call(i)}finally{if(n)throw n.error}}e.target.innerHTML='<ion-icon color="vh-white" src=\'data:image/svg+xml;utf8,\n <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"\n viewBox="0 0 600 600" style="enable-background:new 0 0 512 512;" xml:space="preserve"> \n <path d="M504.502,75.496c-9.997-9.998-26.205-9.998-36.204,0L161.594,382.203L43.702,264.311c-9.997-9.998-26.205-9.997-36.204,0\n c-9.998,9.997-9.998,26.205,0,36.203l135.994,135.992c9.994,9.997,26.214,9.99,36.204,0L504.502,111.7\n C514.5,101.703,514.499,85.494,504.502,75.496z"/> \n </svg>\'>\n </ion-icon>',this.setTheme(t)},t.prototype.getManualVideos=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getManualVideos(t).then((function(t){n(t)}),(function(t){o(t)}))}))},t}();F.decorators=[{type:e.Injectable}],F.ctorParameters=function(){return[{type:o.Vhmongo_firebase},{type:I},{type:e.RendererFactory2}]};var z=function(){function t(t,e,n){this.platform=t,this.router=e,this.vhmongo_firebase=n,this.licensecam="",this.filename="",this.camplaybackURL="",this._src="",this.randomId="cpb",this.oldrandomId="cpb",t.ready().then((function(){}))}return t.prototype.ngOnChanges=function(t){""!=this.filename&&""!=this.licensecam&&this.playbackVideo()},t.prototype.ngOnInit=function(){},t.prototype.playbackVideo=function(){var t=this;this.randomId=Math.random().toString(36).substr(2,5),document.getElementById(this.oldrandomId).id=this.randomId,this.camplayback=document.getElementById(this.randomId),this.oldrandomId=this.randomId,this.camplayback.src="",this.makePlaybackVideoByUser().then((function(e){if(e){var n="licensecam="+t.licensecam,o="rd="+t.randomId;t._src=t.camplaybackURL+"/cloudcamplayback/playbackvideo?"+n+"&filename=playbackvideo&"+o,t.camplayback.src=t._src}}))},t.prototype.ngOnDestroy=function(){document.getElementById(this.oldrandomId).src=""},t.prototype.feAdjustVideoPlaybackInFrame=function(t,e){var n;for(n=0;n<t.frames.length;n++)try{this.feAdjustVideoPlaybackInFrame(t.frames[n],e),t.frames[n].document.querySelector("video").playbackRate=e}catch(t){}},t.prototype.makePlaybackVideoByUser=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.clouds().makePlaybackVideoByUser(t.licensecam,t.camplaybackURL,t.filename).then((function(t){e(t)}),(function(t){n(t)}))}))},t}();z.decorators=[{type:e.Component,args:[{selector:"vh-camplayback",template:' \n <iframe id="cpb" allow="autoplay" allowfullscreen frameborder="0" style="object-fit: fill; width: 100%; height: 100%;" marginheight="0" marginwidth="0"> \n </iframe> \n '}]}],z.ctorParameters=function(){return[{type:d.Platform},{type:n.Router},{type:o.Vhmongo_firebase}]},z.propDecorators={licensecam:[{type:e.Input}],filename:[{type:e.Input}],camplaybackURL:[{type:e.Input}]};var T=function(){function t(t,o){var i=this;this.platform=t,this.router=o,this.url="",this.licensecam="",this.camliveURL="",this.poster="",this.roomid="",this.play=!0,this.monitor=1,this.os="android",this.change=new e.EventEmitter,this.list_camera=[],this._src="",this._video={},this._run=void 0,this._first_time=!0,this._play=!0,this._count=0,this._poster="",this.mime='video/mp4; codecs="avc1.640032"',this.video={},this.randomId="",this.integer=0,t.ready().then((function(){i.router.events.subscribe((function(t){(t instanceof n.NavigationEnd&&"/mobile/tabs/settings"===t.url||t instanceof n.NavigationEnd&&"/mobile/tabs/scripts"===t.url||t instanceof n.NavigationEnd&&"/mobile/tabs/scene"===t.url||t instanceof n.NavigationEnd&&"/mobile/tabs/play-back"===t.url)&&i._run&&i.stopVideo()})),i.randomId=Math.random().toString(36).substr(2,5),i._poster=localStorage.getItem(i.licensecam),document.getElementById("mse").id=i.randomId,i._play&&i.loadVideo()}))}return t.prototype.ngOnInit=function(){},t.prototype.ngOnChanges=function(t){this._play=this.play,null!=this._run&&(this._play?this._run||this.startVideo():this._run&&this.stopVideo())},t.prototype.ngOnDestroy=function(){this._run&&this.stopVideo(),console.log("destroyed camera")},t.prototype.loadVideo=function(){var t=this;console.log("loadVideo"),this.config={channelid:this.licensecam,channelname:this.licensecam,url:this.url,monitor:this.monitor,os:this.os};for(var e=0,n=0,o=new Array,i=0;i<10;i++)o[i]=0;this.video=document.getElementById(this.randomId),this.mediaSource=new MediaSource,this.video.src=URL.createObjectURL(this.mediaSource),this.subscription_listenMediaSource=this.listenMediaSource().subscribe((function(i){t.subscription_listenBuffer=t.listenBuffer().subscribe((function(i){t.mediaSource.duration!==Number.POSITIVE_INFINITY&&0===t.video.currentTime&&t.mediaSource.duration>0&&(t.video.currentTime=t.mediaSource.duration-1,t.mediaSource.duration=Number.POSITIVE_INFINITY),e=t.video.currentTime-n,n=t.video.currentTime;var a=0;if(0!=e){o[Math.round(e)]++;for(var s=0;s<o.length;s++)o[s]>a&&(a=o[s],t.integer=s);0!=t.integer&&(t.video.playbackRate=e/t.integer+.1)}}),(function(t){console.log(t)})),t._play?t.startVideo():(t._run=!1,t.change.emit({status:"loaded"}))}),(function(t){console.log(t)}))},t.prototype.startVideo=function(){this.change.emit({status:"play"}),this.config.monitor=this.monitor;var t=this,e="?channelid="+this.config.channelid+"&channelname="+this.config.channelname+"&url="+this.config.url+"&monitor="+this.config.monitor+"&os="+this.config.os;this.socket=new WebSocket(this.camliveURL+e),this.socket.addEventListener("open",(function(t){})),this.socket.addEventListener("message",(function(e){new Blob([e.data],{type:"image/jpeg"}).arrayBuffer().then((function(e){var n=new Uint8Array(e);t.buffer.appendBuffer(n),5==t._count&&t.getScreenshot(),t._count++}))})),this.video.muted=!0,this._run=!0,console.log("startVideo")},t.prototype.stopVideo=function(){this.video.pause(),this._run=!1,this.socket.removeAllListeners(),this.socket.close(),console.log("stopVideo")},t.prototype.listenMediaSource=function(){var t=this,e=this;return c.Observable.create((function(n){t.mediaSource.addEventListener("updateend",(function(t){console.log("updateend: "+e.mediaSource.readyState)})),t.mediaSource.addEventListener("sourceended",(function(t){console.log("sourceended: "+e.mediaSource.readyState)})),t.mediaSource.addEventListener("sourceclose",(function(t){console.log("sourceclose: "+e.mediaSource.readyState)})),t.mediaSource.addEventListener("error",(function(t){console.log("error: "+e.mediaSource.readyState)})),t.mediaSource.addEventListener("sourceopen",(function(t){n.next("sourceopen")}),!0)}))},t.prototype.listenBuffer=function(){var t=this;return c.Observable.create((function(e){t.buffer=t.mediaSource.addSourceBuffer(t.mime),t.buffer.mode="sequence",t.buffer.addEventListener("updateend",(function(t){e.next("updateend")}))}))},t.prototype.getScreenshot=function(){var t=document.getElementById(this.randomId),e=document.createElement("canvas");(null==t?void 0:t.videoWidth)>=1280?(e.width=t.videoWidth/4,e.height=t.videoHeight/4):(null==t?void 0:t.videoWidth)<1280&&(e.width=t.videoWidth/2,e.height=t.videoHeight/2),e.getContext("2d").drawImage(t,0,0,e.width,e.height);var n=e.toDataURL();localStorage.setItem(this.licensecam,n)},t}();T.decorators=[{type:e.Component,args:[{selector:"vh-camera-msev",template:'\n <video id="mse" poster={{_poster}} autoplay=true style="object-fit: fill; width: 100%; height: 100%;">\n </video>\n '}]}],T.ctorParameters=function(){return[{type:d.Platform},{type:n.Router}]},T.propDecorators={url:[{type:e.Input,args:["url"]}],licensecam:[{type:e.Input}],camliveURL:[{type:e.Input}],poster:[{type:e.Input}],roomid:[{type:e.Input}],width:[{type:e.Input}],height:[{type:e.Input}],play:[{type:e.Input}],monitor:[{type:e.Input}],os:[{type:e.Input}],change:[{type:e.Output}]};var M=function(){function t(t,o){var i=this;this.platform=t,this.router=o,this.url="",this.licensecam="",this.camliveURL="",this.poster="",this.roomid="",this.play=!0,this.monitor=1,this.os="ios",this.change=new e.EventEmitter,this.online=new e.EventEmitter,this.detection=new e.EventEmitter,this.list_camera=[],this._src="",this._run=void 0,this._autoplay=!1,this._play=!0,this._poster="",this.randomId="",t.ready().then((function(){i.router.events.subscribe((function(t){(t instanceof n.NavigationEnd&&"/mobile/tabs/settings"===t.url||t instanceof n.NavigationEnd&&"/mobile/tabs/scripts"===t.url||t instanceof n.NavigationEnd&&"/mobile/tabs/scene"===t.url||t instanceof n.NavigationEnd&&"/mobile/tabs/play-back"===t.url)&&i._run&&i.stopVideo()})),i._poster=localStorage.getItem(i.licensecam),i.randomId=Math.random().toString(36).substr(2,5),document.getElementById("vh-camera-canvas").id=i.randomId,i._play&&i.loadVideo()}))}return t.prototype.ngOnInit=function(){},t.prototype.ngOnChanges=function(t){this._play=this.play,null!=this._run&&(this._play?this._run||this.startVideo():this._run&&this.stopVideo())},t.prototype.ngOnDestroy=function(){this._run&&this.stopVideo()},t.prototype.loadVideo=function(){this.config={channelid:this.licensecam,channelname:this.licensecam,url:this.url,monitor:this.monitor,os:this.os},this._play?this.startVideo():this._run=!1},t.prototype.startVideo=function(){var t=this;this.online.emit({status:!0}),this.config.monitor=this.monitor;var e="?channelid="+this.config.channelid+"&channelname="+this.config.channelname+"&url="+this.config.url+"&monitor="+this.config.monitor+"&os="+this.config.os,n=document.getElementById(this.randomId);this.wsavc=new WSAvcPlayer(n,"webgl",1,35),this.wsavc.connect(this.camliveURL+e),this.wsavc.on("deadprocess",(function(){t._run&&(t.stopVideo(),t.settimeout=setTimeout((function(){t.startVideo()}),5e3))})),this.wsavc.on("detection",(function(e){t.detection.emit({status:e})})),this._run=!0},t.prototype.stopVideo=function(){this.online.emit({status:!1}),this.settimeout&&clearTimeout(this.settimeout),this._run=!1,this.wsavc.disconnect()},t.prototype.getScreenshot=function(){var t=document.getElementById(this.randomId),e=document.createElement("canvas");(null==t?void 0:t.videoWidth)>=1280?(e.width=t.videoWidth/4,e.height=t.videoHeight/4):(null==t?void 0:t.videoWidth)<1280&&(e.width=t.videoWidth/2,e.height=t.videoHeight/2),e.getContext("2d").drawImage(t,0,0,e.width,e.height);var n=e.toDataURL();localStorage.setItem(this.licensecam,n)},t}();M.decorators=[{type:e.Component,args:[{selector:"vh-camera-h265c",template:' \n <canvas id="vh-camera-canvas">\n </canvas> \n '}]}],M.ctorParameters=function(){return[{type:d.Platform},{type:n.Router}]},M.propDecorators={url:[{type:e.Input,args:["url"]}],licensecam:[{type:e.Input}],camliveURL:[{type:e.Input}],poster:[{type:e.Input}],roomid:[{type:e.Input}],width:[{type:e.Input}],height:[{type:e.Input}],play:[{type:e.Input}],monitor:[{type:e.Input}],os:[{type:e.Input}],change:[{type:e.Output}],online:[{type:e.Output}],detection:[{type:e.Output}]};var N=function(){function t(t,o){var i=this;this.platform=t,this.router=o,this.url="",this.licensecam="",this.camliveURL="",this.poster="",this.roomid="",this.play=!0,this.monitor=1,this.os="ios",this.change=new e.EventEmitter,this.list_camera=[],this._src="",this._run=void 0,this._autoplay=!1,this._play=!0,this._poster="",this.randomId="",t.ready().then((function(){i.router.events.subscribe((function(t){(t instanceof n.NavigationEnd&&"/mobile/tabs/settings"===t.url||t instanceof n.NavigationEnd&&"/mobile/tabs/scripts"===t.url||t instanceof n.NavigationEnd&&"/mobile/tabs/scene"===t.url||t instanceof n.NavigationEnd&&"/mobile/tabs/play-back"===t.url)&&i._run&&i.stopVideo()})),i._poster=localStorage.getItem(i.licensecam),i.randomId=Math.random().toString(36).substr(2,5),document.getElementById("vh-camera-mobile-canvas").id=i.randomId,i._play&&i.loadVideo()}))}return t.prototype.ngOnInit=function(){},t.prototype.ngOnChanges=function(t){this._play=this.play,null!=this._run&&(this._play?this._run||this.startVideo():this._run&&this.stopVideo())},t.prototype.ngOnDestroy=function(){this._run&&this.stopVideo(),console.log("destroyed camera")},t.prototype.loadVideo=function(){console.log("loadVideo on mobile"),this.config={channelid:this.licensecam,channelname:this.licensecam,url:this.url,monitor:this.monitor,os:this.os},this._play?this.startVideo():this._run=!1},t.prototype.startVideo=function(){this.config.monitor=this.monitor;var t="?channelid="+this.config.channelid+"&channelname="+this.config.channelname+"&url="+this.config.url+"&monitor="+this.config.monitor+"&os="+this.config.os,e=document.getElementById(this.randomId);this.player=new JSMpeg.Player(this.camliveURL+t,{canvas:e}),this._run=!0,console.log("startVideo on mobile")},t.prototype.stopVideo=function(){this._run=!1,this.player.destroy(),console.log("stopVideo on mobile")},t.prototype.getScreenshot=function(){var t=document.getElementById(this.randomId),e=document.createElement("canvas");(null==t?void 0:t.videoWidth)>=1280?(e.width=t.videoWidth/4,e.height=t.videoHeight/4):(null==t?void 0:t.videoWidth)<1280&&(e.width=t.videoWidth/2,e.height=t.videoHeight/2),e.getContext("2d").drawImage(t,0,0,e.width,e.height);var n=e.toDataURL();localStorage.setItem(this.licensecam,n)},t}();N.decorators=[{type:e.Component,args:[{selector:"vh-camera-jsmpegc",template:' \n <canvas id="vh-camera-mobile-canvas">\n </canvas> \n '}]}],N.ctorParameters=function(){return[{type:d.Platform},{type:n.Router}]},N.propDecorators={url:[{type:e.Input,args:["url"]}],licensecam:[{type:e.Input}],camliveURL:[{type:e.Input}],poster:[{type:e.Input}],roomid:[{type:e.Input}],width:[{type:e.Input}],height:[{type:e.Input}],play:[{type:e.Input}],monitor:[{type:e.Input}],os:[{type:e.Input}],change:[{type:e.Output}]};var R=function(){function t(t,o){var i=this;this.platform=t,this.router=o,this.url="",this.licensecam="",this.camliveURL="",this.poster="",this.roomid="",this.play=!0,this.monitor=1,this.os="ios",this.change=new e.EventEmitter,this.list_camera=[],this._src="",this._run=void 0,this._autoplay=!1,this._play=!0,this._poster="",this.randomId="",t.ready().then((function(){i.router.events.subscribe((function(t){(t instanceof n.NavigationEnd&&"/mobile/tabs/settings"===t.url||t instanceof n.NavigationEnd&&"/mobile/tabs/scripts"===t.url||t instanceof n.NavigationEnd&&"/mobile/tabs/scene"===t.url||t instanceof n.NavigationEnd&&"/mobile/tabs/play-back"===t.url)&&i._run&&i.stopVideo()})),i._poster=localStorage.getItem(i.licensecam),i._play&&i.loadVideo()}))}return t.prototype.ngOnInit=function(){},t.prototype.ngOnChanges=function(t){this._play=this.play,null!=this._run&&(this._play?this._run||this.startVideo():this._run&&this.stopVideo())},t.prototype.ngOnDestroy=function(){this._run&&this.stopVideo(),console.log("destroyed camera")},t.prototype.loadVideo=function(){console.log("loadVideo"),this.config={channelid:this.licensecam,channelname:this.licensecam,url:this.url,monitor:this.monitor,os:this.os},this._play?this.startVideo():(this._run=!1,this.change.emit({status:"loaded"}))},t.prototype.startVideo=function(){this.change.emit({status:"play"});var t=this;this.socket=new l.Socket({url:this.camliveURL}),this.socket.emit("start",JSON.stringify(this.config)),this.socket.on("segment-ios",(function(e){e&&(t._src="data:image/jpeg;base64,"+e),console.log("channelid:",t.config.channelid)})),this._run=!0,console.log("startVideo ios")},t.prototype.stopVideo=function(){this._run=!1,this.change.emit({status:"stop"}),this.socket.disconnect(),this.socket.removeAllListeners(),console.log("stopVideo")},t.prototype.getScreenshot=function(){var t=document.getElementById(this.randomId),e=document.createElement("canvas");(null==t?void 0:t.videoWidth)>=1280?(e.width=t.videoWidth/4,e.height=t.videoHeight/4):(null==t?void 0:t.videoWidth)<1280&&(e.width=t.videoWidth/2,e.height=t.videoHeight/2),e.getContext("2d").drawImage(t,0,0,e.width,e.height);var n=e.toDataURL();localStorage.setItem(this.licensecam,n)},t}();R.decorators=[{type:e.Component,args:[{selector:"vh-camera-img",template:"\n <img src={{_src}}> \n "}]}],R.ctorParameters=function(){return[{type:d.Platform},{type:n.Router}]},R.propDecorators={url:[{type:e.Input,args:["url"]}],licensecam:[{type:e.Input}],camliveURL:[{type:e.Input}],poster:[{type:e.Input}],roomid:[{type:e.Input}],width:[{type:e.Input}],height:[{type:e.Input}],play:[{type:e.Input}],monitor:[{type:e.Input}],os:[{type:e.Input}],change:[{type:e.Output}]};var U=function(){function t(t,e,n,o){this.vhmongo_firebase=t,this.imagePicker=e,this.webview=n,this.camera=o}return t.prototype.getThumbnailFromCamera=function(t,e,n,o){var i=this;return console.log("oldthumbnailURL",o),new Promise((function(a,s){var r={quality:100,destinationType:i.camera.DestinationType.FILE_URI,encodingType:i.camera.EncodingType.JPEG,mediaType:i.camera.MediaType.PICTURE};i.camera.getPicture(r).then((function(r){null==o||(null==o?void 0:o.length)<30||i.deleteThumbnail([o]).then((function(t){}),(function(t){console.log("Lỗi này chỉ xảy ra khi đường link hình ko tồn tại trong storage firebase, hoặc hàm deleteThumbnail bị lỗi")})),i.uploadThumbnailToImageServer(r,t,e,n).then((function(t){a(t)}),(function(t){s(t)}))}),(function(t){s(t)}))}))},t.prototype.getThumbnailFromAlbum=function(t,e,n,o){var i=this;return console.log("oldthumbnailURL",o),new Promise((function(a,s){i.imagePicker.hasReadPermission().then((function(r){r?i.imagePicker.getPictures({maximumImagesCount:1}).then((function(r){r.length>0?(null==o||(null==o?void 0:o.length)<30||i.deleteThumbnail([o]).then((function(t){}),(function(t){console.log("Lỗi này chỉ xảy ra khi đường link hình ko tồn tại trong storage firebase, hoặc hàm deleteThumbnail bị lỗi")})),i.uploadThumbnailToImageServer(r[0],t,e,n).then((function(t){a(t)}),(function(t){s(t)}))):s({message:"cancel"})}),(function(t){s(t)})):(i.imagePicker.requestReadPermission(),s({message:"cancel"}))}),(function(t){s(t)}))}))},t.prototype.getThumbnailFromDesktop=function(t,e,n,o,i){var a=this;return new Promise((function(s,r){if(console.log("oldthumbnailURL",i),null!=t){null==i||(null==i?void 0:i.length)<30||a.deleteThumbnail([i]).then((function(t){}),(function(t){console.log("link hình muốn xóa, ko tồn tại trên imageserver")}));var l=new FileReader;l.addEventListener("load",(function(t){var i=Math.random().toString(36).substr(2,5);a.uploadThumbnail(t.target.result,e,n,i,o).then((function(t){s(t)}),(function(t){r(t)}))})),l.readAsDataURL(t)}else r({})}))},t.prototype.uploadThumbnailToImageServer=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=i.webview.convertFileSrc(t),l=Math.random().toString(36).substr(2,5);i.uploadThumbnail(r,e,n,l,o).then((function(t){a(t)}),(function(t){s(t)}))}))},t.prototype.uploadThumbnail=function(t,e,n,o,i){var a=this;return new Promise((function(s,r){var l=a.vhmongo_firebase.auth().getDatabase(),c=a;a.encodeThumbnailUri(t,e,n,(function(t){c.vhmongo_firebase.image().uploadBase64Image(t,o,l,i).then((function(t){s(t)})).catch((function(t){r(t)}))}))}))},t.prototype.encodeThumbnailUri=function(t,e,n,o){var i=document.createElement("canvas"),a=i.getContext("2d"),s=new Image;s.onload=function(){i.width=e,i.height=n,a.drawImage(s,0,0,e,n);var t=i.toDataURL("image/jpeg");o(t)},s.src=t},t.prototype.deleteThumbnail=function(t){var e=this;return new Promise((function(n,o){for(var i=e,a=new Array,s=0;s<t.length;s++)a[s]=i.vhmongo_firebase.image().deleteImage(t[s]).then((function(t){n(!0)}),(function(t){n(!1)})).catch((function(t){n(!1)}));Promise.all(a).then((function(t){for(var e=0;t.length;e++)if(!t[e])return n(t[e]);n(!0)}))}))},t}();U.decorators=[{type:e.Injectable}],U.ctorParameters=function(){return[{type:o.Vhmongo_firebase},{type:i.ImagePicker},{type:a.WebView},{type:s.Camera}]};var V=function(){function t(t){this.vhmongo_firebase=t}return t.prototype.listener=function(t,e){var n=this;return c.Observable.create((function(o){n.vhmongo_firebase.database().listener(t,e).subscribe((function(t){o.next(t)}))}))},t.prototype.addDoc=function(t,e){var n=this;return new Promise((function(o,i){return"vhbill_details"===t||"printers"===t||"vhpermissions"===t||"vhemployees"===t||"branchs"===t||"appsettingstations"===t?o(null):void n.vhmongo_firebase.database().addDoc(t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.addDocbyID=function(t,e,n){var o=this;return new Promise((function(i,a){return"vhbill_details"===t||"printers"===t||"vhpermissions"===t||"vhemployees"===t||"branchs"===t||"appsettingstations"===t?i(null):void o.vhmongo_firebase.database().addDocbyID(t,e,n).then((function(t){i(t)}),(function(t){a(t)}))}))},t.prototype.updateDoc=function(t,e,n){var o=this;return new Promise((function(i,a){return"vhbill_details"===t||"printers"===t||"vhpermissions"===t||"vhemployees"===t||"branchs"===t||"appsettingstations"===t?i(!1):void o.vhmongo_firebase.database().updateDoc(t,e,n).then((function(t){i(t)}),(function(t){a(t)}))}))},t.prototype.deleteDoc=function(t,e){var n=this;return new Promise((function(o,i){return"vhbill_details"===t||"printers"===t||"vhpermissions"===t||"vhemployees"===t||"branchs"===t||"appsettingstations"===t?o(!1):void n.vhmongo_firebase.database().deleteDoc(t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.getDoc=function(t,e){var n=this;return new Promise((function(o,i){return"vhbill_details"===t||"printers"===t||"vhpermissions"===t||"vhemployees"===t||"branchs"===t||"appsettingstations"===t?o(null):void n.vhmongo_firebase.database().getDoc(t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.getDocs=function(t){var e=this;return new Promise((function(n){return"vhbill_details"===t||"printers"===t||"vhpermissions"===t||"vhemployees"===t||"branchs"===t||"appsettingstations"===t?n([]):void e.vhmongo_firebase.database().getDocs(t).then((function(t){n(t)}))}))},t.prototype.getDocsByFields=function(t,e,n,o,i){var a=this;return new Promise((function(s){return"vhbill_details"===t||"printers"===t||"vhpermissions"===t||"vhemployees"===t||"branchs"===t||"appsettingstations"===t?s([]):void a.vhmongo_firebase.database().getDocsByFields(t,e,n,o,i).then((function(t){s(t)}))}))},t.prototype.asyncPromiseAll=function(t){return new Promise((function(e,n){Promise.all(t).then((function(t){e(t)})).catch((function(t){n(t)}))}))},t}();V.decorators=[{type:e.Injectable}],V.ctorParameters=function(){return[{type:o.Vhmongo_firebase}]};var W=function(){function t(t,e,n,o){var i=this;this.vhmongo_firebase=t,this.vhQuery=e,this.vhAuth=n,this.vhAlgorithm=o,this.restriction_main_package=null,this.areas=new Array,this.tables=new Array,this.products=new Array,this.customers=new Array,this.suppliers=new Array,this.wallets=new Array,this.taxs=new Array,this.categorys=new Array,this.inventorytimes=new Array,this.deliverys=new Array,this.addresss=new Array,this.incoming_groups=new Array,this.spending_groups=new Array,this.branchs=new Array,this.promotions=new Array,this.patternmenus=new Array,this.printers=new Array,this.discount_bills=new Array,this.discount_saless=new Array,this.customer_classs=new Array,this.commissions=new Array,this.hwinfo={},this.appsettingstations=new Array,this.appsettingbranchs=new Array,this.kitchendispatcherlist=new Array,this.servicedispatcherlist=new Array,this.warehousedispatcherlist=new Array,this.subjectwallets=new c.Subject,this.subjectappsettingstations=new c.Subject,this.subjectappsettingbranchs=new c.Subject,this.subjectbranchs=new c.Subject,this.subjectcategorys=new c.Subject,this.subjectcustomers=new c.Subject,this.subjectinventorytimes=new c.Subject,this.subjectprinters=new c.Subject,this.subjectproducts=new c.Subject,this.subjectpromotions=new c.Subject,this.subjectsuppliers=new c.Subject,this.subjecttaxs=new c.Subject,this.subjectareas=new c.Subject,this.subjecttables=new c.Subject,this.subjectdiscount_bills=new c.Subject,this.subjectcustomer_classs=new c.Subject,this.sync_code=Math.random().toString(36).substr(2,10).toUpperCase(),r.Device.getId().then((function(t){var e=i.vhAuth.localStorageGET("hwinfo");null!=e&&null!=e?i.hwinfo=e:(i.hwinfo=Object.assign({},t),i.vhAuth.localStorageSET("hwinfo",i.hwinfo))}))}return t.prototype.refreshLocalRestrictionMainPackage=function(){var t=this;return new Promise((function(e,n){var o=t.getDefaultBranch()._id,i=t.vhAuth.getStore()[o].main_package_expire.id_restriction;t.vhmongo_firebase.rootdatabase().getDoc("restrictions",i).then((function(n){n&&(t.restriction_main_package=Object.assign(Object.assign({},n),t.vhAuth.getStore()[o].main_package_expire),delete t.restriction_main_package.id_restriction,delete t.restriction_main_package._id,console.log("restriction_main_package",t.restriction_main_package)),e(null)}),(function(t){n(t)}))}))},t.prototype.getLocalRestrictionMainPackage=function(){return this.restriction_main_package},t.prototype.syncCollections_Mobile=function(){var t=this;return new Promise((function(e,n){t.initSyncCollections(),t.callbackCollectionInsert().subscribe(),t.callbackCollectionUpdate().subscribe(),t.callbackCollectionDelete().subscribe(),setTimeout((function(){t.checkExpireBranch_Cafe(),e(!0)}),3e3)}))},t.prototype.syncCollections_Desktop=function(){var t=this;return new Promise((function(e,n){t.initSyncCollections(),t.callbackCollectionInsert().subscribe(),t.callbackCollectionUpdate().subscribe(),t.callbackCollectionDelete().subscribe(),setTimeout((function(){t.syncCashBookEveryDay_Stock1stDayOfMonth().then((function(){t.syncInventoryEveryDay_Stock1stDayOfMonth().then((function(){e(!0)}))})),t.checkExpireBranch_Cafe()}),3e3)}))},t.prototype.checkExpireBranch_Cafe=function(){if(this.getDefaultBranch()){var t=this.getDefaultBranch()._id;this.vhmongo_firebase.auth().checkExpireBranch_Cafe(t).then((function(){console.log("success checkExpireBranch_Cafe")}),(function(t){console.log("no success checkExpireBranch_Cafe")}))}},t.prototype.initSyncCollections=function(){this.categorys=new Array,this.products=new Array,this.suppliers=new Array,this.customers=new Array,this.wallets=new Array,this.areas=new Array,this.tables=new Array,this.branchs=new Array,this.taxs=new Array,this.promotions=new Array,this.inventorytimes=new Array,this.appsettingbranchs=new Array,this.appsettingstations=new Array,this.printers=new Array,this.vhAuth.clearLocalEmployeeFromSyncCollection();var t=new Array;return t[0]="categorys",t[1]="printers",t[2]="suppliers",t[3]="customers",t[4]="wallets",t[5]="areas",t[6]="tables",t[7]="branchs",t[8]="taxs",t[9]="vhemployees",t[10]="promotions",t[11]="inventorytimes",t[12]="appsettingstations",t[13]="appsettingbranchs",t[14]="products",t[15]="discount_bills",t[16]="customer_classs",this.vhmongo_firebase.socketMongoDB().initSyncCollections(t)},t.prototype.closeSyncCollections=function(){this.vhmongo_firebase.socketMongoDB().closeSyncCollections()},t.prototype.callbackCollectionInsert=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackCollectionInsert().subscribe((function(n){if("vhemployees"===n.colname?n.colname="employees":"branchs"===n.colname?n.colname="branchs":"printers"===n.colname?n.colname="printers":"appsettingstations"===n.colname&&(n.colname="appsettingstations"),"categorys"===n.colname)t.getlocalCategory(n._id)||((o=Object.assign({},n.data))._id=n._id,t.categorys.push(o),t.publishObservableEventCategorys(),e.next(n.colname));else if("products"===n.colname){if(!t.getlocalProduct(n._id))(o=Object.assign({},n.data))._id=n._id,t.products.push(o),t.publishObservableEventProducts(),e.next(n.colname)}else if("suppliers"===n.colname){if(!t.getlocalSupplier(n._id))(o=Object.assign({},n.data))._id=n._id,t.suppliers.push(o),t.publishObservableEventSuppliers(),e.next(n.colname)}else if("customers"===n.colname){if(!t.getlocalCustomer(n._id))(o=Object.assign({},n.data))._id=n._id,t.customers.push(o),t.publishObservableEventCustomers(),e.next(n.colname)}else if("wallets"===n.colname){if(!t.getlocalWallet(n._id))(o=Object.assign({},n.data))._id=n._id,t.wallets.push(o),t.publishObservableEventWallets(),e.next(n.colname)}else if("areas"===n.colname){if(!t.getlocalArea(n._id))(o=Object.assign({},n.data))._id=n._id,t.areas.push(o),t.publishObservableEventAreas(),e.next(n.colname)}else if("tables"===n.colname){if(!t.getlocalTable(n._id))(o=Object.assign({},n.data))._id=n._id,t.tables.push(o),t.publishObservableEventTables(),e.next(n.colname)}else if("branchs"===n.colname){if(!t.getlocalBranch(n._id))(o=Object.assign({},n.data))._id=n._id,t.branchs.push(o),t.publishObservableEventBranchs(),e.next(n.colname)}else if("taxs"===n.colname){if(!t.getlocalTax(n._id))(o=Object.assign({},n.data))._id=n._id,t.taxs.push(o),t.publishObservableEventTaxs(),e.next(n.colname)}else if("employees"===n.colname){(o=Object.assign({},n.data))._id=n._id,t.vhAuth.insertlocalEmployeeFromSyncCollection(o),t.vhAuth.publishObservableEventEmployees(),e.next(n.colname)}else if("promotions"===n.colname){if(!t.getlocalPromotion(n._id))(o=Object.assign({},n.data))._id=n._id,t.promotions.push(o),t.publishObservableEventPromotions(),e.next(n.colname)}else if("inventorytimes"===n.colname){if(!t.getlocalInventorytime(n._id))(o=Object.assign({},n.data))._id=n._id,t.inventorytimes.push(o),t.publishObservableEventInventorytimes(),e.next(n.colname)}else if("appsettingbranchs"===n.colname){if(!t.getLocalAppSettingBranch(n._id))if(n.data.id_branch===t.getDefaultBranch()._id)(o=Object.assign({},n.data))._id=n._id,delete o.id_branch,t.appsettingbranchs.push(o),t.publishObservableEventAppSettingNameBranchs(),e.next(n.colname)}else if("appsettingstations"===n.colname){if(!t.getLocalAppSettingStation(n._id))if(n.data.uuid===t.hwinfo.uuid)(o=Object.assign({},n.data))._id=n._id,delete o.uuid,t.appsettingstations.push(o),t.publishObservableEventAppSettingNameStations(),e.next(n.colname)}else if("printers"===n.colname){if(!t.getlocalPrinter(n._id))if(n.data.uuid===t.hwinfo.uuid)(o=Object.assign({},n.data))._id=n._id,delete o.uuid,t.printers.push(o),t.publishObservableEventPrinters(),e.next(n.colname)}else if("discount_bills"===n.colname){if(!t.getlocalDiscount_bill(n._id))(o=Object.assign({},n.data))._id=n._id,t.discount_bills.push(o),t.publishObservableEventDiscount_bills(),e.next(n.colname)}else if("customer_classs"===n.colname){var o;if(!t.getlocalCustomerClass(n._id))(o=Object.assign({},n.data))._id=n._id,t.customer_classs.push(o),t.publishObservableEventCustomerClasss(),e.next(n.colname)}console.log("inserted",n.colname)}))}))},t.prototype.callbackCollectionUpdate=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackCollectionUpdate().subscribe((function(n){if("vhemployees"===n.colname&&(n.colname="employees"),"categorys"===n.colname){for(var o=0;o<t.categorys.length;o++)if(t.categorys[o]._id===n._id){t.categorys[o]=Object.assign(Object.assign({},t.categorys[o]),n.data),t.publishObservableEventCategorys(),e.next(n.colname);break}}else if("products"===n.colname){for(o=0;o<t.products.length;o++)if(t.products[o]._id===n._id){t.products[o]=Object.assign(Object.assign({},t.products[o]),n.data),t.publishObservableEventProducts(),e.next(n.colname);break}}else if("suppliers"===n.colname){for(o=0;o<t.suppliers.length;o++)if(t.suppliers[o]._id===n._id){t.suppliers[o]=Object.assign(Object.assign({},t.suppliers[o]),n.data),t.publishObservableEventSuppliers(),e.next(n.colname);break}}else if("customers"===n.colname){for(o=0;o<t.customers.length;o++)if(t.customers[o]._id===n._id){t.customers[o]=Object.assign(Object.assign({},t.customers[o]),n.data),t.publishObservableEventCustomers(),e.next(n.colname);break}e.next(n.colname)}else if("wallets"===n.colname){for(o=0;o<t.wallets.length;o++)if(t.wallets[o]._id===n._id){t.wallets[o]=Object.assign(Object.assign({},t.wallets[o]),n.data),t.publishObservableEventWallets(),e.next(n.colname);break}}else if("areas"===n.colname){for(o=0;o<t.areas.length;o++)if(t.areas[o]._id===n._id){t.areas[o]=Object.assign(Object.assign({},t.areas[o]),n.data),t.publishObservableEventAreas(),e.next(n.colname);break}}else if("tables"===n.colname){for(o=0;o<t.tables.length;o++)if(t.tables[o]._id===n._id){t.tables[o]=Object.assign(Object.assign({},t.tables[o]),n.data),t.publishObservableEventTables(),e.next(n.colname);break}}else if("branchs"===n.colname){for(o=0;o<t.branchs.length;o++)if(t.branchs[o]._id===n._id){t.branchs[o]=Object.assign(Object.assign({},t.branchs[o]),n.data),t.publishObservableEventBranchs(),e.next(n.colname);break}}else if("taxs"===n.colname){for(o=0;o<t.taxs.length;o++)if(t.taxs[o]._id===n._id){t.taxs[o]=Object.assign(Object.assign({},t.taxs[o]),n.data),t.publishObservableEventTaxs(),e.next(n.colname);break}}else if("employees"===n.colname)t.vhAuth.updateLocalEmployeeFromSyncCollection(n._id,n.data),t.vhAuth.publishObservableEventEmployees(),e.next(n.colname);else if("promotions"===n.colname){for(o=0;o<t.promotions.length;o++)if(t.promotions[o]._id===n._id){t.promotions[o]=Object.assign(Object.assign({},t.promotions[o]),n.data),t.publishObservableEventPromotions(),e.next(n.colname);break}}else if("inventorytimes"===n.colname){for(o=0;o<t.inventorytimes.length;o++)if(t.inventorytimes[o]._id===n._id){t.inventorytimes[o]=Object.assign(Object.assign({},t.inventorytimes[o]),n.data),t.publishObservableEventInventorytimes(),e.next(n.colname);break}}else if("appsettingbranchs"===n.colname){for(o=0;o<t.appsettingbranchs.length;o++)if(t.appsettingbranchs[o]._id===n._id){t.appsettingbranchs[o]=Object.assign(Object.assign({},t.appsettingbranchs[o]),n.data),t.publishObservableEventAppSettingNameBranchs(),e.next(n.colname);break}}else if("appsettingstations"===n.colname){for(o=0;o<t.appsettingstations.length;o++)if(t.appsettingstations[o]._id===n._id){t.appsettingstations[o]=Object.assign(Object.assign({},t.appsettingstations[o]),n.data),t.publishObservableEventAppSettingNameStations(),e.next(n.colname);break}}else if("printers"===n.colname){for(o=0;o<t.printers.length;o++)if(t.printers[o]._id===n._id){t.printers[o]=Object.assign(Object.assign({},t.printers[o]),n.data),t.publishObservableEventPrinters(),e.next(n.colname);break}}else if("discount_bills"===n.colname){for(o=0;o<t.discount_bills.length;o++)if(t.discount_bills[o]._id===n._id){t.discount_bills[o]=Object.assign(Object.assign({},t.discount_bills[o]),n.data),t.publishObservableEventDiscount_bills(),e.next(n.colname);break}}else if("customer_classs"===n.colname)for(o=0;o<t.customer_classs.length;o++)if(t.customer_classs[o]._id===n._id){t.customer_classs[o]=Object.assign(Object.assign({},t.customer_classs[o]),n.data),t.publishObservableEventCustomerClasss(),e.next(n.colname);break}console.log("updated",n.colname)}))}))},t.prototype.callbackCollectionDelete=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackCollectionDelete().subscribe((function(n){if("vhemployees"===n.colname&&(n.colname="employees"),"categorys"===n.colname){for(var o=0;o<t.categorys.length;o++)if(t.categorys[o]._id===n._id){t.categorys.splice(o,1),t.publishObservableEventCategorys(),e.next(n.colname);break}}else if("products"===n.colname){for(o=0;o<t.products.length;o++)if(t.products[o]._id===n._id){t.products.splice(o,1),t.publishObservableEventProducts(),e.next(n.colname);break}}else if("suppliers"===n.colname){for(o=0;o<t.suppliers.length;o++)if(t.suppliers[o]._id===n._id){t.suppliers.splice(o,1),t.publishObservableEventSuppliers(),e.next(n.colname);break}}else if("customers"===n.colname){for(o=0;o<t.customers.length;o++)if(t.customers[o]._id===n._id){t.customers.splice(o,1),t.publishObservableEventCustomers(),e.next(n.colname);break}}else if("wallets"===n.colname){for(o=0;o<t.wallets.length;o++)if(t.wallets[o]._id===n._id){t.wallets.splice(o,1),t.publishObservableEventWallets(),e.next(n.colname);break}}else if("areas"===n.colname){for(o=0;o<t.areas.length;o++)if(t.areas[o]._id===n._id){t.areas.splice(o,1),t.publishObservableEventAreas(),e.next(n.colname);break}}else if("tables"===n.colname){for(o=0;o<t.tables.length;o++)if(t.tables[o]._id===n._id){t.tables.splice(o,1),t.publishObservableEventTables(),e.next(n.colname);break}}else if("branchs"===n.colname){for(o=0;o<t.branchs.length;o++)if(t.branchs[o]._id===n._id){t.branchs.splice(o,1),t.publishObservableEventBranchs(),e.next(n.colname);break}}else if("taxs"===n.colname){for(o=0;o<t.taxs.length;o++)if(t.taxs[o]._id===n._id){t.taxs.splice(o,1),t.publishObservableEventTaxs(),e.next(n.colname);break}}else if("employees"===n.colname)t.vhAuth.deleteLocalEmployeeFromSyncCollection(n._id),t.vhAuth.publishObservableEventEmployees(),e.next(n.colname);else if("promotions"===n.colname){for(o=0;o<t.promotions.length;o++)if(t.promotions[o]._id===n._id){t.promotions.splice(o,1),t.publishObservableEventPromotions(),e.next(n.colname);break}}else if("inventorytimes"===n.colname){for(o=0;o<t.inventorytimes.length;o++)if(t.inventorytimes[o]._id===n._id){t.inventorytimes.splice(o,1),t.publishObservableEventInventorytimes(),e.next(n.colname);break}}else if("appsettingbranchs"===n.colname){for(o=0;o<t.appsettingbranchs.length;o++)if(t.appsettingbranchs[o]._id===n._id){t.appsettingbranchs.splice(o,1),t.publishObservableEventAppSettingNameBranchs(),e.next(n.colname);break}}else if("appsettingstations"===n.colname){for(o=0;o<t.appsettingstations.length;o++)if(t.appsettingstations[o]._id===n._id){t.appsettingstations.splice(o,1),t.publishObservableEventAppSettingNameStations(),e.next(n.colname);break}}else if("printers"===n.colname){for(o=0;o<t.printers.length;o++)if(t.printers[o]._id===n._id){t.printers.splice(o,1),t.publishObservableEventPrinters(),e.next(n.colname);break}}else if("discount_bills"===n.colname){for(o=0;o<t.discount_bills.length;o++)if(t.discount_bills[o]._id===n._id){t.discount_bills.splice(o,1),t.publishObservableEventDiscount_bills(),e.next(n.colname);break}}else if("customer_classs"===n.colname)for(o=0;o<t.customer_classs.length;o++)if(t.customer_classs[o]._id===n._id){t.customer_classs.splice(o,1),t.publishObservableEventCustomerClasss(),e.next(n.colname);break}console.log("deleted",n.colname)}))}))},t.prototype.initChatToAppCare=function(){return this.vhmongo_firebase.socketMongoDB().initChat("vhmessages",{})},t.prototype.listeningChatToAppCare_Insert=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackChatInsert().subscribe((function(t){e.next(t)}))}))},t.prototype.listeningChatToAppCare_Update=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackChatUpdate().subscribe((function(t){e.next(t)}))}))},t.prototype.getOldMessages=function(t){return this.vhmongo_firebase.database().getDocsByFields("vhmessages",{},{},{date:1},t)},t.prototype.sendMessageToAppCare=function(t){var e=this;return new Promise((function(n,o){var i={msg:t,date:new Date,avatar:e.getLocalAppSettingNameStation("store_info").img,email:e.getLocalAppSettingNameStation("store_info").email,company:e.getLocalAppSettingNameStation("store_info").company,align:"left"};e.vhmongo_firebase.database().addDoc("vhmessages",i).then((function(t){n(t)}),(function(t){o(t)})),e.vhmongo_firebase.socketMongoDB().saytoAppCareFirebase()}))},t.prototype.sendImageToAppCare=function(t){var e=this;return new Promise((function(n,o){var i={img:t,date:new Date,avatar:e.getLocalAppSettingNameStation("store_info").img,email:e.getLocalAppSettingNameStation("store_info").email,company:e.getLocalAppSettingNameStation("store_info").company,align:"left"};e.vhmongo_firebase.database().addDoc("vhmessages",i).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.startLocalStorage=function(){var t=this;return new Promise((function(e){var n=new Array;n[0]=t.vhAuth.refreshLocalMyPermission(),n[1]=t.refreshLocalDeliverys(),n[2]=t.refreshLocalAddresss(),t.vhQuery.asyncPromiseAll(n).then((function(){e(null)}))}))},t.prototype.observableDispatcher=function(t){var e=this;return new c.Observable((function(n){e.kitchendispatcherlist=new Array,e.servicedispatcherlist=new Array,e.warehousedispatcherlist=new Array,e.initDispatcher().then((function(o){o&&(e.callbackdispatcher=e.callbackDispatcher(t).subscribe((function(t){n.next(t)})))}))}))},t.prototype.initDispatcher=function(){var t=this.getDefaultBranch()._id;return this.vhmongo_firebase.socketMongoDB().initDispatcher("vhbill_details",t)},t.prototype.closeDispatcher=function(){this.callbackdispatcher.unsubscribe(),this.vhmongo_firebase.socketMongoDB().closeDispatcher()},t.prototype.doneDispatcher=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().updateDoc("vhbill_details",t,{done:!0}).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.callbackDispatcher=function(t){var e=this;this.getDefaultBranch()._id;return new c.Observable((function(n){e.listeningDispatcher_Insert().subscribe((function(o){1!==t||1!==o.ptype&&4!==o.ptype&&5!==o.ptype?2===t&&2===o.ptype?(e.servicedispatcherlist.push(o),e.refreshServiceDispatcherList().then((function(t){n.next(t)}))):3===t&&3===o.ptype&&(e.warehousedispatcherlist.push(o),e.refreshWarehouseDispatcherList().then((function(t){n.next(t)}))):(e.kitchendispatcherlist.push(o),e.refreshKitchenDispatcherList().then((function(t){n.next(t)})))}),(function(t){console.log(t)})),e.listeningDispatcher_Update().subscribe((function(t){for(var o,i,a,s=0;s<e.kitchendispatcherlist.length;s++)if(e.kitchendispatcherlist[s]._id===t._id){if(!0===(null===(o=t.value)||void 0===o?void 0:o.done))e.kitchendispatcherlist.splice(s,1);else for(var r in t.value)e.kitchendispatcherlist[s][r]=t.value[r];e.refreshKitchenDispatcherList().then((function(t){n.next(t)}));break}for(s=0;s<e.servicedispatcherlist.length;s++)if(e.servicedispatcherlist[s]._id===t._id){if(!0===(null===(i=t.value)||void 0===i?void 0:i.done))e.servicedispatcherlist.splice(s,1);else for(var r in t.value)e.servicedispatcherlist[s][r]=t.value[r];e.refreshServiceDispatcherList().then((function(t){n.next(t)}));break}for(s=0;s<e.warehousedispatcherlist.length;s++)if(e.warehousedispatcherlist[s]._id===t._id){if(!0===(null===(a=t.value)||void 0===a?void 0:a.done))e.warehousedispatcherlist.splice(s,1);else for(var r in t.value)e.warehousedispatcherlist[s][r]=t.value[r];e.refreshWarehouseDispatcherList().then((function(t){n.next(t)}));break}})),e.listeningDispatcher_Delete().subscribe((function(t){for(var o=0;o<e.kitchendispatcherlist.length;o++)if(e.kitchendispatcherlist[o]._id===t._id){e.kitchendispatcherlist.splice(o,1),e.refreshKitchenDispatcherList().then((function(t){n.next(t)}));break}for(o=0;o<e.servicedispatcherlist.length;o++)if(e.servicedispatcherlist[o]._id===t._id){e.servicedispatcherlist.splice(o,1),e.refreshServiceDispatcherList().then((function(t){n.next(t)}));break}for(o=0;o<e.warehousedispatcherlist.length;o++)if(e.warehousedispatcherlist[o]._id===t._id){e.warehousedispatcherlist.splice(o,1),e.refreshWarehouseDispatcherList().then((function(t){n.next(t)}));break}}))}))},t.prototype.listeningDispatcher_Insert=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackDispatcherInsert().subscribe((function(t){e.next(t)}))}))},t.prototype.listeningDispatcher_Update=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackDispatcherUpdate().subscribe((function(t){e.next(t)}))}))},t.prototype.listeningDispatcher_Delete=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackDispatcherDelete().subscribe((function(t){e.next(t)}))}))},t.prototype.refreshKitchenDispatcherList=function(){var t=this;return new Promise((function(e,n){var o,i,a,s,r,l,c={bills_takeaway:new Array,bills_table:new Array,products:new Array},u=t.kitchendispatcherlist;if(u.length>0){for(var d=t.getlocalProducts(145),_=0;_<d.length;_++)if(null===(o=d[_])||void 0===o||delete o.allow_sell,null===(i=d[_])||void 0===i||delete i.describe,null===(a=d[_])||void 0===a||delete a.id_category,null===(s=d[_])||void 0===s||delete s.toppings,null===(r=d[_])||void 0===r||delete r.combos,d[_].late_warning=!1,d[_].quantity=0,d[_].bill_details=new Array,null!=d[_].subs)for(var p=0;p<d[_].subs.length;p++)null===(l=d[_].subs[p])||void 0===l||delete l.active,delete d[_].subs[p].price,d[_].subs[p].late_warning=!1,d[_].subs[p].quantity=0,d[_].subs[p].bill_details=new Array;var b=new Array,f=new Array;for(_=0;_<u.length;_++){var h=!1;for(p=0;p<b.length;p++)if(u[_].id_bill===b[p].id_bill){h=!0;break}if(!h&&"go_home"!=u[_].id_table){var y=t.getlocalTable(u[_].id_table),m={id_bill:u[_].id_bill,id_table:u[_].id_table,table_name:y.name,quantity:0,orders:0,bill_details:new Array,late_warning:!1};b.push(m)}}for(_=0;_<u.length;_++){for(h=!1,p=0;p<f.length;p++)if(u[_].id_bill===f[p].id_bill){h=!0;break}if(!h&&"go_home"===u[_].id_table){m={id_bill:u[_].id_bill,bill_code:u[_].bill_code,table_name:"Take away",quantity:0,orders:0,bill_details:new Array,late_warning:!1};f.push(m)}}for(_=0;_<u.length;_++){m=Object.assign({},u[_]),y=t.getlocalTable(u[_].id_table);if(m.late_warning=!1,m.table_name=y.name,m._id=u[_]._id,null==m||delete m.date,null==m||delete m.tax,null==m||delete m.bill_type,null==m||delete m.id_cashier,null==m||delete m.id_employee,null==m||delete m.id_supplier,delete m.id_customer,delete m.id_branch,delete m.id_category,null==m||delete m.done,null==m||delete m.price,null!=m.toppings)for(p=0;p<m.toppings.length;p++)m.toppings[p].name=t.getlocalProduct(m.toppings[p].id_product).name;if(null!=m.combos)for(p=0;p<m.combos.length;p++)m.combos[p].name=t.getlocalProduct(m.combos[p].id_product).name;var v=(new Date).getTime()-new Date(m.date_order).getTime();(v=Math.floor(v/6e4))>t.getlocalProduct(m.id_product).time_warning?m.late_warning=!0:m.late_warning=!1;for(p=0;p<b.length;p++)b[p].id_bill===m.id_bill&&(b[p].orders++,b[p].quantity=b[p].quantity+m.quantity,v>t.getlocalProduct(m.id_product).time_warning&&(b[p].late_warning=!0),b[p].bill_details.push(m));for(p=0;p<f.length;p++)f[p].id_bill===m.id_bill&&(f[p].orders++,f[p].quantity=f[p].quantity+m.quantity,v>t.getlocalProduct(m.id_product).time_warning&&(f[p].late_warning=!0),f[p].bill_details.push(m));for(p=0;p<d.length;p++)if(v>d[p].time_warning&&(d[p].late_warning=!0),d[p]._id===m.id_product){if(d[p].quantity=d[p].quantity+m.quantity,null!=d[p].subs)for(var g=0;g<d[p].subs.length;g++)d[p].subs[g]._id===m.id_subproduct&&(d[p].subs[g].quantity=d[p].subs[g].quantity+m.quantity,v>d[p].time_warning&&(d[p].subs[g].late_warning=!0),d[p].subs[g].bill_details.push(m));d[p].bill_details.push(m)}}d=d.filter((function(t){return t.quantity>0}));for(_=0;_<d.length;_++)if(null!=d[_].subs){var x=d[_].subs.filter((function(t){return t.quantity>0}));delete d[_].subs,d[_].subs=x}b.length>0&&(c.bills_table=b),f.length>0&&(c.bills_takeaway=f),d.length>0&&(c.products=d)}e(c)}))},t.prototype.getKitchenDispatcherList=function(t){var e=new Date;return e.setDate(e.getDate()-1),e.setHours(0),e.setMinutes(0),e.setSeconds(0),e.setMilliseconds(0),this.vhmongo_firebase.database().getDocsByFields("vhbill_details",{id_branch:{$eq:t},done:{$eq:!1},bill_type:{$in:[1,5]},ptype:{$eq:1},date_order:{$gte:e}},{},{date_order:1},0)},t.prototype.refreshWarehouseDispatcherList=function(){var t=this;return new Promise((function(e,n){var o,i,a,s,r,l={bills_takeaway:new Array,bills_table:new Array,products:new Array},c=t.warehousedispatcherlist;if(c.length>0){for(var u=t.getlocalProducts(3),d=0;d<u.length;d++)if(null===(o=u[d])||void 0===o||delete o.allow_sell,null===(i=u[d])||void 0===i||delete i.describe,null===(a=u[d])||void 0===a||delete a.id_category,u[d].late_warning=!1,u[d].quantity=0,u[d].bill_details=new Array,null!=u[d].subs)for(var _=0;_<u[d].subs.length;_++)null===(s=u[d].subs[_])||void 0===s||delete s.active,null===(r=u[d].subs[_])||void 0===r||delete r.price,u[d].subs[_].late_warning=!1,u[d].subs[_].quantity=0,u[d].subs[_].bill_details=new Array;var p=new Array,b=new Array;for(d=0;d<c.length;d++){var f=!1;for(_=0;_<p.length;_++)if(c[d].id_bill===p[_].id_bill){f=!0;break}if(!f&&"go_home"!=c[d].id_table){var h=t.getlocalTable(c[d].id_table),y={id_bill:c[d].id_bill,id_table:c[d].id_table,table_name:h.name,quantity:0,orders:0,bill_details:new Array,late_warning:!1};p.push(y)}}for(d=0;d<c.length;d++){for(f=!1,_=0;_<b.length;_++)if(c[d].id_bill===b[_].id_bill){f=!0;break}if(!f&&"go_home"===c[d].id_table){y={id_bill:c[d].id_bill,bill_code:c[d].bill_code,table_name:"Take away",quantity:0,orders:0,bill_details:new Array,late_warning:!1};b.push(y)}}for(d=0;d<c.length;d++){y=Object.assign({},c[d]),h=t.getlocalTable(c[d].id_table);y.late_warning=!1,y.table_name=h.name,y._id=c[d]._id,null==y||delete y.date,null==y||delete y.tax,null==y||delete y.bill_type,null==y||delete y.id_cashier,null==y||delete y.id_employee,null==y||delete y.id_supplier,delete y.id_customer,delete y.id_branch,delete y.id_category,null==y||delete y.done,null==y||delete y.price;var m=(new Date).getTime()-new Date(y.date_order).getTime();(m=Math.floor(m/6e4))>t.getlocalProduct(y.id_product).time_warning?y.late_warning=!0:y.late_warning=!1;for(_=0;_<p.length;_++)p[_].id_bill===y.id_bill&&(p[_].orders++,p[_].quantity=p[_].quantity+y.quantity,m>t.getlocalProduct(y.id_product).time_warning&&(p[_].late_warning=!0),p[_].bill_details.push(y));for(_=0;_<b.length;_++)b[_].id_bill===y.id_bill&&(b[_].orders++,b[_].quantity=b[_].quantity+y.quantity,m>t.getlocalProduct(y.id_product).time_warning&&(b[_].late_warning=!0),b[_].bill_details.push(y));for(_=0;_<u.length;_++)if(m>u[_].time_warning&&(u[_].late_warning=!0),u[_]._id===y.id_product){if(u[_].quantity=u[_].quantity+y.quantity,null!=u[_].subs)for(var v=0;v<u[_].subs.length;v++)u[_].subs[v]._id===y.id_subproduct&&(u[_].subs[v].quantity=u[_].subs[v].quantity+y.quantity,m>u[_].time_warning&&(u[_].subs[v].late_warning=!0),u[_].subs[v].bill_details.push(y));u[_].bill_details.push(y)}}u=u.filter((function(t){return t.quantity>0}));for(d=0;d<u.length;d++)if(null!=u[d].subs){var g=u[d].subs.filter((function(t){return t.quantity>0}));delete u[d].subs,u[d].subs=g}p.length>0&&(l.bills_table=p),b.length>0&&(l.bills_takeaway=b),u.length>0&&(l.products=u)}e(l)}))},t.prototype.getWarehouseDispatcherList=function(t){var e=new Date;return e.setDate(e.getDate()-1),e.setHours(0),e.setMinutes(0),e.setSeconds(0),e.setMilliseconds(0),this.vhmongo_firebase.database().getDocsByFields("vhbill_details",{id_branch:{$eq:t},done:{$eq:!1},bill_type:{$in:[1,5]},ptype:{$eq:3},date_order:{$gte:e}},{},{date_order:1},0)},t.prototype.refreshServiceDispatcherList=function(){var t=this;return new Promise((function(e,n){var o,i,a,s,r,l={bills_takeaway:new Array,bills_table:new Array,products:new Array},c=t.servicedispatcherlist;if(c.length>0){for(var u=t.getlocalProducts(2),d=0;d<u.length;d++)if(null===(o=u[d])||void 0===o||delete o.allow_sell,null===(i=u[d])||void 0===i||delete i.describe,null===(a=u[d])||void 0===a||delete a.id_category,u[d].late_warning=!1,u[d].quantity=0,u[d].bill_details=new Array,null!=u[d].subs)for(var _=0;_<u[d].subs.length;_++)null===(s=u[d].subs[_])||void 0===s||delete s.active,null===(r=u[d].subs[_])||void 0===r||delete r.price,u[d].subs[_].late_warning=!1,u[d].subs[_].quantity=0,u[d].subs[_].bill_details=new Array;var p=new Array,b=new Array;for(d=0;d<c.length;d++){var f=!1;for(_=0;_<p.length;_++)if(c[d].id_bill===p[_].id_bill){f=!0;break}if(!f&&"go_home"!=c[d].id_table){var h=t.getlocalTable(c[d].id_table),y={id_bill:c[d].id_bill,id_table:c[d].id_table,table_name:h.name,quantity:0,orders:0,bill_details:new Array,late_warning:!1};p.push(y)}}for(d=0;d<c.length;d++){for(f=!1,_=0;_<b.length;_++)if(c[d].id_bill===b[_].id_bill){f=!0;break}if(!f&&"go_home"===c[d].id_table){y={id_bill:c[d].id_bill,bill_code:c[d].bill_code,table_name:"Take away",quantity:0,orders:0,bill_details:new Array,late_warning:!1};b.push(y)}}for(d=0;d<c.length;d++){y=Object.assign({},c[d]),h=t.getlocalTable(c[d].id_table);y.late_warning=!1,y.table_name=h.name,y._id=c[d]._id,null==y||delete y.date,null==y||delete y.tax,null==y||delete y.bill_type,null==y||delete y.id_cashier,null==y||delete y.id_employee,null==y||delete y.id_supplier,delete y.id_customer,delete y.id_branch,delete y.id_category,null==y||delete y.done,null==y||delete y.price;var m=(new Date).getTime()-new Date(y.date_order).getTime();(m=Math.floor(m/6e4))>t.getlocalProduct(y.id_product).time_warning?y.late_warning=!0:y.late_warning=!1;for(_=0;_<p.length;_++)p[_].id_bill===y.id_bill&&(p[_].orders++,p[_].quantity=p[_].quantity+y.quantity,m>t.getlocalProduct(y.id_product).time_warning&&(p[_].late_warning=!0),p[_].bill_details.push(y));for(_=0;_<b.length;_++)b[_].id_bill===y.id_bill&&(b[_].orders++,b[_].quantity=b[_].quantity+y.quantity,m>t.getlocalProduct(y.id_product).time_warning&&(b[_].late_warning=!0),b[_].bill_details.push(y));for(_=0;_<u.length;_++)if(m>u[_].time_warning&&(u[_].late_warning=!0),u[_]._id===y.id_product){if(u[_].quantity=u[_].quantity+y.quantity,null!=u[_].subs)for(var v=0;v<u[_].subs.length;v++)u[_].subs[v]._id===y.id_subproduct&&(u[_].subs[v].quantity=u[_].subs[v].quantity+y.quantity,m>u[_].time_warning&&(u[_].subs[v].late_warning=!0),u[_].subs[v].bill_details.push(y));u[_].bill_details.push(y)}}u=u.filter((function(t){return t.quantity>0}));for(d=0;d<u.length;d++)if(null!=u[d].subs){var g=u[d].subs.filter((function(t){return t.quantity>0}));delete u[d].subs,u[d].subs=g}p.length>0&&(l.bills_table=p),b.length>0&&(l.bills_takeaway=b),u.length>0&&(l.products=u)}e(l)}))},t.prototype.getServiceDispatcherList=function(t){var e=new Date;return e.setDate(e.getDate()-1),e.setHours(0),e.setMinutes(0),e.setSeconds(0),e.setMilliseconds(0),this.vhmongo_firebase.database().getDocsByFields("vhbill_details",{id_branch:{$eq:t},done:{$eq:!1},bill_type:{$in:[1,5]},ptype:{$eq:2},date_order:{$gte:e}},{},{date_order:1},0)},t.prototype.publishObservableEventAreas=function(){this.subjectareas.next(this.areas)},t.prototype.observableLocalAreas=function(){return this.subjectareas},t.prototype.getObservableLocalAreas=function(){var t=this;return new c.Observable((function(e){t.observableLocalAreas().subscribe((function(t){e.next(t)})),t.publishObservableEventAreas()}))},t.prototype.getlocalArea=function(t){for(var e=0;e<this.areas.length;e++)if(this.areas[e]._id===t)return this.areas[e];return null},t.prototype.getlocalAreas=function(){return this.areas},t.prototype.refreshLocalAreas=function(){return new Promise((function(t,e){t(null)}))},t.prototype.addArea=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("areas",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateArea=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("areas",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteArea=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("tables",{id_area:{$eq:t}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("areas",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getArea=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("areas",t).then((function(t){n(t)}))}))},t.prototype.getAreas=function(){var t=this;return new Promise((function(e){t.vhmongo_firebase.database().getDocs("areas").then((function(n){t.areas=n,e(n)}))}))},t.prototype.addAdss=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("adss",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateAds=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("adss",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteAds=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("adss",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getAds=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("adss",t).then((function(t){n(t)}))}))},t.prototype.getAdss=function(){var t=this;return new Promise((function(e){t.vhmongo_firebase.database().getDocs("adss").then((function(t){e(t)}))}))},t.prototype.getAdss_byFields=function(t,e,n,o){var i=this;return new Promise((function(a,s){void 0===e&&(e={}),void 0===n&&(n={}),void 0===o&&(o=0),i.vhmongo_firebase.database().getDocsByFields("adss",t,e,n,o).then((function(t){a(t)}),(function(t){s(t)}))}))},t.prototype.publishObservableEventTables=function(){this.subjecttables.next(this.tables)},t.prototype.observableLocalTables=function(){return this.subjecttables},t.prototype.getObservableLocalTables=function(){var t=this;return new c.Observable((function(e){t.observableLocalTables().subscribe((function(t){e.next(t)})),t.publishObservableEventTables()}))},t.prototype.getlocalTable=function(t){for(var e=0;e<this.tables.length;e++)if(this.tables[e]._id===t)return this.tables[e];return null},t.prototype.getlocalTables=function(){return this.tables},t.prototype.refreshLocalTables=function(){return new Promise((function(t,e){t(null)}))},t.prototype.addTable=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("tables",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateTable=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("tables",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteTable=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("bills",{id_table:{$eq:t}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("tables",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getTable=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("tables",t).then((function(t){n(t)}))}))},t.prototype.getTables=function(){var t=this;return new Promise((function(e){t.vhmongo_firebase.database().getDocs("tables").then((function(n){t.tables=n,e(n)}))}))},t.prototype.publishObservableEventProducts=function(){this.subjectproducts.next()},t.prototype.observableLocalProducts=function(){return this.subjectproducts},t.prototype.getObservableLocalProducts=function(t){var e=this;return new c.Observable((function(n){e.observableLocalProducts().subscribe((function(){n.next(e.getlocalProducts(t))})),e.publishObservableEventProducts()}))},t.prototype.getlocalProductAndCombosAndToppings=function(t){for(var e=new Array,n=0;n<this.products.length;n++){if(this.products[n]._id===t&&(e.push(Object.assign({},this.products[n])),null!=this.products[n].subs)){var o=E(this.products[n].subs);e[e.length-1].subs=new Array,o.forEach((function(t){e[e.length-1].subs.push(Object.assign({},t))}))}if(null!=this.products[n].combos)for(var i=0;i<this.products[n].combos.length;i++)if(this.products[n].combos[i].id_product===t){e.push(Object.assign({},this.products[n]));break}if(null!=this.products[n].toppings)for(i=0;i<this.products[n].toppings.length;i++)if(this.products[n].toppings[i].id_product===t){e.push(Object.assign({},this.products[n]));break}}return e},t.prototype.getlocalProduct=function(t){for(var e=function(e){if(n.products[e]._id===t){var o=Object.assign({},n.products[e]);if(null!=o.subs){var i=E(o.subs);o.subs=new Array,i.forEach((function(t){o.subs.push(Object.assign({},t))}))}if(null!=o.toppings){var a=E(o.toppings);o.toppings=new Array,a.forEach((function(t){o.toppings.push(Object.assign({},t))}))}if(null!=o.combos){var s=E(o.combos);o.combos=new Array,s.forEach((function(t){o.combos.push(Object.assign({},t))}))}return{value:o}}},n=this,o=0;o<this.products.length;o++){var i=e(o);if("object"==typeof i)return i.value}return null},t.prototype.getlocalProducts=function(t){var e=this,n=new Array;return this.products.forEach((function(o){var i=Object.assign({},o);if(null!=i.subs){var a=E(i.subs);i.subs=new Array,a.forEach((function(t){i.subs.push(Object.assign({},t))}))}if(null!=i.toppings){var s=E(i.toppings);i.toppings=new Array,s.forEach((function(t){var n=e.getlocalProduct(t.id_product);t.name=n.name,t.price=n.price,t.img=n.img,t.id_category=n.id_category,t.ptype=n.type,i.toppings.push(Object.assign({},t))}))}if(null!=i.combos){var r=E(i.combos);i.combos=new Array,r.forEach((function(t){var n=e.getlocalProduct(t.id_product);if(t.name=n.name,t.img=n.img,t.id_category=n.id_category,t.ptype=n.type,null!=t.id_subproduct)for(var o=0;o<n.subs.length;o++)if(t.id_subproduct===n.subs[o]._id){t.name=t.name+"("+n.subs[o].name+")";break}i.combos.push(Object.assign({},t))}))}1===t||2===t||3===t||4===t||5===t?i.type===t&&n.push(Object.assign({},i)):13===t?1!==i.type&&3!==i.type||n.push(Object.assign({},i)):15===t?1!==i.type&&5!==i.type||n.push(Object.assign({},i)):25===t?2!==i.type&&5!==i.type||n.push(Object.assign({},i)):35===t?3!==i.type&&5!==i.type||n.push(Object.assign({},i)):41===t?1!==i.type&&4!==i.type||n.push(Object.assign({},i)):1234===t&&1!==i.type&&2!==i.type&&3!==i.type&&4!==i.type||n.push(Object.assign({},i))})),n},t.prototype.refreshLocalProduct=function(t){return new Promise((function(t,e){t(null)}))},t.prototype.refreshLocalProducts=function(){return new Promise((function(t,e){t(null)}))},t.prototype.addProduct=function(t){var e=this;return new Promise((function(n,o){3===(null==t?void 0:t.type)&&(t.quantity=0,t.quantity_branch={},e.branchs.forEach((function(e){t.quantity_branch[e._id]=0}))),e.vhmongo_firebase.database().addDoc("products",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.addProducts=function(t){var e=this;return new Promise((function(n,o){for(var i,a=new Array,s=function(n){3===(null===(i=t[n])||void 0===i?void 0:i.type)&&(t[n].quantity=0,t[n].quantity_branch={},e.branchs.forEach((function(e){t[n].quantity_branch[e._id]=0}))),a[n]=new Promise((function(o){e.vhmongo_firebase.database().addDoc("products",t[n]).then((function(t){o(t)}),(function(){o(null)}))}))},r=0;r<t.length;r++)s(r);Promise.all(a).then((function(t){var e=t.filter((function(t){return null!=t}));n(e)}))}))},t.prototype.updateProduct=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("products",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteProduct=function(t){var e=this;return new Promise((function(n,o){var i=new Array;e.getlocalProductAndCombosAndToppings(t).forEach((function(t){i.push(t._id)})),1===i.length?e.vhmongo_firebase.database().getDocsByFields("vhbill_details",{id_product:{$in:i}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("products",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)})):(console.log("Bạn không thể xóa, vì sản phẩm đang liên kết với sản phẩm khác"),n(!1))}))},t.prototype.getProduct=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("products",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getProducts=function(){var t=this;return new Promise((function(e,n){return new Promise((function(e){t.vhmongo_firebase.database().getDocs("products").then((function(n){t.products=n,e(n)}),(function(t){n(t)}))}))}))},t.prototype.addToppingsProduct=function(t,e){var n=this;return new Promise((function(o,i){new Array;for(var a=new Array,s=0;s<e.length;s++)a[s]=Object.assign(Object.assign({},e[s]),{_id:n.vhAlgorithm.ObjectId()});var r,l=!1,c=0,u=setInterval((function(){var e,s,d;if(c++,r=n.getlocalProduct(t)){l=!0,void 0===r.toppings&&(r.toppings=new Array);for(var _=0;_<r.toppings.length;_++)null===(e=r.toppings[_])||void 0===e||delete e.name,null===(s=r.toppings[_])||void 0===s||delete s.price,null===(d=r.toppings[_])||void 0===d||delete d.img;var p=E(r.toppings,a);n.vhmongo_firebase.database().updateDoc("products",t,{toppings:p}).then((function(){for(var t=0;t<a.length;t++)a[t].name=n.getlocalProduct(a[t].id_product).name,a[t].price=n.getlocalProduct(a[t].id_product).price,a[t].img=n.getlocalProduct(a[t].id_product).img;o(a)}),(function(t){i(t)}))}!0!==l&&20!==c||clearInterval(u)}),100)}))},t.prototype.deleteToppingProduct=function(t,e){var n=this;return new Promise((function(o,i){var a=n.getlocalProduct(t);if(null!=a.toppings)for(var s=0;s<a.toppings.length;s++)if(a.toppings[s]._id===e){a.toppings.splice(s,1),n.vhmongo_firebase.database().updateDoc("products",a._id,{toppings:a.toppings}).then((function(t){o(t)}),(function(t){i(t)}));break}}))},t.prototype.addCombosProduct=function(t,e){for(var n,o=this,i=0;i<e.length;i++)null===(n=e[i])||void 0===n||delete n.name;return new Promise((function(n,i){for(var a=new Array,s=0;s<e.length;s++)a[s]=Object.assign(Object.assign({},e[s]),{_id:o.vhAlgorithm.ObjectId()});var r,l=!1,c=0,u=setInterval((function(){var e,s;if(c++,r=o.getlocalProduct(t)){l=!0,void 0===r.combos&&(r.combos=new Array);for(var d=0;d<r.combos.length;d++)null===(e=r.combos[d])||void 0===e||delete e.name,null===(s=r.combos[d])||void 0===s||delete s.img;var _=E(r.combos,a);o.vhmongo_firebase.database().updateDoc("products",t,{combos:_}).then((function(){for(var t=0;t<a.length;t++){var e=o.getlocalProduct(a[t].id_product);if(a[t].name=e.name,a[t].img=e.img,null!=a[t].id_subproduct)for(var i=0;i<e.subs.length;i++)if(a[t].id_subproduct===e.subs[i]._id){a[t].name=a[t].name+"("+e.subs[i].name+")";break}}n(a)}),(function(){i(null)}))}!0!==l&&20!==c||clearInterval(u)}),100)}))},t.prototype.updateComboProduct=function(t,e,n){var o=this;return null==n||delete n.name,null==n||delete n.quantity,new Promise((function(i,a){var s=o.getlocalProduct(t);if(null!=s.combos){s.combos.forEach((function(t){null==t||delete t.name,null==t||delete t.img}));for(var r=0;r<s.combos.length;r++)if(s.combos[r]._id===e){s.combos[r]=Object.assign(Object.assign({},s.combos[r]),n),o.vhmongo_firebase.database().updateDoc("products",s._id,{combos:s.combos}).then((function(t){i(t)}),(function(t){a(t)}));break}}}))},t.prototype.addSubProduct=function(t,e){var n=this;return new Promise((function(o,i){var a,s=Object.assign(Object.assign({},e),{_id:n.vhAlgorithm.ObjectId()}),r=!1,l=0,c=setInterval((function(){if(l++,a=n.getlocalProduct(t)){r=!0,void 0===a.subs&&(a.subs=new Array);var e=a.subs;e.push(s),n.vhmongo_firebase.database().updateDoc("products",t,{subs:e}).then((function(){o(s)}),(function(t){o(null)}))}!0!==r&&5!==l||clearInterval(c)}),100)}))},t.prototype.addSubsProduct=function(t,e){var n=this;return new Promise((function(o,i){for(var a=new Array,s=0;s<e.length;s++)a[s]=Object.assign(Object.assign({},e[s]),{_id:n.vhAlgorithm.ObjectId()});var r,l=!1,c=0,u=setInterval((function(){if(c++,r=n.getlocalProduct(t)){l=!0,void 0===r.subs&&(r.subs=new Array);var e=E(r.subs,a);n.vhmongo_firebase.database().updateDoc("products",t,{subs:e}).then((function(){o(a)}),(function(t){o(null)}))}!0!==l&&20!==c||clearInterval(u)}),100)}))},t.prototype.updateSubProduct=function(t,e,n){var o=this;return new Promise((function(i,a){var s=o.getlocalProduct(t);if(null!=s.subs)for(var r=0;r<s.subs.length;r++)if(s.subs[r]._id===e){s.subs[r]=Object.assign(Object.assign({},s.subs[r]),n),o.vhmongo_firebase.database().updateDoc("products",s._id,{subs:s.subs}).then((function(t){i(t)}),(function(t){a(t)}));break}}))},t.prototype.deleteSubProduct=function(t,e){var n=this;return new Promise((function(o,i){var a=new Array;n.getlocalProductAndCombosAndToppings(t).forEach((function(t){a.push(t._id)})),1===a.length?n.vhmongo_firebase.database().getDocsByFields("vhbill_details",{id_subproduct:{$eq:e}},{},{},1).then((function(a){if(0===a.length){var s=n.getlocalProduct(t);if(null!=s.subs)for(var r=0;r<s.subs.length;r++)if(s.subs[r]._id===e){s.subs.splice(r,1),n.vhmongo_firebase.database().updateDoc("products",s._id,{subs:s.subs}).then((function(t){o(t)}),(function(t){i(t)}));break}o(!0)}else o(!1)}),(function(t){i(t)})):(console.log("Bạn không thể xóa, vì sản phẩm đang liên kết với sản phẩm khác"),o(!1))}))},t.prototype.publishObservableEventCustomers=function(){this.subjectcustomers.next(this.customers)},t.prototype.observableLocalCustomers=function(){return this.subjectcustomers},t.prototype.getObservableLocalCustomers=function(){var t=this;return new c.Observable((function(e){t.observableLocalCustomers().subscribe((function(t){e.next(t)})),t.publishObservableEventCustomers()}))},t.prototype.getlocalCustomer=function(t){for(var e=0;e<this.customers.length;e++)if(this.customers[e]._id===t)return this.customers[e];return null},t.prototype.getlocalCustomers=function(){return this.customers},t.prototype.refreshLocalCustomers=function(){return new Promise((function(t){t(null)}))},t.prototype.addCustomer=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("customers",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.addCustomers=function(t){var e=this;return new Promise((function(n,o){for(var i=new Array,a=function(n){i[n]=new Promise((function(o){e.vhmongo_firebase.database().addDoc("customers",t[n]).then((function(t){o(t)}),(function(){o(null)}))}))},s=0;s<t.length;s++)a(s);Promise.all(i).then((function(t){var e=t.filter((function(t){return null!=t}));n(e)}))}))},t.prototype.updateCustomer=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("customers",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteCustomer=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("bills",{id_customer:{$eq:t}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("customers",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getCustomer=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("customers",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getCustomers=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("customers").then((function(n){t.customers=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventSuppliers=function(){this.subjectsuppliers.next(this.suppliers)},t.prototype.observableLocalSuppliers=function(){return this.subjectsuppliers},t.prototype.getObservableLocalSuppliers=function(){var t=this;return new c.Observable((function(e){t.observableLocalSuppliers().subscribe((function(t){e.next(t)})),t.publishObservableEventSuppliers()}))},t.prototype.getlocalSupplier=function(t){for(var e=0;e<this.suppliers.length;e++)if(this.suppliers[e]._id===t)return Object.assign({},this.suppliers[e]);return null},t.prototype.getlocalSuppliers=function(){return this.suppliers},t.prototype.refreshLocalSuppliers=function(){return new Promise((function(t){t(null)}))},t.prototype.addSupplier=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("suppliers",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.addSuppliers=function(t){var e=this;return new Promise((function(n,o){for(var i=new Array,a=function(n){i[n]=new Promise((function(o){e.vhmongo_firebase.database().addDoc("suppliers",t[n]).then((function(t){o(t)}),(function(){o(null)}))}))},s=0;s<t.length;s++)a(s);Promise.all(i).then((function(t){var e=t.filter((function(t){return null!=t}));n(e)}))}))},t.prototype.updateSupplier=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("suppliers",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteSupplier=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("bills",{id_supplier:{$eq:t}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("suppliers",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getSupplier=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("suppliers",t).then((function(t){n(t)}))}))},t.prototype.getSuppliers=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("suppliers").then((function(n){t.suppliers=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventWallets=function(){this.subjectwallets.next(this.wallets)},t.prototype.observableLocalWallets=function(){return this.subjectwallets},t.prototype.getObservableLocalWallets=function(){var t=this;return new c.Observable((function(e){t.observableLocalWallets().subscribe((function(t){e.next(t)})),t.publishObservableEventWallets()}))},t.prototype.getlocalWallet=function(t){for(var e=0;e<this.wallets.length;e++)if(this.wallets[e]._id===t)return this.wallets[e];return null},t.prototype.getlocalWallets=function(){return this.wallets},t.prototype.refreshLocalWallets=function(){return new Promise((function(t){t(null)}))},t.prototype.addWallet=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("wallets",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateWallet=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("wallets",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteWallet=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("bills",{id_wallet:{$eq:t}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("wallets",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getWallet=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("wallets",t).then((function(t){n(t)}))}))},t.prototype.getWallets=function(){var t=this;return new Promise((function(e,n){t.wallets=new Array,t.vhmongo_firebase.database().getDocs("wallets").then((function(n){t.wallets=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventTaxs=function(){this.subjecttaxs.next(this.taxs)},t.prototype.observableLocalTaxs=function(){return this.subjecttaxs},t.prototype.getObservableLocalTaxs=function(){var t=this;return new c.Observable((function(e){t.observableLocalTaxs().subscribe((function(t){e.next(t)})),t.publishObservableEventTaxs()}))},t.prototype.getlocalTax=function(t){for(var e=0;e<this.taxs.length;e++)if(this.taxs[e]._id===t)return this.taxs[e];return null},t.prototype.getlocalTaxs=function(){return this.taxs},t.prototype.refreshLocalTaxs=function(){return new Promise((function(t){t(null)}))},t.prototype.addTax=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("taxs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateTax=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("taxs",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteTax=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("taxs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getTax=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("taxs",t).then((function(t){n(t)}))}))},t.prototype.getTaxs=function(){var t=this;return new Promise((function(e,n){t.taxs=new Array,t.vhmongo_firebase.database().getDocs("taxs").then((function(n){t.taxs=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventCategorys=function(){this.subjectcategorys.next()},t.prototype.observableLocalCategorys=function(){return this.subjectcategorys},t.prototype.getObservableLocalCategorys=function(t){var e=this;return new c.Observable((function(n){e.observableLocalCategorys().subscribe((function(){n.next(e.getlocalCategorys(t))})),e.publishObservableEventCategorys()}))},t.prototype.getlocalCategory=function(t){for(var e=0;e<this.categorys.length;e++)if(this.categorys[e]._id===t)return Object.assign({},this.categorys[e]);return null},t.prototype.getlocalCategorys=function(t){var e=new Array;return 1===t||2===t||3===t||4===t||4===t?this.categorys.forEach((function(n){n.type===t&&e.push(Object.assign({},n))})):1234===t?this.categorys.forEach((function(t){1!==t.type&&2!==t.type&&3!==t.type&&4!==t.type||e.push(Object.assign({},t))})):this.categorys.forEach((function(t){e.push(Object.assign({},t))})),e},t.prototype.refreshLocalCategorys=function(){return new Promise((function(t){t(null)}))},t.prototype.addCategory=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("categorys",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.addCategorys=function(t){var e=this;return new Promise((function(n,o){for(var i=new Array,a=function(n){i[n]=new Promise((function(o){e.vhmongo_firebase.database().addDoc("categorys",t[n]).then((function(t){o(t)}),(function(){o(null)}))}))},s=0;s<t.length;s++)a(s);Promise.all(i).then((function(t){var e=t.filter((function(t){return null!=t}));n(e)}))}))},t.prototype.updateCategory=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("categorys",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteCategory=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("products",{id_category:{$eq:t}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("categorys",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getCategory=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("categorys",t).then((function(t){n(t)}))}))},t.prototype.getCategorys=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("categorys").then((function(n){t.categorys=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventInventorytimes=function(){this.subjectinventorytimes.next(this.inventorytimes)},t.prototype.observableLocalInventorytimes=function(){return this.subjectinventorytimes},t.prototype.getObservableLocalInventorytimes=function(){var t=this;return new c.Observable((function(e){t.observableLocalInventorytimes().subscribe((function(t){e.next(t)})),t.publishObservableEventInventorytimes()}))},t.prototype.getlocalInventorytime=function(t){for(var e=0;e<this.inventorytimes.length;e++)if(this.inventorytimes[e]._id===t)return this.inventorytimes[e];return null},t.prototype.getlocalInventorytimes=function(){return this.inventorytimes},t.prototype.refreshLocalInventorytimes=function(){return new Promise((function(t){t(null)}))},t.prototype.addInventorytime=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("inventorytimes",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateInventorytime=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("inventorytimes",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteInventorytime=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("inventorytimes",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getInventorytime=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("inventorytimes",t).then((function(t){n(t)}))}))},t.prototype.getInventorytimes=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("inventorytimes").then((function(n){t.inventorytimes=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventCustomerClasss=function(){this.subjectcustomer_classs.next(this.customer_classs)},t.prototype.observableLocalCustomerClasss=function(){return this.subjectcustomer_classs},t.prototype.getObservableLocalCustomerClasss=function(){var t=this;return new c.Observable((function(e){t.observableLocalCustomerClasss().subscribe((function(t){e.next(t)})),t.publishObservableEventCustomerClasss()}))},t.prototype.getlocalCustomerClass=function(t){for(var e=0;e<this.customer_classs.length;e++)if(this.customer_classs[e]._id===t)return JSON.parse(JSON.stringify(this.customer_classs[e]));return null},t.prototype.getlocalCustomerClasss=function(){return JSON.parse(JSON.stringify(this.customer_classs))},t.prototype.addCustomerClass=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("customer_classs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateCustomerClass=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("customer_classs",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteCustomerClass=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("customer_classs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.publishObservableEventDiscount_bills=function(){this.subjectdiscount_bills.next(this.discount_bills)},t.prototype.observableLocalDiscount_bills=function(){return this.subjectdiscount_bills},t.prototype.getObservableLocalDiscount_bills=function(){var t=this;return new c.Observable((function(e){t.observableLocalDiscount_bills().subscribe((function(t){e.next(t)})),t.publishObservableEventDiscount_bills()}))},t.prototype.getlocalDiscount_bill=function(t){for(var e=0;e<this.discount_bills.length;e++)if(this.discount_bills[e]._id===t)return JSON.parse(JSON.stringify(this.discount_bills[e]));return null},t.prototype.getlocalDiscount_bills=function(){return JSON.parse(JSON.stringify(this.discount_bills))},t.prototype.addDiscount_bill=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("discount_bills",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateDiscount_bill=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("discount_bills",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteDiscount_bill=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("discount_bills",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.addDiscount_sales=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("discount_saless",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateDiscount_sales=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("discount_saless",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteDiscount_sales=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("discount_saless",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getDiscount_sales=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("discount_saless",t).then((function(t){n(t)}))}))},t.prototype.getDiscount_saless=function(){var t=this;return new Promise((function(e,n){t.discount_saless=new Array,t.vhmongo_firebase.database().getDocs("discount_saless").then((function(n){t.discount_saless=n,e(n)}),(function(t){n(t)}))}))},t.prototype.addCommission=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("commissions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateCommission=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("commissions",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteCommission=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("commissions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getCommission=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("commissions",t).then((function(t){n(t)}))}))},t.prototype.getCommissions=function(){var t=this;return new Promise((function(e,n){t.commissions=new Array,t.vhmongo_firebase.database().getDocs("commissions").then((function(n){t.commissions=n,e(n)}),(function(t){n(t)}))}))},t.prototype.getlocalDelivery=function(t){for(var e=0;e<this.deliverys.length;e++)if(this.deliverys[e]._id===t)return this.deliverys[e];return null},t.prototype.getlocalDeliverys=function(){return this.deliverys},t.prototype.refreshLocalDeliverys=function(){var t=this;return new Promise((function(e){t.getDeliverys().then((function(){e(null)}))}))},t.prototype.addDelivery=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("deliverys",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateDelivery=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("deliverys",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteDelivery=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("deliverys",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getDelivery=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("deliverys",t).then((function(t){n(t)}))}))},t.prototype.getDeliverys=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("deliverys").then((function(n){t.deliverys=n,e(n)}),(function(t){n(t)}))}))},t.prototype.getlocalAddress=function(t){for(var e=0;e<this.addresss.length;e++)if(this.addresss[e]._id===t)return this.addresss[e];return null},t.prototype.getlocalAddresss=function(){return this.addresss},t.prototype.refreshLocalAddresss=function(){var t=this;return new Promise((function(e){t.getAddresss().then((function(){e(null)}))}))},t.prototype.addAddress=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("addresss",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateAddress=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("addresss",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteAddress=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("addresss",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getAddress=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("addresss",t).then((function(t){n(t)}))}))},t.prototype.getAddresss=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("addresss").then((function(n){t.addresss=n,e(n)}),(function(t){n(t)}))}))},t.prototype.getlocalIncoming_group=function(t){for(var e=0;e<this.incoming_groups.length;e++)if(this.incoming_groups[e]._id===t)return Object.assign({},this.incoming_groups[e]);return null},t.prototype.getlocalIncoming_groups=function(){return E(this.incoming_groups)},t.prototype.refreshLocalIncoming_groups=function(){var t=this;return new Promise((function(e){t.getIncoming_groups().then((function(){e(null)}))}))},t.prototype.addIncoming_group=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("incoming_groups",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateIncoming_group=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("incoming_groups",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteIncoming_group=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("bills",{id_incoming_group:{$eq:t}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("incoming_groups",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getIncoming_groups=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("incoming_groups").then((function(n){t.incoming_groups=n,t.incoming_groups=t.vhAlgorithm.sortVietnamesebyASC(t.incoming_groups,"name"),e(t.incoming_groups)}),(function(t){n(t)}))}))},t.prototype.getlocalSpending_group=function(t){for(var e=0;e<this.spending_groups.length;e++)if(this.spending_groups[e]._id===t)return Object.assign({},this.spending_groups[e]);return null},t.prototype.getlocalSpending_groups=function(){return E(this.spending_groups)},t.prototype.refreshLocalSpending_groups=function(){var t=this;return new Promise((function(e){t.getSpending_groups().then((function(){e(null)}))}))},t.prototype.addSpending_group=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("spending_groups",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateSpending_group=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("spending_groups",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteSpending_group=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("bills",{id_spending_group:{$eq:t}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("spending_groups",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getSpending_groups=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("spending_groups").then((function(n){t.spending_groups=n,t.spending_groups=t.vhAlgorithm.sortVietnamesebyASC(t.spending_groups,"name"),e(t.spending_groups)}),(function(t){n(t)}))}))},t.prototype.addPatternMenu=function(t){var e=this;return new Promise((function(n,o){var i=Object.assign(Object.assign({},t),{id_branch:e.getDefaultBranch()._id});e.vhmongo_firebase.database().addDoc("patternmenus",i).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updatePatternMenu=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("patternmenus",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deletePatternMenu=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("patternmenus",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPatternMenu=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("patternmenus",t).then((function(t){n(t)}))}))},t.prototype.getPatternMenus=function(){var t=this;return new Promise((function(e,n){t.taxs=new Array,t.vhmongo_firebase.database().getDocsByFields("patternmenus",{id_branch:{$eq:t.getDefaultBranch()._id}},{},{},0).then((function(n){t.patternmenus=n,e(n)}),(function(t){n(t)}))}))},t.prototype.updateDebtAtBeginningCustomer=function(t,e,n){var o=this;return new Promise((function(i,a){var s=o.getlocalCustomer(t),r={};null!=s[e]?r[e]=s[e]:r[e]={},r[e].debt_beginning=n,o.vhmongo_firebase.database().updateDoc("customers",t,Object.assign({},r)).then((function(t){i(t)}),(function(t){a(t)}))}))},t.prototype.getDebtAtBeginningCustomers_byIDcustomer=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("debt_at_beginning_customers",{id_customer:{$eq:t}},{}).then((function(t){n(t)})).catch((function(t){o(t)}))}))},t.prototype.getDebtAtBeginningCustomers_byIDbranch=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("debt_at_beginning_customers",{id_branch:{$eq:t}},{}).then((function(t){n(t)})).catch((function(t){o(t)}))}))},t.prototype.getDebtAtBeginningCustomers_byIDcustomer_byIDbranch=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().getDocsByFields("debt_at_beginning_customers",{id_customer:{$eq:t},id_branch:{$eq:e}},{}).then((function(t){o(t)})).catch((function(t){i(t)}))}))},t.prototype.getDebtAtBeginningCustomers=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("debt_at_beginning_customers").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.updateDebtAtBeginningSupplier=function(t,e,n){var o=this;return new Promise((function(i,a){var s=o.getlocalSupplier(t),r={};null!=s[e]?r[e]=s[e]:r[e]={},r[e].debt_beginning=n,o.vhmongo_firebase.database().updateDoc("suppliers",t,Object.assign({},r)).then((function(t){i(t)}),(function(t){a(t)}))}))},t.prototype.getDebtAtBeginningSuppliers_byIDsupplier=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("debt_at_beginning_suppliers",{id_supplier:{$eq:t}},{}).then((function(t){n(t)})).catch((function(t){o(t)}))}))},t.prototype.getDebtAtBeginningSuppliers_byIDbranch=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("debt_at_beginning_suppliers",{id_branch:{$eq:t}},{}).then((function(t){n(t)})).catch((function(t){o(t)}))}))},t.prototype.getDebtAtBeginningSuppliers_byIDsupplier_byIDbranch=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().getDocsByFields("debt_at_beginning_suppliers",{id_supplier:{$eq:t},id_branch:{$eq:e}},{}).then((function(t){o(t)})).catch((function(t){i(t)}))}))},t.prototype.getDebtAtBeginningSuppliers=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("debt_at_beginning_suppliers").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.setDefaultBranch=function(t){for(var e=0;e<this.branchs.length;e++)if(this.branchs[e]._id===t){localStorage.setItem(this.vhmongo_firebase.auth().getProjectName()+"_default_branch",JSON.stringify(this.branchs[e]));break}},t.prototype.getDefaultBranch=function(){return 0==this.branchs.length?null:localStorage.getItem(this.vhmongo_firebase.auth().getProjectName()+"_default_branch")?JSON.parse(localStorage.getItem(this.vhmongo_firebase.auth().getProjectName()+"_default_branch")):null},t.prototype.clearDefaultBranch=function(){localStorage.setItem(this.vhmongo_firebase.auth().getProjectName()+"_default_branch",null)},t.prototype.isChains=function(){return 0==this.branchs.length?null:1!=this.branchs.length},t.prototype.publishObservableEventBranchs=function(){this.subjectbranchs.next(this.branchs)},t.prototype.observableLocalBranchs=function(){return this.subjectbranchs},t.prototype.getObservableLocalBranchs=function(){var t=this;return new c.Observable((function(e){t.observableLocalBranchs().subscribe((function(t){e.next(t)})),t.publishObservableEventBranchs()}))},t.prototype.getlocalBranch=function(t){for(var e=0;e<this.branchs.length;e++)if(this.branchs[e]._id===t)return this.branchs[e];return null},t.prototype.getlocalBranchs=function(){return this.branchs},t.prototype.refreshLocalBranchs=function(){var t=this;return new Promise((function(e){t.getBranchs().then((function(){e(null)}))}))},t.prototype.addBranch=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("branchs",t).then((function(t){var o=new Array,i=e.getlocalProducts(3),a=Object.assign(Object.assign({},t),{opentime:"8h:00 AM",closetime:"10h:00 PM",img:"",tax_number:""});a.appsetting_name="store_info",a.id_branch=t._id,delete a._id,o.push(e.vhmongo_firebase.database().addDoc("appsettingbranchs",a));for(var s=0;s<i.length;s++)i[s].quantity_branch[t._id]=0,o.push(e.updateProduct(i[s]._id,{quantity_branch:i[s].quantity_branch}));Promise.all(o).then((function(){n(t)}))}),(function(t){o(t)}))}))},t.prototype.updateBranch=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("branchs",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteBranch=function(t){var e=this;return new Promise((function(n,o){var i=new Array;i[0]=e.vhmongo_firebase.database().getDocsByFields("wallets",{id_branch:{$eq:t}},{},{},1),i[1]=e.vhmongo_firebase.database().getDocsByFields("bills",{id_branch:{$eq:t}},{},{},1),i[2]=e.vhmongo_firebase.database().getDocsByFields("bills",{id_branch_receive:{$eq:t}},{},{},1),Promise.all(i).then((function(i){0===i[0].length&&0===i[1].length&&0===i[2].length?e.vhmongo_firebase.database().deleteDoc("branchs",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getBranch=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("branchs",t).then((function(t){n(t)}))}))},t.prototype.getBranchs=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("branchs").then((function(n){t.branchs=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventPrinters=function(){this.subjectprinters.next(this.printers)},t.prototype.observableLocalPrinters=function(){return this.subjectprinters},t.prototype.getObservableLocalPrinters=function(){var t=this;return new c.Observable((function(e){t.observableLocalPrinters().subscribe((function(t){e.next(t)})),t.publishObservableEventPrinters()}))},t.prototype.getlocalPrinter=function(t){for(var e=0;e<this.printers.length;e++)if(this.printers[e]._id===t)return this.printers[e];return null},t.prototype.getlocalPrinters=function(){return this.printers},t.prototype.refreshLocalPrinters=function(){return new Promise((function(t,e){t(null)}))},t.prototype.addPrinter=function(t){var e=this;return new Promise((function(n,o){var i=Object.assign({},t);i.uuid=e.hwinfo.uuid,e.vhmongo_firebase.database().addDoc("printers",i).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updatePrinter=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("printers",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deletePrinter=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("printers",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPrinter=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("printers",t).then((function(t){t&&(null==t||delete t.uuid),n(t)}),(function(t){o(t)}))}))},t.prototype.getPrinters=function(){var t=this;return new Promise((function(e){t.vhmongo_firebase.database().getDocsByFields("printers",{uuid:{$eq:t.hwinfo.uuid}},{},{},0).then((function(n){t.printers=new Array,n.length>0&&n.forEach((function(e){null==e||delete e.uuid,t.printers.push(e)})),e(t.printers)}))}))},t.prototype.createBill_Billdetail=function(t,e){var n=this;return new Promise((function(o,i){n.sync_code=Math.random().toString(36).substr(2,10).toUpperCase(),t.sync_code=n.sync_code,t.bill_code=n.vhAlgorithm.createBillCode(null==t?void 0:t.date),n.vhmongo_firebase.database().addDoc("bills",t).then((function(a){if(a){for(var s=new Array,r=0;r<e.length;r++){var l=e[r];l.id_bill=a._id,t.bill_code&&(l.bill_code=t.bill_code),t.date&&(l.date=t.date),t.id_area&&(l.id_area=t.id_area),t.id_table&&(l.id_table=t.id_table),"number"==typeof t.tax&&(l.tax=t.tax),"number"==typeof t.bill_type&&(l.bill_type=t.bill_type),t.id_cashier&&(l.id_cashier=t.id_cashier),t.id_employee&&(l.id_employee=t.id_employee),t.id_supplier&&(l.id_supplier=t.id_supplier),t.id_customer&&(l.id_customer=t.id_customer),t.id_inventorytime&&(l.id_inventorytime=t.id_inventorytime),t.id_branch&&(l.id_branch=t.id_branch),s[r]=n.vhmongo_firebase.database().addDoc("vhbill_details",l)}n.vhQuery.asyncPromiseAll(s).then((function(i){if(1===t.bill_type||3===t.bill_type||10===t.bill_type){for(var s=new Array,r=function(o){s[o]=new Promise((function(i){if(3===e[o].ptype){var a=n.getlocalProduct(e[o].id_product),s={};null!=a.quantity_branch?(s=a.quantity_branch,null!=a.quantity_branch[t.id_branch]?s[t.id_branch]=s[t.id_branch]-e[o].quantity:s[t.id_branch]=-e[o].quantity):s[t.id_branch]=-e[o].quantity;var r=a.quantity-e[o].quantity;n.vhmongo_firebase.database().updateDoc("products",a._id,{quantity:r,quantity_branch:s}).then((function(){i(null)}))}else i(null)}))},l=0;l<e.length;l++)r(l);n.vhQuery.asyncPromiseAll(s).then((function(){o(a)}))}else if(2===t.bill_type||16===t.bill_type){s=new Array;var c=function(o){s[o]=new Promise((function(i){if(3===e[o].ptype){var a=n.getlocalProduct(e[o].id_product),s={};null!=a.quantity_branch?(s=a.quantity_branch,null!=a.quantity_branch[t.id_branch]?s[t.id_branch]=s[t.id_branch]+e[o].quantity:s[t.id_branch]=e[o].quantity):s[t.id_branch]=e[o].quantity;var r=a.quantity+e[o].quantity;n.vhmongo_firebase.database().updateDoc("products",a._id,{quantity:r,quantity_branch:s}).then((function(){i(null)}))}else i(null)}))};for(l=0;l<e.length;l++)c(l);n.vhQuery.asyncPromiseAll(s).then((function(){o(a)}))}else if(9===t.bill_type){s=new Array;var u=function(o){s[o]=new Promise((function(i){var a;if(3===e[o].ptype){var s=n.getlocalProduct(e[o].id_product),r={};null!=s.quantity_branch?(r=s.quantity_branch,null!=s.quantity_branch[t.id_branch]?r[t.id_branch]=r[t.id_branch]+e[o].quantity:r[t.id_branch]=e[o].quantity):r[t.id_branch]=e[o].quantity;var l=s.quantity+e[o].quantity,c={};null!=s[t.id_branch]&&null!=s[t.id_branch].inventory&&(c[t.id_branch]=s[t.id_branch],null===(a=c[t.id_branch])||void 0===a||delete a.inventory),n.vhmongo_firebase.database().updateDoc("products",s._id,Object.assign({quantity:l,quantity_branch:r},c)).then((function(){i(null)}))}else i(null)}))};for(l=0;l<e.length;l++)u(l);n.vhQuery.asyncPromiseAll(s).then((function(){o(a)}))}else 5!==t.bill_type&&6!==t.bill_type&&13!==t.bill_type&&14!==t.bill_type&&15!==t.bill_type&&17!==t.bill_type&&20!==t.bill_type&&29!==t.bill_type||o(a)}))}else i({message:"Invoice creation failed"})}),(function(t){i(t)}))}))},t.prototype.saveBill_Billdetail=function(t){var e=this;return new Promise((function(n,o){e.sync_code=Math.random().toString(36).substr(2,10).toUpperCase();var i=e.vhmongo_firebase.database().getDoc("bills",t),a=e.vhmongo_firebase.database().getDocsByFields("vhbill_details",{id_bill:{$eq:t}},{},{},0);Promise.all([i,a]).then((function(o){if(5===o[0].bill_type){for(var i=new Array,a=0;a<o[1].length;a++){var s=Object.assign({},o[1][a]);s.id_bill=o[0]._id,s.bill_type=1,o[0].id_area&&(s.id_area=o[0].id_area),o[0].id_table&&(s.id_table=o[0].id_table),o[0].date&&(s.date=o[0].date),"number"==typeof o[0].tax&&(s.tax=o[0].tax),"number"==typeof o[0].bill_type&&(s.bill_type=1),o[0].id_cashier&&(s.id_cashier=o[0].id_cashier),o[0].id_employee&&(s.id_employee=o[0].id_employee),o[0].id_supplier&&(s.id_supplier=o[0].id_supplier),o[0].id_customer&&(s.id_customer=o[0].id_customer),i[a]=e.vhmongo_firebase.database().updateDoc("vhbill_details",o[1][a]._id,s)}i[o[1].length]=e.vhmongo_firebase.database().updateDoc("bills",t,{bill_type:1,uuid:null,sync_code:e.sync_code}),Promise.all(i).then((function(){for(var t=new Array,i=function(n){t[n]=new Promise((function(t){if(3===o[1][n].ptype){var i=e.getlocalProduct(o[1][n].id_product),a={};null!=i.quantity_branch?(a=i.quantity_branch,null!=i.quantity_branch[o[0].id_branch]?a[o[0].id_branch]=a[o[0].id_branch]-o[1][n].quantity:a[o[0].id_branch]=-o[1][n].quantity):a[o[0].id_branch]=-o[1][n].quantity;var s=i.quantity-o[1][n].quantity;e.vhmongo_firebase.database().updateDoc("products",i._id,{quantity:s,quantity_branch:a}).then((function(){t(null)}))}else t(null)}))},a=0;a<o[1].length;a++)i(a);e.vhQuery.asyncPromiseAll(t).then((function(){n(o)}))}))}}))}))},t.prototype.updateBill_Billdetail=function(t,e,n){var o=this;return new Promise((function(i,a){o.sync_code=Math.random().toString(36).substr(2,10).toUpperCase(),e.sync_code=o.sync_code,new Promise((function(n){var i=o.vhmongo_firebase.database().getDoc("bills",t),a=o.vhmongo_firebase.database().getDocsByFields("vhbill_details",{id_bill:{$eq:t}},{},{},0);Promise.all([i,a]).then((function(t){if(1===t[0].bill_type||3===t[0].bill_type||10===t[0].bill_type){for(var i=new Array,a=0;a<t[1].length;a++)i[a]=o.vhmongo_firebase.database().deleteDoc("vhbill_details",t[1][a]._id);Promise.all(i).then((function(){for(var i=new Array,a=function(n){i[n]=new Promise((function(i){if(3===t[1][n].ptype){var a=o.getlocalProduct(t[1][n].id_product),s={};null!=a.quantity_branch?(s=a.quantity_branch,null!=a.quantity_branch[e.id_branch]?s[e.id_branch]=s[e.id_branch]+t[1][n].quantity:s[e.id_branch]=t[1][n].quantity):s[e.id_branch]=t[1][n].quantity;var r=a.quantity+t[1][n].quantity;o.vhmongo_firebase.database().updateDoc("products",a._id,{quantity:r,quantity_branch:s}).then((function(){i(null)}))}else i(null)}))},s=0;s<t[1].length;s++)a(s);o.vhQuery.asyncPromiseAll(i).then((function(){n(t)}))}))}else if(2===t[0].bill_type||16===t[0].bill_type){for(i=new Array,a=0;a<t[1].length;a++)i[a]=o.vhmongo_firebase.database().deleteDoc("vhbill_details",t[1][a]._id);Promise.all(i).then((function(){for(var i=new Array,a=function(n){i[n]=new Promise((function(i){if(3===t[1][n].ptype){var a=o.getlocalProduct(t[1][n].id_product),s={};null!=a.quantity_branch?(s=a.quantity_branch,null!=a.quantity_branch[e.id_branch]?s[e.id_branch]=s[e.id_branch]-t[1][n].quantity:s[e.id_branch]=-t[1][n].quantity):s[e.id_branch]=-t[1][n].quantity;var r=a.quantity-t[1][n].quantity;o.vhmongo_firebase.database().updateDoc("products",a._id,{quantity:r,quantity_branch:s}).then((function(){i(null)}))}else i(null)}))},s=0;s<t[1].length;s++)a(s);o.vhQuery.asyncPromiseAll(i).then((function(){n(t)}))}))}else if(9===t[0].bill_type){for(i=new Array,a=0;a<t[1].length;a++)i[a]=o.vhmongo_firebase.database().deleteDoc("vhbill_details",t[1][a]._id);Promise.all(i).then((function(){for(var i=new Array,a=function(n){i[n]=new Promise((function(i){var a;if(3===t[1][n].ptype){var s=o.getlocalProduct(t[1][n].id_product),r={};null!=s.quantity_branch?(r=s.quantity_branch,null!=s.quantity_branch[e.id_branch]?r[e.id_branch]=r[e.id_branch]-t[1][n].quantity:r[e.id_branch]=-t[1][n].quantity):r[e.id_branch]=-t[1][n].quantity;var l=s.quantity-t[1][n].quantity,c={};null!=s[e.id_branch]&&null!=s[e.id_branch].inventory&&(c[e.id_branch]=s[e.id_branch],null===(a=c[e.id_branch])||void 0===a||delete a.inventory),o.vhmongo_firebase.database().updateDoc("products",s._id,Object.assign({quantity:l,quantity_branch:r},c)).then((function(){i(null)}))}else i(null)}))},s=0;s<t[1].length;s++)a(s);o.vhQuery.asyncPromiseAll(i).then((function(){n(t)}))}))}else if(5===t[0].bill_type||6===t[0].bill_type||13===t[0].bill_type||14===t[0].bill_type||15===t[0].bill_type||17===t[0].bill_type||20===t[0].bill_type||29===t[0].bill_type){for(i=new Array,a=0;a<t[1].length;a++)i[a]=o.vhmongo_firebase.database().deleteDoc("vhbill_details",t[1][a]._id);Promise.all(i).then((function(){n(t)}))}}))})).then((function(a){if(1===e.bill_type||3===e.bill_type||10===e.bill_type){var s=new Array;(l=Object.assign({},e)).bill_code=a[0].bill_code,s[n.length]=o.vhmongo_firebase.database().updateDoc("bills",t,l);for(var r=0;r<n.length;r++){(_=Object.assign({},n[r])).id_bill=t,a[0].bill_code&&(_.bill_code=a[0].bill_code),e.date&&(_.date=e.date),e.id_area&&(_.id_area=e.id_area),e.id_table&&(_.id_table=e.id_table),"number"==typeof e.tax&&(_.tax=e.tax),"number"==typeof e.bill_type&&(_.bill_type=e.bill_type),e.id_cashier&&(_.id_cashier=e.id_cashier),e.id_employee&&(_.id_employee=e.id_employee),e.id_supplier&&(_.id_supplier=e.id_supplier),e.id_customer&&(_.id_customer=e.id_customer),e.id_inventorytime&&(_.id_inventorytime=e.id_inventorytime),e.id_branch&&(_.id_branch=e.id_branch),s[r]=o.vhmongo_firebase.database().addDoc("vhbill_details",_)}Promise.all(s).then((function(){for(var a=new Array,s=function(t){a[t]=new Promise((function(i){if(3===n[t].ptype){var a=o.getlocalProduct(n[t].id_product),s={};null!=a.quantity_branch?(s=a.quantity_branch,null!=a.quantity_branch[e.id_branch]?s[e.id_branch]=s[e.id_branch]-n[t].quantity:s[e.id_branch]=-n[t].quantity):s[e.id_branch]=-n[t].quantity;var r=a.quantity-n[t].quantity;o.vhmongo_firebase.database().updateDoc("products",a._id,{quantity:r,quantity_branch:s}).then((function(){i(null)}))}else i(null)}))},r=0;r<n.length;r++)s(r);o.vhQuery.asyncPromiseAll(a).then((function(){i(t)}))}))}else if(2===e.bill_type||16===e.bill_type){s=new Array;(l=Object.assign({},e)).bill_code=a[0].bill_code,l.date=a[0].date,s[n.length]=o.vhmongo_firebase.database().updateDoc("bills",t,l);for(r=0;r<n.length;r++){(_=Object.assign({},n[r])).id_bill=t,a[0].bill_code&&(_.bill_code=a[0].bill_code),a[0].date&&(_.date=a[0].date),e.id_area&&(_.id_area=e.id_area),e.id_table&&(_.id_table=e.id_table),"number"==typeof e.tax&&(_.tax=e.tax),"number"==typeof e.bill_type&&(_.bill_type=e.bill_type),e.id_cashier&&(_.id_cashier=e.id_cashier),e.id_employee&&(_.id_employee=e.id_employee),e.id_supplier&&(_.id_supplier=e.id_supplier),e.id_customer&&(_.id_customer=e.id_customer),e.id_inventorytime&&(_.id_inventorytime=e.id_inventorytime),e.id_branch&&(_.id_branch=e.id_branch),s[r]=o.vhmongo_firebase.database().addDoc("vhbill_details",_)}Promise.all(s).then((function(){for(var a=new Array,s=function(t){a[t]=new Promise((function(i){if(3===n[t].ptype){var a=o.getlocalProduct(n[t].id_product),s={};null!=a.quantity_branch?(s=a.quantity_branch,null!=a.quantity_branch[e.id_branch]?s[e.id_branch]=s[e.id_branch]+n[t].quantity:s[e.id_branch]=n[t].quantity):s[e.id_branch]=n[t].quantity;var r=a.quantity+n[t].quantity;o.vhmongo_firebase.database().updateDoc("products",a._id,{quantity:r,quantity_branch:s}).then((function(){i(null)}))}else i(null)}))},r=0;r<n.length;r++)s(r);o.vhQuery.asyncPromiseAll(a).then((function(){i(t)}))}))}else if(9===e.bill_type){s=new Array;(l=Object.assign({},e)).bill_code=a[0].bill_code,l.date=a[0].date,s[n.length]=o.vhmongo_firebase.database().updateDoc("bills",t,l);for(r=0;r<n.length;r++){(_=Object.assign({},n[r])).id_bill=t,a[0].bill_code&&(_.bill_code=a[0].bill_code),a[0].date&&(_.date=a[0].date),e.id_area&&(_.id_area=e.id_area),e.id_table&&(_.id_table=e.id_table),"number"==typeof e.tax&&(_.tax=e.tax),"number"==typeof e.bill_type&&(_.bill_type=e.bill_type),e.id_cashier&&(_.id_cashier=e.id_cashier),e.id_employee&&(_.id_employee=e.id_employee),e.id_supplier&&(_.id_supplier=e.id_supplier),e.id_customer&&(_.id_customer=e.id_customer),e.id_inventorytime&&(_.id_inventorytime=e.id_inventorytime),e.id_branch&&(_.id_branch=e.id_branch),s[r]=o.vhmongo_firebase.database().addDoc("vhbill_details",_)}Promise.all(s).then((function(){for(var a=new Array,s=function(t){a[t]=new Promise((function(i){var a;if(3===n[t].ptype){var s=o.getlocalProduct(n[t].id_product),r={};null!=s.quantity_branch?(r=s.quantity_branch,null!=s.quantity_branch[e.id_branch]?r[e.id_branch]=r[e.id_branch]+n[t].quantity:r[e.id_branch]=n[t].quantity):r[e.id_branch]=n[t].quantity;var l=s.quantity+n[t].quantity,c={};null!=s[e.id_branch]&&null!=s[e.id_branch].inventory&&(c[e.id_branch]=s[e.id_branch],null===(a=c[e.id_branch])||void 0===a||delete a.inventory),o.vhmongo_firebase.database().updateDoc("products",s._id,Object.assign({quantity:l,quantity_branch:r},c)).then((function(){i(null)}))}else i(null)}))},r=0;r<n.length;r++)s(r);o.vhQuery.asyncPromiseAll(a).then((function(){i(t)}))}))}else if(5===e.bill_type||6===e.bill_type||13===e.bill_type||14===e.bill_type||15===e.bill_type||17===e.bill_type||20===e.bill_type||29===e.bill_type){var l;s=new Array;(l=Object.assign({},e)).bill_code=a[0].bill_code,l.date=a[0].date,s[n.length]=o.vhmongo_firebase.database().updateDoc("bills",t,l);for(r=0;r<n.length;r++){(_=Object.assign({},n[r])).id_bill=t,a[0].bill_code&&(_.bill_code=a[0].bill_code),a[0].date&&(_.date=a[0].date),e.id_area&&(_.id_area=e.id_area),e.id_table&&(_.id_table=e.id_table),"number"==typeof e.tax&&(_.tax=e.tax),"number"==typeof e.bill_type&&(_.bill_type=e.bill_type),e.id_cashier&&(_.id_cashier=e.id_cashier),e.id_employee&&(_.id_employee=e.id_employee),e.id_supplier&&(_.id_supplier=e.id_supplier),e.id_customer&&(_.id_customer=e.id_customer),e.id_inventorytime&&(_.id_inventorytime=e.id_inventorytime),e.id_branch&&(_.id_branch=e.id_branch),s[r]=o.vhmongo_firebase.database().addDoc("vhbill_details",_)}Promise.all(s).then((function(){i(t)}))}else if(3031===e.bill_type){var c=new Array,u=new Array,d=Object.assign({},a[0]);d.bill_type=30,u[n.length]=o.vhmongo_firebase.database().updateDoc("bills",t,d);for(r=0;r<n.length;r++){var _;(_=Object.assign({},n[r])).id_bill=t,a[0].bill_code&&(_.bill_code=a[0].bill_code),a[0].date&&(_.date=a[0].date),a[0].id_branch&&(_.id_branch=a[0].id_branch),"number"==typeof e.tax&&(_.tax=e.tax),_.bill_type=30,e.id_cashier&&(_.id_cashier=e.id_cashier),e.id_employee&&(_.id_employee=e.id_employee),e.id_supplier&&(_.id_supplier=e.id_supplier),e.id_customer&&(_.id_customer=e.id_customer),e.id_inventorytime&&(_.id_inventorytime=e.id_inventorytime),u[r]=o.vhmongo_firebase.database().addDoc("vhbill_details",_)}o.vhQuery.asyncPromiseAll(u).then((function(){for(var t=new Array,i=function(i){t[i]=new Promise((function(t){if(3===n[i].ptype){var a=o.getlocalProduct(n[i].id_product),s={};null!=a.quantity_branch?(s=a.quantity_branch,null!=a.quantity_branch[e.id_branch]?s[e.id_branch]=s[e.id_branch]-n[i].quantity:s[e.id_branch]=-n[i].quantity):s[e.id_branch]=-n[i].quantity;var r=a.quantity-n[i].quantity;o.vhmongo_firebase.database().updateDoc("products",a._id,{quantity:r,quantity_branch:s}).then((function(){t(null)}))}else t(null)}))},a=0;a<n.length;a++)i(a);c[0]=o.vhQuery.asyncPromiseAll(t)}));var p=new Array,b=Object.assign({},e);null==b||delete b.id_branch_receive,b.bill_type=31,b.bill_code=a[0].bill_code,b.id_branch=a[0].id_branch_receive,b.id_branch_send=a[0].id_branch,b.date=a[0].date,o.vhmongo_firebase.database().addDoc("bills",b).then((function(t){for(var i=0;i<n.length;i++){var s=Object.assign({},n[i]);s.id_bill=t._id,a[0].bill_code&&(s.bill_code=a[0].bill_code),a[0].date&&(s.date=a[0].date),a[0].id_branch&&(s.id_branch=a[0].id_branch_receive),"number"==typeof e.tax&&(s.tax=e.tax),s.bill_type=31,e.id_cashier&&(s.id_cashier=e.id_cashier),e.id_employee&&(s.id_employee=e.id_employee),e.id_supplier&&(s.id_supplier=e.id_supplier),e.id_customer&&(s.id_customer=e.id_customer),e.id_inventorytime&&(s.id_inventorytime=e.id_inventorytime),p[i]=o.vhmongo_firebase.database().addDoc("vhbill_details",s)}o.vhQuery.asyncPromiseAll(p).then((function(){for(var t=new Array,i=function(i){t[i]=new Promise((function(t){if(3===n[i].ptype){var a=o.getlocalProduct(n[i].id_product),s={};null!=a.quantity_branch?(s=a.quantity_branch,null!=a.quantity_branch[e.id_branch]?s[e.id_branch]=s[e.id_branch]+n[i].quantity:s[e.id_branch]=n[i].quantity):s[e.id_branch]=n[i].quantity;var r=a.quantity+n[i].quantity;o.vhmongo_firebase.database().updateDoc("products",a._id,{quantity:r,quantity_branch:s}).then((function(){t(null)}))}else t(null)}))},a=0;a<n.length;a++)i(a);c[1]=o.vhQuery.asyncPromiseAll(t)}))}),(function(t){console.log("error",t)})),o.vhQuery.asyncPromiseAll(c).then((function(){i(t)}))}}))}))},t.prototype.deleteBill_Billdetail=function(t){var e=this;return new Promise((function(n,o){var i=e.vhmongo_firebase.database().getDoc("bills",t),a=e.vhmongo_firebase.database().getDocsByFields("vhbill_details",{id_bill:{$eq:t}},{},{},0);e.vhQuery.asyncPromiseAll([i,a]).then((function(i){var a=new Array;if(!i[0])return o({message:"id_bill "+t+" không tồn tại"});if(1===i[0].bill_type){for(var s=0;s<i[1].length;s++)a[s]=e.vhmongo_firebase.database().deleteDoc("vhbill_details",i[1][s]._id);a[i[1].length]=e.vhmongo_firebase.database().deleteDoc("bills",t)}else if(2===i[0].bill_type){for(s=0;s<i[1].length;s++)a[s]=e.vhmongo_firebase.database().deleteDoc("vhbill_details",i[1][s]._id);a[i[1].length]=e.vhmongo_firebase.database().deleteDoc("bills",t)}else if(3===i[0].bill_type){for(s=0;s<i[1].length;s++)a[s]=e.vhmongo_firebase.database().deleteDoc("vhbill_details",i[1][s]._id);a[i[1].length]=e.vhmongo_firebase.database().deleteDoc("bills",t)}else if(9===i[0].bill_type){for(s=0;s<i[1].length;s++)a[s]=e.vhmongo_firebase.database().deleteDoc("vhbill_details",i[1][s]._id);a[i[1].length]=e.vhmongo_firebase.database().deleteDoc("bills",t)}else if(10===i[0].bill_type){for(s=0;s<i[1].length;s++)a[s]=e.vhmongo_firebase.database().deleteDoc("vhbill_details",i[1][s]._id);a[i[1].length]=e.vhmongo_firebase.database().deleteDoc("bills",t)}else if(16===i[0].bill_type){for(s=0;s<i[1].length;s++)a[s]=e.vhmongo_firebase.database().deleteDoc("vhbill_details",i[1][s]._id);a[i[1].length]=e.vhmongo_firebase.database().deleteDoc("bills",t)}else{if(5!==i[0].bill_type&&6!==i[0].bill_type&&13!==i[0].bill_type&&14!==i[0].bill_type&&15!==i[0].bill_type&&17!==i[0].bill_type&&20!==i[0].bill_type&&29!==i[0].bill_type)return 7===i[0].bill_type||8===i[0].bill_type||11===i[0].bill_type||12===i[0].bill_type?o({message:"Loại bill_type "+i[0].bill_type+"này không phát sinh bill_detail dùng hàm deleteBill xóa"}):o({message:"Loại bill_type "+i[0].bill_type+" này không thể xóa hoặc liên hệ anh Huy"});for(s=0;s<i[1].length;s++)a[s]=e.vhmongo_firebase.database().deleteDoc("vhbill_details",i[1][s]._id);a[i[1].length]=e.vhmongo_firebase.database().deleteDoc("bills",t)}1===i[0].bill_type||3===i[0].bill_type||10===i[0].bill_type?e.vhQuery.asyncPromiseAll(a).then((function(){for(var t=new Array,o=function(n){t[n]=new Promise((function(t){if(3===i[1][n].ptype){var o=e.getlocalProduct(i[1][n].id_product),a={};null!=o.quantity_branch?(a=o.quantity_branch,null!=o.quantity_branch[i[0].id_branch]?a[i[0].id_branch]=a[i[0].id_branch]+i[1][n].quantity:a[i[0].id_branch]=i[1][n].quantity):a[i[0].id_branch]=i[1][n].quantity;var s=o.quantity+i[1][n].quantity;e.vhmongo_firebase.database().updateDoc("products",o._id,{quantity:s,quantity_branch:a}).then((function(){t(null)}))}else t(null)}))},a=0;a<i[1].length;a++)o(a);e.vhQuery.asyncPromiseAll(t).then((function(){n(!0)}))})):2===i[0].bill_type||14===i[0].bill_type?e.vhQuery.asyncPromiseAll(a).then((function(){for(var t=new Array,o=function(n){t[n]=new Promise((function(t){if(3===i[1][n].ptype){var o=e.getlocalProduct(i[1][n].id_product),a={};null!=o.quantity_branch?(a=o.quantity_branch,null!=o.quantity_branch[i[0].id_branch]?a[i[0].id_branch]=a[i[0].id_branch]-i[1][n].quantity:a[i[0].id_branch]=-i[1][n].quantity):a[i[0].id_branch]=-i[1][n].quantity;var s=o.quantity-i[1][n].quantity;e.vhmongo_firebase.database().updateDoc("products",o._id,{quantity:s,quantity_branch:a}).then((function(){t(null)}))}else t(null)}))},a=0;a<i[1].length;a++)o(a);e.vhQuery.asyncPromiseAll(t).then((function(){n(null)}))})):9===i[0].bill_type?e.vhQuery.asyncPromiseAll(a).then((function(){for(var t=new Array,o=function(n){t[n]=new Promise((function(t){var o;if(3===i[1][n].ptype){var a=e.getlocalProduct(i[1][n].id_product),s={};null!=a.quantity_branch?(s=a.quantity_branch,null!=a.quantity_branch[i[0].id_branch]?s[i[0].id_branch]=s[i[0].id_branch]-i[1][n].quantity:s[i[0].id_branch]=-i[1][n].quantity):s[i[0].id_branch]=-i[1][n].quantity;var r=a.quantity-i[1][n].quantity,l={};null!=a[i[0].id_branch]&&null!=a[i[0].id_branch].inventory&&(l[i[0].id_branch]=a[i[0].id_branch],null===(o=l[i[0].id_branch])||void 0===o||delete o.inventory),e.vhmongo_firebase.database().updateDoc("products",a._id,Object.assign({quantity:r,quantity_branch:s},l)).then((function(){t(null)}))}else t(null)}))},a=0;a<i[1].length;a++)o(a);e.vhQuery.asyncPromiseAll(t).then((function(){n(null)}))})):e.vhQuery.asyncPromiseAll(a).then((function(){n(!0)}))}),(function(t){console.log("error",t),o(t)}))}))},t.prototype.getBill_details=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("vhbill_details",{id_bill:{$eq:t}},{},{},0).then((function(t){var e=new Array;if(t.length>0)for(var o=0;o<t.length;o++){var i=Object.assign({},t[o]);null==i||delete i.bill_code,null==i||delete i.date,null==i||delete i.tax,null==i||delete i.bill_type,null==i||delete i.id_cashier,null==i||delete i.id_employee,null==i||delete i.id_supplier,null==i||delete i.id_customer,null==i||delete i.id_inventorytime,null==i||delete i.id_branch,e.push(i)}n(e)}),(function(t){o(t)}))}))},t.prototype.getBill_detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("vhbill_details",t).then((function(t){if(t){var e=Object.assign({},t);null==e||delete e.bill_code,null==e||delete e.date,null==e||delete e.id_area,null==e||delete e.id_table,null==e||delete e.tax,null==e||delete e.bill_type,null==e||delete e.id_cashier,null==e||delete e.id_employee,null==e||delete e.id_supplier,null==e||delete e.id_customer,null==e||delete e.id_inventorytime,null==e||delete e.id_branch,n(e)}else n(t)}),(function(t){o(t)}))}))},t.prototype.createBill_Detail=function(t){var e=this;return new Promise((function(n,o){t.id_bill?e.vhmongo_firebase.database().getDoc("bills",t.id_bill).then((function(i){var a=t;i.bill_code&&(a.bill_code=i.bill_code),i.id_table&&(a.id_table=i.id_table),i.id_branch&&(a.id_branch=i.id_branch),"number"==typeof i.bill_type&&(a.bill_type=i.bill_type),e.vhmongo_firebase.database().addDoc("vhbill_details",a).then((function(t){n(t)}),(function(t){o(t)}))}),(function(t){console.log("error",t)})):console.log("error","không tồn tại id_bill trong data")}))},t.prototype.updateBill_Detail=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("vhbill_details",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteBill_Detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("vhbill_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getBill=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("bills",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getBills=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.database().getDocsByFields("bills",t,{},n,o).then((function(t){e(t)})).catch((function(t){a(t)}))}))},t.prototype.createBill=function(t){var e=this;return new Promise((function(n,o){e.sync_code=Math.random().toString(36).substr(2,10).toUpperCase(),t.sync_code=e.sync_code,e.vhmongo_firebase.database().addDoc("bills",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateBill=function(t,e){var n=this;return new Promise((function(o,i){n.sync_code=Math.random().toString(36).substr(2,10).toUpperCase(),e.sync_code=n.sync_code,"3334"===(null==e?void 0:e.bill_type)?n.vhmongo_firebase.database().getDoc("bills",t).then((function(a){32===a.bill_type?n.vhmongo_firebase.database().getDoc("bills",t).then((function(a){var s=new Array;s[0]=n.vhmongo_firebase.database().updateDoc("bills",t,{bill_type:33,sync_code:n.sync_code});var r=Object.assign({},e);null==r||delete r.id_branch_receive,r.bill_type=34,r.bill_code=a.bill_code,r.id_branch=a.id_branch_receive,r.id_branch_send=a.id_branch,r.date=a.date,s[1]=n.vhmongo_firebase.database().addDoc("bills",r),Promise.all(s).then((function(){o(!0)})).catch((function(t){i(t)}))})):i("Lưu không thành công, vui lòng kiểm tra lại.")})):n.vhmongo_firebase.database().updateDoc("bills",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteBill=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("bills",t).then((function(i){if(i){var a=void 0;(7===i.bill_type||8===i.bill_type||11===i.bill_type||12===i.bill_type||32===i.bill_type)&&(a=e.vhmongo_firebase.database().deleteDoc("bills",t)),a.then((function(t){return n(t)}))}else o({message:t+" no exist"})}))}))},t.prototype.observableSyncOpeningBill=function(t,e){var n=this;return new c.Observable((function(o){var i=0;n.callbacksyncopeningbill=n.vhmongo_firebase.socketMongoDB().initSyncOpeningBill(t).subscribe((function(t){if(t.exists)if(t.data().sync_code!=n.sync_code)if(t.data().bill_type===e){if(i++){var a=Object.assign(Object.assign({},n.vhmongo_firebase.database().cvtDataFB2MG(t.data())),{_id:t.id});o.next({vcode:0,message:"repaired bill",data:a})}}else o.next({vcode:1,message:"changed bill_type"});else i++;else o.next({vcode:2,message:"deleted bill by unknown device"})}))}))},t.prototype.closeSyncOpeningBill=function(){this.callbacksyncopeningbill.unsubscribe(),this.vhmongo_firebase.socketMongoDB().closeSyncOpeningBill()},t.prototype.createPaymentVnpay=function(t,e,n,o){this.vhmongo_firebase.paymentVNPAY().createPaymentVnpay(t,e,n,o).then((function(t){window.location=t.data}),(function(t){console.log("error",t)}))},t.prototype.createPaymentVnpay_Mobile=function(t,e,n,o,i){var a=this;return new Promise((function(i,s){a.vhmongo_firebase.paymentVNPAY().createPaymentVnpay(t,e,n,o).then((function(t){i(t.data)}),(function(t){console.log("error",t),s(t)}))}))},t.prototype.createPayment=function(t){var e=this;return new Promise((function(n,o){t.payment_code=e.vhAlgorithm.createPaymentCode(null==t?void 0:t.date),t.id_store=e.vhmongo_firebase.auth().getDatabase(),e.vhmongo_firebase.rootdatabase().addDoc("payments",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updatePayment=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.rootdatabase().updateDoc("payments",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deletePayment=function(t){var e=this;return new Promise((function(n,o){var i={id_payment:{$eq:t}};e.vhmongo_firebase.rootdatabase().getDocsByFields("payment_details",i,{},{},0).then((function(t){if(t.length>0)for(var n=0;n<t.length;n++)e.vhmongo_firebase.rootdatabase().deleteDoc("payment_details",t[n]._id)}),(function(t){console.log(t,t)})),e.vhmongo_firebase.rootdatabase().deleteDoc("payments",t).then((function(t){n(t)}),(function(t){console.log(t,t)}))}))},t.prototype.getPayments=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.rootdatabase().getDocsByFields("payments",t,{},n,o).then((function(t){e(t)}),(function(t){console.log(t,t)}))}))},t.prototype.getPayment=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.rootdatabase().getDoc("payments",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.createPayment_Detail=function(t){var e=this;return new Promise((function(n,o){null!=t.id_payment&&null!=t.id_payment?e.vhmongo_firebase.rootdatabase().getDoc("payments",t.id_payment).then((function(i){var a=t;a.activating=!1,a.invalid=!1,a.date=i.date,i.id_store&&(a.id_store=i.id_store),"number"==typeof i.payment_type&&(a.payment_type=i.payment_type),e.vhmongo_firebase.rootdatabase().addDoc("payment_details",a).then((function(t){n(t)}),(function(t){o(t)}))}),(function(t){console.log("error",t)})):console.log("error","không tồn tại id_bill trong data")}))},t.prototype.updatePayment_Detail=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.rootdatabase().updateDoc("payment_details",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.getPayment_details=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.rootdatabase().getDocsByFields("payment_details",t,{},n,o).then((function(t){e(t)}),(function(t){console.log(t,t)}))}))},t.prototype.getPayment_detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.rootdatabase().getDoc("payment_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.deletePayment_Detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.rootdatabase().deleteDoc("payment_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPackage=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.rootdatabase().getDoc("packages",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.publishObservableEventPromotions=function(){this.subjectpromotions.next(this.promotions)},t.prototype.observableLocalPromotions=function(){return this.subjectpromotions},t.prototype.getObservableLocalPromotions=function(){var t=this;return new c.Observable((function(e){t.observableLocalPromotions().subscribe((function(t){e.next(t)})),t.publishObservableEventPromotions()}))},t.prototype.getlocalPromotion=function(t){for(var e=0;e<this.promotions.length;e++)if(this.promotions[e]._id===t)return this.suppliers[e];return null},t.prototype.getlocalPromotions=function(){return this.promotions},t.prototype.refreshLocalPromotions=function(){return new Promise((function(t,e){t(null)}))},t.prototype.addPromotion=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("promotions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updatePromotion=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("promotions",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deletePromotion=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("promotions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPromotion=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("promotions",t).then((function(t){n(t)}))}))},t.prototype.getPromotions=function(){var t=this;return new Promise((function(e){t.vhmongo_firebase.database().getDocs("promotions").then((function(n){t.promotions=n,e(n)}))}))},t.prototype.addPromotion_detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("promotion_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updatePromotion_detail=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("promotion_details",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deletePromotion_detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("promotion_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPromotion_detail=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("promotion_details",t).then((function(t){n(t)}))}))},t.prototype.getPromotion_details=function(){var t=this;return new Promise((function(e){t.vhmongo_firebase.database().getDocs("promotion_details").then((function(t){e(t)}))}))},t.prototype.addPromotion_Promotiondetail=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().addDoc("promotions",t).then((function(t){for(var a=new Array,s=0;s<e.length;s++){var r=e[s];r.id_promotion=t._id,a[s]=n.vhmongo_firebase.database().addDoc("promotion_details",r)}Promise.all(a).then((function(){o(t)})).catch((function(t){i(t)}))}),(function(t){i(t)}))}))},t.prototype.updatePromotion_Promotiondetail=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.database().getDocsByFields("promotion_details",{id_promotion:{$eq:t}},{},{},0).then((function(s){for(var r=new Array,l=0;l<s.length;l++)r[l]=o.vhmongo_firebase.database().deleteDoc("promotion_details",s[l]._id);var c=Object.assign({},e);r[s.length]=o.vhmongo_firebase.database().updateDoc("promotions",t,c);for(l=0;l<n.length;l++){var u=n[l];u.id_promotion=t,r[l+s.length+1]=o.vhmongo_firebase.database().addDoc("promotion_details",u)}Promise.all(r).then((function(){i(!0)})).catch((function(t){a(t)}))})).catch((function(){i(!1)}))}))},t.prototype.deletePromotion_Promotiondetail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("promotion_details",{id_promotion:{$eq:t}},{},{},0).then((function(i){for(var a=new Array,s=0;s<i.length;s++)a[s]=e.vhmongo_firebase.database().deleteDoc("promotion_details",i[s]._id);a[i.length]=e.vhmongo_firebase.database().deleteDoc("promotions",t),Promise.all(a).then((function(){n(!0)})).catch((function(t){o(t)}))})).catch((function(){n(!1)}))}))},t.prototype.getPromotion_details_byId_promotion=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDocsByFields("promotion_details",{id_promotion:{$eq:t}},{},{},0).then((function(t){n(t)})).catch((function(){n(!1)}))}))},t.prototype.checkNewPromotion=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.database().getDocs("promotions").then((function(s){var r=new Array,l=new Array;if(s.length>0){for(var c=0;c<s.length;c++)new Date(t)<new Date(s[c].date_start)?new Date(e)>=new Date(s[c].date_start)&&r.push(s[c]._id):new Date(t)>=new Date(s[c].date_start)&&new Date(t)<=new Date(s[c].date_end)&&r.push(s[c]._id);r.length>0?o.vhmongo_firebase.database().getDocsByFields("promotion_details",{id_promotion:{$in:r}},{},{},0).then((function(t){if(t.length){for(var e=0;e<n.length;e++)for(var o=0;o<t.length;o++)if(n[e]===t[o].id_product){l.push(n[e]);break}i(l)}else i(l)})).catch((function(t){a(t)})):i(l)}else i(l)}),(function(t){console.log("error",t)}))}))},t.prototype.checkOldPromotion=function(t,e,n,o){var i=this;return new Promise((function(a,s){i.vhmongo_firebase.database().getDocs("promotions").then((function(s){var r=new Array,l=new Array;if(s.length>0){for(var c=0;c<s.length;c++)new Date(t)<new Date(s[c].date_start)?new Date(e)>=new Date(s[c].date_start)&&s[c]._id!=o&&r.push(s[c]._id):new Date(t)>=new Date(s[c].date_start)&&new Date(t)<=new Date(s[c].date_end)&&s[c]._id!=o&&r.push(s[c]._id);r.length>0?i.vhmongo_firebase.database().getDocsByFields("promotion_details",{id_promotion:{$in:r}},{},{},0).then((function(t){if(t.length>0){for(var e=0;e<n.length;e++)for(var o=0;o<t.length;o++)if(n[e]===t[o].id_product){l.push(n[e]);break}a(l)}else a(l)}),(function(t){console.log("error",t)})):a(l)}else a(l)}))}))},t.prototype.publishObservableEventAppSettingNameStations=function(){this.subjectappsettingstations.next()},t.prototype.observableLocalAppSettingNameStations=function(){return this.subjectappsettingstations},t.prototype.getObservableLocalAppSettingNameStations=function(){var t=this;return new c.Observable((function(e){t.observableLocalAppSettingNameStations().subscribe((function(){e.next(null)})),t.publishObservableEventAppSettingNameStations()}))},t.prototype.getLocalAppSettingNameStations=function(){for(var t=new Array,e=0;e<this.appsettingstations.length;e++)t.push(this.appsettingstations[e].appsetting_name);return t},t.prototype.getLocalAppSettingNameStation=function(t){for(var e={},n=0;n<this.appsettingstations.length;n++)if(this.appsettingstations[n].appsetting_name===t){delete(e=Object.assign({},this.appsettingstations[n]))._id,delete e.appsetting_name;break}return e},t.prototype.getLocalAppSettingStation=function(t){for(var e=0;e<this.appsettingstations.length;e++)if(this.appsettingstations[e]._id===t)return this.appsettingstations[e];return null},t.prototype.refreshLocalAppSettingNameStations=function(){return new Promise((function(t,e){t(null)}))},t.prototype.getAppSettingStations=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocsByFields("appsettingstations",{uuid:{$eq:t.hwinfo.uuid}},{},{},0).then((function(n){n.length>0&&(t.appsettingstations=n),e(null)}),(function(t){n(t)}))}))},t.prototype.updateAppSettingNameStation=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().getDocsByFields("appsettingstations",{appsetting_name:{$eq:t},uuid:{$eq:n.hwinfo.uuid}},{},{},0).then((function(a){if(a.length>0)n.vhmongo_firebase.database().updateDoc("appsettingstations",a[0]._id,e).then((function(t){o(t)}),(function(t){i(t)}));else{var s=Object.assign({},e);s.appsetting_name=t,s.uuid=n.hwinfo.uuid,n.vhmongo_firebase.database().addDoc("appsettingstations",s).then((function(){o(!0)}),(function(t){i(t)}))}}))}))},t.prototype.deleteAppSettingNameStation=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("appsettingstations",{appsetting_name:{$eq:t},uuid:{$eq:e.hwinfo.uuid}},{},{},0).then((function(t){t.length>0?e.vhmongo_firebase.database().deleteDoc("appsettingstations",t[0]._id).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}))}))},t.prototype.publishObservableEventAppSettingNameBranchs=function(){this.subjectappsettingbranchs.next()},t.prototype.observableLocalAppSettingNameBranchs=function(){return this.subjectappsettingbranchs},t.prototype.getObservableLocalAppSettingNameBranchs=function(){var t=this;return new c.Observable((function(e){t.observableLocalAppSettingNameBranchs().subscribe((function(){e.next(null)})),t.publishObservableEventAppSettingNameBranchs()}))},t.prototype.getLocalAppSettingNameBranchs=function(){for(var t=new Array,e=0;e<this.appsettingbranchs.length;e++)t.push(this.appsettingbranchs[e].appsetting_name);return t},t.prototype.getLocalAppSettingNameBranch=function(t){for(var e={},n=0;n<this.appsettingbranchs.length;n++)if(this.appsettingbranchs[n].appsetting_name===t){delete(e=Object.assign({},this.appsettingbranchs[n]))._id,delete e.appsetting_name;break}return e},t.prototype.getLocalAppSettingBranch=function(t){for(var e=0;e<this.appsettingbranchs.length;e++)if(this.appsettingbranchs[e]._id===t)return this.appsettingbranchs[e];return null},t.prototype.updateAppSettingNameBranch=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().getDocsByFields("appsettingbranchs",{appsetting_name:{$eq:t},id_branch:{$eq:n.getDefaultBranch()._id}},{},{},1).then((function(a){if(a.length>0)n.vhmongo_firebase.database().updateDoc("appsettingbranchs",a[0]._id,e).then((function(t){o(t)}),(function(t){i(t)}));else{var s=Object.assign({},e);s.appsetting_name=t,s.id_branch=n.getDefaultBranch()._id,n.vhmongo_firebase.database().addDoc("appsettingbranchs",s).then((function(){o(!0)}),(function(t){i(t)}))}}))}))},t.prototype.deleteAppSettingNameBranch=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("appsettingbranchs",{appsetting_name:{$eq:t},id_branch:{$eq:e.getDefaultBranch()._id}},{},{},0).then((function(t){t.length>0?e.vhmongo_firebase.database().deleteDoc("appsettingbranchs",t[0]._id).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}))}))},t.prototype.getDiscount_bill_byCustomer=function(t,e){for(var n=this.getlocalCustomer(e),o=this.getlocalDiscount_bills(),i=null,a=0;a<o.length;a++)if(o[a]._id===n.id_discount_bill){i={discount:0},1===o[a].method?(0!=o[a].level5.sales||0!=o[a].level5.discount)&&t>=o[a].level5.sales?1===o[a].type?(i.discount=i.discount+(o[a].level2.sales-o[a].level1.sales)*o[a].level1.discount/100,i.discount=i.discount+(o[a].level3.sales-o[a].level2.sales)*o[a].level2.discount/100,i.discount=i.discount+(o[a].level4.sales-o[a].level3.sales)*o[a].level3.discount/100,i.discount=i.discount+(o[a].level5.sales-o[a].level4.sales)*o[a].level4.discount/100,i.discount=i.discount+(t-o[a].level5.sales)*o[a].level5.discount/100):2===o[a].type&&(i.discount=o[a].level1.discount,i.discount=i.discount+o[a].level2.discount,i.discount=i.discount+o[a].level3.discount,i.discount=i.discount+o[a].level4.discount,i.discount=i.discount+o[a].level5.discount):(0!=o[a].level4.sales||0!=o[a].level4.discount)&&t>=o[a].level4.sales?1===o[a].type?(i.discount=i.discount+(o[a].level2.sales-o[a].level1.sales)*o[a].level1.discount/100,i.discount=i.discount+(o[a].level3.sales-o[a].level2.sales)*o[a].level2.discount/100,i.discount=i.discount+(o[a].level4.sales-o[a].level3.sales)*o[a].level3.discount/100,i.discount=i.discount+(t-o[a].level4.sales)*o[a].level4.discount/100):2===o[a].type&&(i.discount=o[a].level1.discount,i.discount=i.discount+o[a].level2.discount,i.discount=i.discount+o[a].level3.discount,i.discount=i.discount+o[a].level4.discount):(0!=o[a].level3.sales||0!=o[a].level3.discount)&&t>=o[a].level3.sales?1===o[a].type?(i.discount=i.discount+(o[a].level2.sales-o[a].level1.sales)*o[a].level1.discount/100,i.discount=i.discount+(o[a].level3.sales-o[a].level2.sales)*o[a].level2.discount/100,i.discount=i.discount+(t-o[a].level3.sales)*o[a].level3.discount/100):2===o[a].type&&(i.discount=o[a].level1.discount,i.discount=i.discount+o[a].level2.discount,i.discount=i.discount+o[a].level3.discount):(0!=o[a].level2.sales||0!=o[a].level2.discount)&&t>=o[a].level2.sales?1===o[a].type?(i.discount=i.discount+(o[a].level2.sales-o[a].level1.sales)*o[a].level1.discount/100,i.discount=i.discount+(t-o[a].level2.sales)*o[a].level2.discount/100):2===o[a].type&&(i.discount=o[a].level1.discount,i.discount=i.discount+o[a].level2.discount):(0!=o[a].level1.sales||0!=o[a].level1.discount)&&t>=o[a].level1.sales&&(1===o[a].type?i.discount=i.discount+(t-o[a].level1.sales)*o[a].level1.discount/100:2===o[a].type&&(i.discount=o[a].level1.discount)):2===o[a].method&&((0!=o[a].level5.sales||0!=o[a].level5.discount)&&t>=o[a].level5.sales?1===o[a].type?i.discount=t*o[a].level5.discount/100:2===o[a].type&&(i.discount=o[a].level5.discount):(0!=o[a].level4.sales||0!=o[a].level4.discount)&&t>=o[a].level4.sales?1===o[a].type?i.discount=t*o[a].level4.discount/100:2===o[a].type&&(i.discount=o[a].level4.discount):(0!=o[a].level3.sales||0!=o[a].level3.discount)&&t>=o[a].level3.sales?1===o[a].type?i.discount=t*o[a].level3.discount/100:2===o[a].type&&(i.discount=o[a].level3.discount):(0!=o[a].level2.sales||0!=o[a].level2.discount)&&t>=o[a].level2.sales?1===o[a].type?i.discount=t*o[a].level2.discount/100:2===o[a].type&&(i.discount=o[a].level2.discount):(0!=o[a].level1.sales||0!=o[a].level1.discount)&&t>=o[a].level1.sales&&(1===o[a].type?i.discount=t*o[a].level1.discount/100:2===o[a].type&&(i.discount=o[a].level1.discount)));break}return i},t.prototype.getDiscount_bill_byCustomer_new=function(t,e){for(var n=this.getlocalCustomer(e),o=this.getlocalDiscount_bills(),i=this.getlocalCustomerClasss(),a=null,s=0;s<i.length;s++)if(i[s]._id===n.id_customer_class&&null!=i[s].id_discount_bill&&null!=i[s].id_discount_bill)for(var r=0;r<o.length;r++)if(o[r]._id===i[s].id_discount_bill){a={discount:0},1===o[r].method?(0!=o[r].level5.sales||0!=o[r].level5.discount)&&t>=o[r].level5.sales?1===o[r].type?(a.discount=a.discount+(o[r].level2.sales-o[r].level1.sales)*o[r].level1.discount/100,a.discount=a.discount+(o[r].level3.sales-o[r].level2.sales)*o[r].level2.discount/100,a.discount=a.discount+(o[r].level4.sales-o[r].level3.sales)*o[r].level3.discount/100,a.discount=a.discount+(o[r].level5.sales-o[r].level4.sales)*o[r].level4.discount/100,a.discount=a.discount+(t-o[r].level5.sales)*o[r].level5.discount/100):2===o[r].type&&(a.discount=o[r].level1.discount,a.discount=a.discount+o[r].level2.discount,a.discount=a.discount+o[r].level3.discount,a.discount=a.discount+o[r].level4.discount,a.discount=a.discount+o[r].level5.discount):(0!=o[r].level4.sales||0!=o[r].level4.discount)&&t>=o[r].level4.sales?1===o[r].type?(a.discount=a.discount+(o[r].level2.sales-o[r].level1.sales)*o[r].level1.discount/100,a.discount=a.discount+(o[r].level3.sales-o[r].level2.sales)*o[r].level2.discount/100,a.discount=a.discount+(o[r].level4.sales-o[r].level3.sales)*o[r].level3.discount/100,a.discount=a.discount+(t-o[r].level4.sales)*o[r].level4.discount/100):2===o[r].type&&(a.discount=o[r].level1.discount,a.discount=a.discount+o[r].level2.discount,a.discount=a.discount+o[r].level3.discount,a.discount=a.discount+o[r].level4.discount):(0!=o[r].level3.sales||0!=o[r].level3.discount)&&t>=o[r].level3.sales?1===o[r].type?(a.discount=a.discount+(o[r].level2.sales-o[r].level1.sales)*o[r].level1.discount/100,a.discount=a.discount+(o[r].level3.sales-o[r].level2.sales)*o[r].level2.discount/100,a.discount=a.discount+(t-o[r].level3.sales)*o[r].level3.discount/100):2===o[r].type&&(a.discount=o[r].level1.discount,a.discount=a.discount+o[r].level2.discount,a.discount=a.discount+o[r].level3.discount):(0!=o[r].level2.sales||0!=o[r].level2.discount)&&t>=o[r].level2.sales?1===o[r].type?(a.discount=a.discount+(o[r].level2.sales-o[r].level1.sales)*o[r].level1.discount/100,a.discount=a.discount+(t-o[r].level2.sales)*o[r].level2.discount/100):2===o[r].type&&(a.discount=o[r].level1.discount,a.discount=a.discount+o[r].level2.discount):(0!=o[r].level1.sales||0!=o[r].level1.discount)&&t>=o[r].level1.sales&&(1===o[r].type?a.discount=a.discount+(t-o[r].level1.sales)*o[r].level1.discount/100:2===o[r].type&&(a.discount=o[r].level1.discount)):2===o[r].method&&((0!=o[r].level5.sales||0!=o[r].level5.discount)&&t>=o[r].level5.sales?1===o[r].type?a.discount=t*o[r].level5.discount/100:2===o[r].type&&(a.discount=o[r].level5.discount):(0!=o[r].level4.sales||0!=o[r].level4.discount)&&t>=o[r].level4.sales?1===o[r].type?a.discount=t*o[r].level4.discount/100:2===o[r].type&&(a.discount=o[r].level4.discount):(0!=o[r].level3.sales||0!=o[r].level3.discount)&&t>=o[r].level3.sales?1===o[r].type?a.discount=t*o[r].level3.discount/100:2===o[r].type&&(a.discount=o[r].level3.discount):(0!=o[r].level2.sales||0!=o[r].level2.discount)&&t>=o[r].level2.sales?1===o[r].type?a.discount=t*o[r].level2.discount/100:2===o[r].type&&(a.discount=o[r].level2.discount):(0!=o[r].level1.sales||0!=o[r].level1.discount)&&t>=o[r].level1.sales&&(1===o[r].type?a.discount=t*o[r].level1.discount/100:2===o[r].type&&(a.discount=o[r].level1.discount)));break}return a},t.prototype.getReportDiscount_sales_Customers=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Array;if("all"===n)r=i.getlocalCustomers();else{var l=i.getlocalCustomer(n);r.push(l)}var c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,discount_btax:0,discount_atax:0};if(r.length>0){var u=void 0;u="all"===n?"all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$gte:t,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1]},id_branch:{$eq:o}};var d=i.vhmongo_firebase.database().getDocsByFields("discount_saless",{},{},{},0),_=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0);Promise.all([d,_]).then((function(t){var e,n=t[0],o=t[1];if(o.length>0)for(var i=0;i<r.length;i++){for(var s=!1,l={id_customer:r[i]._id,name:r[i].name,img:null===(e=r[i])||void 0===e?void 0:e.img,sales_btax:0,sales_atax:0,quantity:0,discount_btax:0,discount_atax:0,discount_name:""},u=0;u<o.length;u++)if(r[i]._id===o[u].id_customer)if(s=!0,5===o[u].ptype){if(null!=o[u].combos)for(var d=0;d<o[u].combos.length;d++)l.quantity=l.quantity+o[u].combos[d].quantity*o[u].quantity,l.sales_btax=l.sales_btax+o[u].combos[d].price*o[u].combos[d].quantity*o[u].quantity,l.sales_atax=l.sales_atax+o[u].combos[d].price*o[u].combos[d].quantity*o[u].quantity*(1+o[u].tax/100)}else l.quantity=l.quantity+o[u].quantity,l.sales_btax=l.sales_btax+o[u].price*o[u].quantity,l.sales_atax=l.sales_atax+o[u].price*o[u].quantity*(1+o[u].tax/100);if(s&&null!=r[i].id_discount_sales&&null!=r[i].id_discount_sales)for(var _=0;_<n.length;_++)if(n[_]._id===r[i].id_discount_sales){l.discount_name=n[_].name,1===n[_].method?(0!=n[_].level5.sales||0!=n[_].level5.discount)&&l.sales_btax>=n[_].level5.sales?1===n[_].type?(l.discount_btax=l.discount_btax+(n[_].level2.sales-n[_].level1.sales)*n[_].level1.discount/100,l.discount_btax=l.discount_btax+(n[_].level3.sales-n[_].level2.sales)*n[_].level2.discount/100,l.discount_btax=l.discount_btax+(n[_].level4.sales-n[_].level3.sales)*n[_].level3.discount/100,l.discount_btax=l.discount_btax+(n[_].level5.sales-n[_].level4.sales)*n[_].level4.discount/100,l.discount_btax=l.discount_btax+(l.sales_btax-n[_].level5.sales)*n[_].level5.discount/100):2===n[_].type&&(l.discount_btax=n[_].level1.discount,l.discount_btax=l.discount_btax+n[_].level2.discount,l.discount_btax=l.discount_btax+n[_].level3.discount,l.discount_btax=l.discount_btax+n[_].level4.discount,l.discount_btax=l.discount_btax+n[_].level5.discount):(0!=n[_].level4.sales||0!=n[_].level4.discount)&&l.sales_btax>=n[_].level4.sales?1===n[_].type?(l.discount_btax=l.discount_btax+(n[_].level2.sales-n[_].level1.sales)*n[_].level1.discount/100,l.discount_btax=l.discount_btax+(n[_].level3.sales-n[_].level2.sales)*n[_].level2.discount/100,l.discount_btax=l.discount_btax+(n[_].level4.sales-n[_].level3.sales)*n[_].level3.discount/100,l.discount_btax=l.discount_btax+(l.sales_btax-n[_].level4.sales)*n[_].level4.discount/100):2===n[_].type&&(l.discount_btax=n[_].level1.discount,l.discount_btax=l.discount_btax+n[_].level2.discount,l.discount_btax=l.discount_btax+n[_].level3.discount,l.discount_btax=l.discount_btax+n[_].level4.discount):(0!=n[_].level3.sales||0!=n[_].level3.discount)&&l.sales_btax>=n[_].level3.sales?1===n[_].type?(l.discount_btax=l.discount_btax+(n[_].level2.sales-n[_].level1.sales)*n[_].level1.discount/100,l.discount_btax=l.discount_btax+(n[_].level3.sales-n[_].level2.sales)*n[_].level2.discount/100,l.discount_btax=l.discount_btax+(l.sales_btax-n[_].level3.sales)*n[_].level3.discount/100):2===n[_].type&&(l.discount_btax=n[_].level1.discount,l.discount_btax=l.discount_btax+n[_].level2.discount,l.discount_btax=l.discount_btax+n[_].level3.discount):(0!=n[_].level2.sales||0!=n[_].level2.discount)&&l.sales_btax>=n[_].level2.sales?1===n[_].type?(l.discount_btax=l.discount_btax+(n[_].level2.sales-n[_].level1.sales)*n[_].level1.discount/100,l.discount_btax=l.discount_btax+(l.sales_btax-n[_].level2.sales)*n[_].level2.discount/100):2===n[_].type&&(l.discount_btax=n[_].level1.discount,l.discount_btax=l.discount_btax+n[_].level2.discount):(0!=n[_].level1.sales||0!=n[_].level1.discount)&&l.sales_btax>=n[_].level1.sales&&(1===n[_].type?l.discount_btax=l.discount_btax+(l.sales_btax-n[_].level1.sales)*n[_].level1.discount/100:2===n[_].type&&(l.discount_btax=n[_].level1.discount)):2===n[_].method&&((0!=n[_].level5.sales||0!=n[_].level5.discount)&&l.sales_btax>=n[_].level5.sales?1===n[_].type?l.discount_btax=l.sales_btax*n[_].level5.discount/100:2===n[_].type&&(l.discount_btax=n[_].level5.discount):(0!=n[_].level4.sales||0!=n[_].level4.discount)&&l.sales_btax>=n[_].level4.sales?1===n[_].type?l.discount_btax=l.sales_btax*n[_].level4.discount/100:2===n[_].type&&(l.discount_btax=n[_].level4.discount):(0!=n[_].level3.sales||0!=n[_].level3.discount)&&l.sales_btax>=n[_].level3.sales?1===n[_].type?l.discount_btax=l.sales_btax*n[_].level3.discount/100:2===n[_].type&&(l.discount_btax=n[_].level3.discount):(0!=n[_].level2.sales||0!=n[_].level2.discount)&&l.sales_btax>=n[_].level2.sales?1===n[_].type?l.discount_btax=l.sales_btax*n[_].level2.discount/100:2===n[_].type&&(l.discount_btax=n[_].level2.discount):(0!=n[_].level1.sales||0!=n[_].level1.discount)&&l.sales_btax>=n[_].level1.sales&&(1===n[_].type?l.discount_btax=l.sales_btax*n[_].level1.discount/100:2===n[_].type&&(l.discount_btax=n[_].level1.discount))),1===n[_].method?(0!=n[_].level5.sales||0!=n[_].level5.discount)&&l.sales_atax>=n[_].level5.sales?1===n[_].type?(l.discount_atax=l.discount_atax+(n[_].level2.sales-n[_].level1.sales)*n[_].level1.discount/100,l.discount_atax=l.discount_atax+(n[_].level3.sales-n[_].level2.sales)*n[_].level2.discount/100,l.discount_atax=l.discount_atax+(n[_].level4.sales-n[_].level3.sales)*n[_].level3.discount/100,l.discount_atax=l.discount_atax+(n[_].level5.sales-n[_].level4.sales)*n[_].level4.discount/100,l.discount_atax=l.discount_atax+(l.sales_atax-n[_].level5.sales)*n[_].level5.discount/100):2===n[_].type&&(l.discount_atax=n[_].level1.discount,l.discount_atax=l.discount_atax+n[_].level2.discount,l.discount_atax=l.discount_atax+n[_].level3.discount,l.discount_atax=l.discount_atax+n[_].level4.discount,l.discount_atax=l.discount_atax+n[_].level5.discount):(0!=n[_].level4.sales||0!=n[_].level4.discount)&&l.sales_atax>=n[_].level4.sales?1===n[_].type?(l.discount_atax=l.discount_atax+(n[_].level2.sales-n[_].level1.sales)*n[_].level1.discount/100,l.discount_atax=l.discount_atax+(n[_].level3.sales-n[_].level2.sales)*n[_].level2.discount/100,l.discount_atax=l.discount_atax+(n[_].level4.sales-n[_].level3.sales)*n[_].level3.discount/100,l.discount_atax=l.discount_atax+(l.sales_atax-n[_].level4.sales)*n[_].level4.discount/100):2===n[_].type&&(l.discount_atax=n[_].level1.discount,l.discount_atax=l.discount_atax+n[_].level2.discount,l.discount_atax=l.discount_atax+n[_].level3.discount,l.discount_atax=l.discount_atax+n[_].level4.discount):(0!=n[_].level3.sales||0!=n[_].level3.discount)&&l.sales_atax>=n[_].level3.sales?1===n[_].type?(l.discount_atax=l.discount_atax+(n[_].level2.sales-n[_].level1.sales)*n[_].level1.discount/100,l.discount_atax=l.discount_atax+(n[_].level3.sales-n[_].level2.sales)*n[_].level2.discount/100,l.discount_atax=l.discount_atax+(l.sales_atax-n[_].level3.sales)*n[_].level3.discount/100):2===n[_].type&&(l.discount_atax=n[_].level1.discount,l.discount_atax=l.discount_atax+n[_].level2.discount,l.discount_atax=l.discount_atax+n[_].level3.discount):(0!=n[_].level2.sales||0!=n[_].level2.discount)&&l.sales_atax>=n[_].level2.sales?1===n[_].type?(l.discount_atax=l.discount_atax+(n[_].level2.sales-n[_].level1.sales)*n[_].level1.discount/100,l.discount_atax=l.discount_atax+(l.sales_atax-n[_].level2.sales)*n[_].level2.discount/100):2===n[_].type&&(l.discount_atax=n[_].level1.discount,l.discount_atax=l.discount_atax+n[_].level2.discount):(0!=n[_].level1.sales||0!=n[_].level1.discount)&&l.sales_atax>=n[_].level1.sales&&(1===n[_].type?l.discount_atax=l.discount_atax+(l.sales_atax-n[_].level1.sales)*n[_].level1.discount/100:2===n[_].type&&(l.discount_atax=n[_].level1.discount)):2===n[_].method&&((0!=n[_].level5.sales||0!=n[_].level5.discount)&&l.sales_atax>=n[_].level5.sales?1===n[_].type?l.discount_atax=l.sales_atax*n[_].level5.discount/100:2===n[_].type&&(l.discount_atax=n[_].level5.discount):(0!=n[_].level4.sales||0!=n[_].level4.discount)&&l.sales_atax>=n[_].level4.sales?1===n[_].type?l.discount_atax=l.sales_atax*n[_].level4.discount/100:2===n[_].type&&(l.discount_atax=n[_].level4.discount):(0!=n[_].level3.sales||0!=n[_].level3.discount)&&l.sales_atax>=n[_].level3.sales?1===n[_].type?l.discount_atax=l.sales_atax*n[_].level3.discount/100:2===n[_].type&&(l.discount_atax=n[_].level3.discount):(0!=n[_].level2.sales||0!=n[_].level2.discount)&&l.sales_atax>=n[_].level2.sales?1===n[_].type?l.discount_atax=l.sales_atax*n[_].level2.discount/100:2===n[_].type&&(l.discount_atax=n[_].level2.discount):(0!=n[_].level1.sales||0!=n[_].level1.discount)&&l.sales_atax>=n[_].level1.sales&&(1===n[_].type?l.discount_atax=l.sales_atax*n[_].level1.discount/100:2===n[_].type&&(l.discount_atax=n[_].level1.discount))),c.sales_btax=c.sales_btax+l.sales_btax,c.sales_atax=c.sales_atax+l.sales_atax,c.discount_btax=c.discount_btax+l.discount_btax,c.discount_atax=c.discount_atax+l.discount_atax,l.index=c.size+1,c.docs.push(l),c.size++,c.empty=!1;break}}console.log("getReportDiscount_Customers",c),a(c)}))}else a(c)}))},t.prototype.getReportDiscount_sales_Customers_new=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Array;if("all"===n)r=i.getlocalCustomers();else{var l=i.getlocalCustomer(n);r.push(l)}var c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,discount_btax:0,discount_atax:0};if(r.length>0){var u=void 0;u="all"===n?"all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$gte:t,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1]},id_branch:{$eq:o}};var d=i.vhmongo_firebase.database().getDocsByFields("discount_saless",{},{},{},0),_=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0),p=i.vhmongo_firebase.database().getDocsByFields("customer_classs",{},{},{},0);Promise.all([d,_,p]).then((function(t){var e,n=t[0],o=t[1],i=t[2];if(o.length>0)for(var s=0;s<r.length;s++){for(var l=!1,u={id_customer:r[s]._id,name:r[s].name,img:null===(e=r[s])||void 0===e?void 0:e.img,sales_btax:0,sales_atax:0,quantity:0,discount_btax:0,discount_atax:0,discount_name:""},d=0;d<o.length;d++)if(r[s]._id===o[d].id_customer)if(l=!0,5===o[d].ptype){if(null!=o[d].combos)for(var _=0;_<o[d].combos.length;_++)u.quantity=u.quantity+o[d].combos[_].quantity*o[d].quantity,u.sales_btax=u.sales_btax+o[d].combos[_].price*o[d].combos[_].quantity*o[d].quantity,u.sales_atax=u.sales_atax+o[d].combos[_].price*o[d].combos[_].quantity*o[d].quantity*(1+o[d].tax/100)}else u.quantity=u.quantity+o[d].quantity,u.sales_btax=u.sales_btax+o[d].price*o[d].quantity,u.sales_atax=u.sales_atax+o[d].price*o[d].quantity*(1+o[d].tax/100);if(l&&null!=r[s].id_discount_sales&&null!=r[s].id_discount_sales)for(d=0;d<i.length;d++)if(i[d]._id===r[s].id_customer_class&&null!=i[d].id_discount_sales&&null!=i[d].id_discount_sales)for(var p=0;p<n.length;p++)if(n[p]._id===i[d].id_discount_sales){u.discount_name=n[p].name,1===n[p].method?(0!=n[p].level5.sales||0!=n[p].level5.discount)&&u.sales_btax>=n[p].level5.sales?1===n[p].type?(u.discount_btax=u.discount_btax+(n[p].level2.sales-n[p].level1.sales)*n[p].level1.discount/100,u.discount_btax=u.discount_btax+(n[p].level3.sales-n[p].level2.sales)*n[p].level2.discount/100,u.discount_btax=u.discount_btax+(n[p].level4.sales-n[p].level3.sales)*n[p].level3.discount/100,u.discount_btax=u.discount_btax+(n[p].level5.sales-n[p].level4.sales)*n[p].level4.discount/100,u.discount_btax=u.discount_btax+(u.sales_btax-n[p].level5.sales)*n[p].level5.discount/100):2===n[p].type&&(u.discount_btax=n[p].level1.discount,u.discount_btax=u.discount_btax+n[p].level2.discount,u.discount_btax=u.discount_btax+n[p].level3.discount,u.discount_btax=u.discount_btax+n[p].level4.discount,u.discount_btax=u.discount_btax+n[p].level5.discount):(0!=n[p].level4.sales||0!=n[p].level4.discount)&&u.sales_btax>=n[p].level4.sales?1===n[p].type?(u.discount_btax=u.discount_btax+(n[p].level2.sales-n[p].level1.sales)*n[p].level1.discount/100,u.discount_btax=u.discount_btax+(n[p].level3.sales-n[p].level2.sales)*n[p].level2.discount/100,u.discount_btax=u.discount_btax+(n[p].level4.sales-n[p].level3.sales)*n[p].level3.discount/100,u.discount_btax=u.discount_btax+(u.sales_btax-n[p].level4.sales)*n[p].level4.discount/100):2===n[p].type&&(u.discount_btax=n[p].level1.discount,u.discount_btax=u.discount_btax+n[p].level2.discount,u.discount_btax=u.discount_btax+n[p].level3.discount,u.discount_btax=u.discount_btax+n[p].level4.discount):(0!=n[p].level3.sales||0!=n[p].level3.discount)&&u.sales_btax>=n[p].level3.sales?1===n[p].type?(u.discount_btax=u.discount_btax+(n[p].level2.sales-n[p].level1.sales)*n[p].level1.discount/100,u.discount_btax=u.discount_btax+(n[p].level3.sales-n[p].level2.sales)*n[p].level2.discount/100,u.discount_btax=u.discount_btax+(u.sales_btax-n[p].level3.sales)*n[p].level3.discount/100):2===n[p].type&&(u.discount_btax=n[p].level1.discount,u.discount_btax=u.discount_btax+n[p].level2.discount,u.discount_btax=u.discount_btax+n[p].level3.discount):(0!=n[p].level2.sales||0!=n[p].level2.discount)&&u.sales_btax>=n[p].level2.sales?1===n[p].type?(u.discount_btax=u.discount_btax+(n[p].level2.sales-n[p].level1.sales)*n[p].level1.discount/100,u.discount_btax=u.discount_btax+(u.sales_btax-n[p].level2.sales)*n[p].level2.discount/100):2===n[p].type&&(u.discount_btax=n[p].level1.discount,u.discount_btax=u.discount_btax+n[p].level2.discount):(0!=n[p].level1.sales||0!=n[p].level1.discount)&&u.sales_btax>=n[p].level1.sales&&(1===n[p].type?u.discount_btax=u.discount_btax+(u.sales_btax-n[p].level1.sales)*n[p].level1.discount/100:2===n[p].type&&(u.discount_btax=n[p].level1.discount)):2===n[p].method&&((0!=n[p].level5.sales||0!=n[p].level5.discount)&&u.sales_btax>=n[p].level5.sales?1===n[p].type?u.discount_btax=u.sales_btax*n[p].level5.discount/100:2===n[p].type&&(u.discount_btax=n[p].level5.discount):(0!=n[p].level4.sales||0!=n[p].level4.discount)&&u.sales_btax>=n[p].level4.sales?1===n[p].type?u.discount_btax=u.sales_btax*n[p].level4.discount/100:2===n[p].type&&(u.discount_btax=n[p].level4.discount):(0!=n[p].level3.sales||0!=n[p].level3.discount)&&u.sales_btax>=n[p].level3.sales?1===n[p].type?u.discount_btax=u.sales_btax*n[p].level3.discount/100:2===n[p].type&&(u.discount_btax=n[p].level3.discount):(0!=n[p].level2.sales||0!=n[p].level2.discount)&&u.sales_btax>=n[p].level2.sales?1===n[p].type?u.discount_btax=u.sales_btax*n[p].level2.discount/100:2===n[p].type&&(u.discount_btax=n[p].level2.discount):(0!=n[p].level1.sales||0!=n[p].level1.discount)&&u.sales_btax>=n[p].level1.sales&&(1===n[p].type?u.discount_btax=u.sales_btax*n[p].level1.discount/100:2===n[p].type&&(u.discount_btax=n[p].level1.discount))),1===n[p].method?(0!=n[p].level5.sales||0!=n[p].level5.discount)&&u.sales_atax>=n[p].level5.sales?1===n[p].type?(u.discount_atax=u.discount_atax+(n[p].level2.sales-n[p].level1.sales)*n[p].level1.discount/100,u.discount_atax=u.discount_atax+(n[p].level3.sales-n[p].level2.sales)*n[p].level2.discount/100,u.discount_atax=u.discount_atax+(n[p].level4.sales-n[p].level3.sales)*n[p].level3.discount/100,u.discount_atax=u.discount_atax+(n[p].level5.sales-n[p].level4.sales)*n[p].level4.discount/100,u.discount_atax=u.discount_atax+(u.sales_atax-n[p].level5.sales)*n[p].level5.discount/100):2===n[p].type&&(u.discount_atax=n[p].level1.discount,u.discount_atax=u.discount_atax+n[p].level2.discount,u.discount_atax=u.discount_atax+n[p].level3.discount,u.discount_atax=u.discount_atax+n[p].level4.discount,u.discount_atax=u.discount_atax+n[p].level5.discount):(0!=n[p].level4.sales||0!=n[p].level4.discount)&&u.sales_atax>=n[p].level4.sales?1===n[p].type?(u.discount_atax=u.discount_atax+(n[p].level2.sales-n[p].level1.sales)*n[p].level1.discount/100,u.discount_atax=u.discount_atax+(n[p].level3.sales-n[p].level2.sales)*n[p].level2.discount/100,u.discount_atax=u.discount_atax+(n[p].level4.sales-n[p].level3.sales)*n[p].level3.discount/100,u.discount_atax=u.discount_atax+(u.sales_atax-n[p].level4.sales)*n[p].level4.discount/100):2===n[p].type&&(u.discount_atax=n[p].level1.discount,u.discount_atax=u.discount_atax+n[p].level2.discount,u.discount_atax=u.discount_atax+n[p].level3.discount,u.discount_atax=u.discount_atax+n[p].level4.discount):(0!=n[p].level3.sales||0!=n[p].level3.discount)&&u.sales_atax>=n[p].level3.sales?1===n[p].type?(u.discount_atax=u.discount_atax+(n[p].level2.sales-n[p].level1.sales)*n[p].level1.discount/100,u.discount_atax=u.discount_atax+(n[p].level3.sales-n[p].level2.sales)*n[p].level2.discount/100,u.discount_atax=u.discount_atax+(u.sales_atax-n[p].level3.sales)*n[p].level3.discount/100):2===n[p].type&&(u.discount_atax=n[p].level1.discount,u.discount_atax=u.discount_atax+n[p].level2.discount,u.discount_atax=u.discount_atax+n[p].level3.discount):(0!=n[p].level2.sales||0!=n[p].level2.discount)&&u.sales_atax>=n[p].level2.sales?1===n[p].type?(u.discount_atax=u.discount_atax+(n[p].level2.sales-n[p].level1.sales)*n[p].level1.discount/100,u.discount_atax=u.discount_atax+(u.sales_atax-n[p].level2.sales)*n[p].level2.discount/100):2===n[p].type&&(u.discount_atax=n[p].level1.discount,u.discount_atax=u.discount_atax+n[p].level2.discount):(0!=n[p].level1.sales||0!=n[p].level1.discount)&&u.sales_atax>=n[p].level1.sales&&(1===n[p].type?u.discount_atax=u.discount_atax+(u.sales_atax-n[p].level1.sales)*n[p].level1.discount/100:2===n[p].type&&(u.discount_atax=n[p].level1.discount)):2===n[p].method&&((0!=n[p].level5.sales||0!=n[p].level5.discount)&&u.sales_atax>=n[p].level5.sales?1===n[p].type?u.discount_atax=u.sales_atax*n[p].level5.discount/100:2===n[p].type&&(u.discount_atax=n[p].level5.discount):(0!=n[p].level4.sales||0!=n[p].level4.discount)&&u.sales_atax>=n[p].level4.sales?1===n[p].type?u.discount_atax=u.sales_atax*n[p].level4.discount/100:2===n[p].type&&(u.discount_atax=n[p].level4.discount):(0!=n[p].level3.sales||0!=n[p].level3.discount)&&u.sales_atax>=n[p].level3.sales?1===n[p].type?u.discount_atax=u.sales_atax*n[p].level3.discount/100:2===n[p].type&&(u.discount_atax=n[p].level3.discount):(0!=n[p].level2.sales||0!=n[p].level2.discount)&&u.sales_atax>=n[p].level2.sales?1===n[p].type?u.discount_atax=u.sales_atax*n[p].level2.discount/100:2===n[p].type&&(u.discount_atax=n[p].level2.discount):(0!=n[p].level1.sales||0!=n[p].level1.discount)&&u.sales_atax>=n[p].level1.sales&&(1===n[p].type?u.discount_atax=u.sales_atax*n[p].level1.discount/100:2===n[p].type&&(u.discount_atax=n[p].level1.discount))),c.sales_btax=c.sales_btax+u.sales_btax,c.sales_atax=c.sales_atax+u.sales_atax,c.discount_btax=c.discount_btax+u.discount_btax,c.discount_atax=c.discount_atax+u.discount_atax,u.index=c.size+1,c.docs.push(u),c.size++,c.empty=!1;break}}console.log("getReportDiscount_Customers",c),a(c)}))}else a(c)}))},t.prototype.getReportCommission_Employees=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Array;if("all"===n)r=i.vhAuth.getlocalEmployees();else{var l=i.vhAuth.getlocalEmployee(n);r.push(l)}var c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,commission_btax:0,commission_atax:0};if(r.length>0){var u=void 0;u="all"===n?"all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$gte:t,$lte:e},id_employee:{$eq:n},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},id_employee:{$eq:n},bill_type:{$in:[1]},id_branch:{$eq:o}};var d=i.vhmongo_firebase.database().getDocsByFields("commissions",{},{},{},0),_=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0);Promise.all([d,_]).then((function(t){var e=t[0],n=t[1];if(n.length>0)for(var o=0;o<r.length;o++){for(var i=!1,s={id_employee:r[o]._id,name:r[o].name,sales_btax:0,sales_atax:0,quantity:0,commission_btax:0,commission_atax:0,commission_name:""},l=0;l<n.length;l++)if(r[o]._id===n[l].id_employee)if(i=!0,5===n[l].ptype){if(null!=n[l].combos)for(var u=0;u<n[l].combos.length;u++)s.quantity=s.quantity+n[l].combos[u].quantity*n[l].quantity,s.sales_btax=s.sales_btax+n[l].combos[u].price*n[l].combos[u].quantity*n[l].quantity,s.sales_atax=s.sales_atax+n[l].combos[u].price*n[l].combos[u].quantity*n[l].quantity*(1+n[l].tax/100)}else s.quantity=s.quantity+n[l].quantity,s.sales_btax=s.sales_btax+n[l].price*n[l].quantity,s.sales_atax=s.sales_atax+n[l].price*n[l].quantity*(1+n[l].tax/100);if(i&&null!=r[o].id_commission&&null!=r[o].id_commission)for(var d=0;d<e.length;d++)if(e[d]._id===r[o].id_commission){s.commission_name=e[d].name,1===e[d].method?(0!=e[d].level5.sales||0!=e[d].level5.commission)&&s.sales_btax>=e[d].level5.sales?1===e[d].type?(s.commission_btax=s.commission_btax+(e[d].level2.sales-e[d].level1.sales)*e[d].level1.commission/100,s.commission_btax=s.commission_btax+(e[d].level3.sales-e[d].level2.sales)*e[d].level2.commission/100,s.commission_btax=s.commission_btax+(e[d].level4.sales-e[d].level3.sales)*e[d].level3.commission/100,s.commission_btax=s.commission_btax+(e[d].level5.sales-e[d].level4.sales)*e[d].level4.commission/100,s.commission_btax=s.commission_btax+(s.sales_btax-e[d].level5.sales)*e[d].level5.commission/100):2===e[d].type&&(s.commission_btax=e[d].level1.commission,s.commission_btax=s.commission_btax+e[d].level2.commission,s.commission_btax=s.commission_btax+e[d].level3.commission,s.commission_btax=s.commission_btax+e[d].level4.commission,s.commission_btax=s.commission_btax+e[d].level5.commission):(0!=e[d].level4.sales||0!=e[d].level4.commission)&&s.sales_btax>=e[d].level4.sales?1===e[d].type?(s.commission_btax=s.commission_btax+(e[d].level2.sales-e[d].level1.sales)*e[d].level1.commission/100,s.commission_btax=s.commission_btax+(e[d].level3.sales-e[d].level2.sales)*e[d].level2.commission/100,s.commission_btax=s.commission_btax+(e[d].level4.sales-e[d].level3.sales)*e[d].level3.commission/100,s.commission_btax=s.commission_btax+(s.sales_btax-e[d].level4.sales)*e[d].level4.commission/100):2===e[d].type&&(s.commission_btax=e[d].level1.commission,s.commission_btax=s.commission_btax+e[d].level2.commission,s.commission_btax=s.commission_btax+e[d].level3.commission,s.commission_btax=s.commission_btax+e[d].level4.commission):(0!=e[d].level3.sales||0!=e[d].level3.commission)&&s.sales_btax>=e[d].level3.sales?1===e[d].type?(s.commission_btax=s.commission_btax+(e[d].level2.sales-e[d].level1.sales)*e[d].level1.commission/100,s.commission_btax=s.commission_btax+(e[d].level3.sales-e[d].level2.sales)*e[d].level2.commission/100,s.commission_btax=s.commission_btax+(s.sales_btax-e[d].level3.sales)*e[d].level3.commission/100):2===e[d].type&&(s.commission_btax=e[d].level1.commission,s.commission_btax=s.commission_btax+e[d].level2.commission,s.commission_btax=s.commission_btax+e[d].level3.commission):(0!=e[d].level2.sales||0!=e[d].level2.commission)&&s.sales_btax>=e[d].level2.sales?1===e[d].type?(s.commission_btax=s.commission_btax+(e[d].level2.sales-e[d].level1.sales)*e[d].level1.commission/100,s.commission_btax=s.commission_btax+(s.sales_btax-e[d].level2.sales)*e[d].level2.commission/100):2===e[d].type&&(s.commission_btax=e[d].level1.commission,s.commission_btax=s.commission_btax+e[d].level2.commission):(0!=e[d].level1.sales||0!=e[d].level1.commission)&&s.sales_btax>=e[d].level1.sales&&(1===e[d].type?s.commission_btax=s.commission_btax+(s.sales_btax-e[d].level1.sales)*e[d].level1.commission/100:2===e[d].type&&(s.commission_btax=e[d].level1.commission)):2===e[d].method&&((0!=e[d].level5.sales||0!=e[d].level5.commission)&&s.sales_btax>=e[d].level5.sales?1===e[d].type?s.commission_btax=s.sales_btax*e[d].level5.commission/100:2===e[d].type&&(s.commission_btax=e[d].level5.commission):(0!=e[d].level4.sales||0!=e[d].level4.commission)&&s.sales_btax>=e[d].level4.sales?1===e[d].type?s.commission_btax=s.sales_btax*e[d].level4.commission/100:2===e[d].type&&(s.commission_btax=e[d].level4.commission):(0!=e[d].level3.sales||0!=e[d].level3.commission)&&s.sales_btax>=e[d].level3.sales?1===e[d].type?s.commission_btax=s.sales_btax*e[d].level3.commission/100:2===e[d].type&&(s.commission_btax=e[d].level3.commission):(0!=e[d].level2.sales||0!=e[d].level2.commission)&&s.sales_btax>=e[d].level2.sales?1===e[d].type?s.commission_btax=s.sales_btax*e[d].level2.commission/100:2===e[d].type&&(s.commission_btax=e[d].level2.commission):(0!=e[d].level1.sales||0!=e[d].level1.commission)&&s.sales_btax>=e[d].level1.sales&&(1===e[d].type?s.commission_btax=s.sales_btax*e[d].level1.commission/100:2===e[d].type&&(s.commission_btax=e[d].level1.commission))),1===e[d].method?(0!=e[d].level5.sales||0!=e[d].level5.commission)&&s.sales_atax>=e[d].level5.sales?1===e[d].type?(s.commission_atax=s.commission_atax+(e[d].level2.sales-e[d].level1.sales)*e[d].level1.commission/100,s.commission_atax=s.commission_atax+(e[d].level3.sales-e[d].level2.sales)*e[d].level2.commission/100,s.commission_atax=s.commission_atax+(e[d].level4.sales-e[d].level3.sales)*e[d].level3.commission/100,s.commission_atax=s.commission_atax+(e[d].level5.sales-e[d].level4.sales)*e[d].level4.commission/100,s.commission_atax=s.commission_atax+(s.sales_atax-e[d].level5.sales)*e[d].level5.commission/100):2===e[d].type&&(s.commission_atax=e[d].level1.commission,s.commission_atax=s.commission_atax+e[d].level2.commission,s.commission_atax=s.commission_atax+e[d].level3.commission,s.commission_atax=s.commission_atax+e[d].level4.commission,s.commission_atax=s.commission_atax+e[d].level5.commission):(0!=e[d].level4.sales||0!=e[d].level4.commission)&&s.sales_atax>=e[d].level4.sales?1===e[d].type?(s.commission_atax=s.commission_atax+(e[d].level2.sales-e[d].level1.sales)*e[d].level1.commission/100,s.commission_atax=s.commission_atax+(e[d].level3.sales-e[d].level2.sales)*e[d].level2.commission/100,s.commission_atax=s.commission_atax+(e[d].level4.sales-e[d].level3.sales)*e[d].level3.commission/100,s.commission_atax=s.commission_atax+(s.sales_atax-e[d].level4.sales)*e[d].level4.commission/100):2===e[d].type&&(s.commission_atax=e[d].level1.commission,s.commission_atax=s.commission_atax+e[d].level2.commission,s.commission_atax=s.commission_atax+e[d].level3.commission,s.commission_atax=s.commission_atax+e[d].level4.commission):(0!=e[d].level3.sales||0!=e[d].level3.commission)&&s.sales_atax>=e[d].level3.sales?1===e[d].type?(s.commission_atax=s.commission_atax+(e[d].level2.sales-e[d].level1.sales)*e[d].level1.commission/100,s.commission_atax=s.commission_atax+(e[d].level3.sales-e[d].level2.sales)*e[d].level2.commission/100,s.commission_atax=s.commission_atax+(s.sales_atax-e[d].level3.sales)*e[d].level3.commission/100):2===e[d].type&&(s.commission_atax=e[d].level1.commission,s.commission_atax=s.commission_atax+e[d].level2.commission,s.commission_atax=s.commission_atax+e[d].level3.commission):(0!=e[d].level2.sales||0!=e[d].level2.commission)&&s.sales_atax>=e[d].level2.sales?1===e[d].type?(s.commission_atax=s.commission_atax+(e[d].level2.sales-e[d].level1.sales)*e[d].level1.commission/100,s.commission_atax=s.commission_atax+(s.sales_atax-e[d].level2.sales)*e[d].level2.commission/100):2===e[d].type&&(s.commission_atax=e[d].level1.commission,s.commission_atax=s.commission_atax+e[d].level2.commission):(0!=e[d].level1.sales||0!=e[d].level1.commission)&&s.sales_atax>=e[d].level1.sales&&(1===e[d].type?s.commission_atax=s.commission_atax+(s.sales_atax-e[d].level1.sales)*e[d].level1.commission/100:2===e[d].type&&(s.commission_atax=e[d].level1.commission)):2===e[d].method&&((0!=e[d].level5.sales||0!=e[d].level5.commission)&&s.sales_atax>=e[d].level5.sales?1===e[d].type?s.commission_atax=s.sales_atax*e[d].level5.commission/100:2===e[d].type&&(s.commission_atax=e[d].level5.commission):(0!=e[d].level4.sales||0!=e[d].level4.commission)&&s.sales_atax>=e[d].level4.sales?1===e[d].type?s.commission_atax=s.sales_atax*e[d].level4.commission/100:2===e[d].type&&(s.commission_atax=e[d].level4.commission):(0!=e[d].level3.sales||0!=e[d].level3.commission)&&s.sales_atax>=e[d].level3.sales?1===e[d].type?s.commission_atax=s.sales_atax*e[d].level3.commission/100:2===e[d].type&&(s.commission_atax=e[d].level3.commission):(0!=e[d].level2.sales||0!=e[d].level2.commission)&&s.sales_atax>=e[d].level2.sales?1===e[d].type?s.commission_atax=s.sales_atax*e[d].level2.commission/100:2===e[d].type&&(s.commission_atax=e[d].level2.commission):(0!=e[d].level1.sales||0!=e[d].level1.commission)&&s.sales_atax>=e[d].level1.sales&&(1===e[d].type?s.commission_atax=s.sales_atax*e[d].level1.commission/100:2===e[d].type&&(s.commission_atax=e[d].level1.commission))),c.sales_btax=c.sales_btax+s.sales_btax,c.sales_atax=c.sales_atax+s.sales_atax,c.commission_btax=c.commission_btax+s.commission_btax,c.commission_atax=c.commission_atax+s.commission_atax,s.index=c.size+1,c.docs.push(s),c.size++,c.empty=!1;break}}console.log("getReportCommission_Employees",c),a(c)}))}else a(c)}))},t.prototype.getReportCommission_Employees_new=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Array;if("all"===n)r=i.vhAuth.getlocalEmployees();else{var l=i.vhAuth.getlocalEmployee(n);r.push(l)}var c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,commission_btax:0,commission_atax:0};if(r.length>0){var u=void 0;u="all"===n?"all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$gte:t,$lte:e},id_employee:{$eq:n},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},id_employee:{$eq:n},bill_type:{$in:[1]},id_branch:{$eq:o}};var d=i.vhmongo_firebase.database().getDocsByFields("commissions",{},{},{},0),_=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0),p=i.vhmongo_firebase.database().getDocsByFields("employee_classs",{},{},{},0);Promise.all([d,_,p]).then((function(t){var e=t[0],n=t[1],o=t[2];if(n.length>0)for(var i=0;i<r.length;i++){for(var s=!1,l={id_employee:r[i]._id,name:r[i].name,sales_btax:0,sales_atax:0,quantity:0,commission_btax:0,commission_atax:0,commission_name:""},u=0;u<n.length;u++)if(r[i]._id===n[u].id_employee)if(s=!0,5===n[u].ptype){if(null!=n[u].combos)for(var d=0;d<n[u].combos.length;d++)l.quantity=l.quantity+n[u].combos[d].quantity*n[u].quantity,l.sales_btax=l.sales_btax+n[u].combos[d].price*n[u].combos[d].quantity*n[u].quantity,l.sales_atax=l.sales_atax+n[u].combos[d].price*n[u].combos[d].quantity*n[u].quantity*(1+n[u].tax/100)}else l.quantity=l.quantity+n[u].quantity,l.sales_btax=l.sales_btax+n[u].price*n[u].quantity,l.sales_atax=l.sales_atax+n[u].price*n[u].quantity*(1+n[u].tax/100);if(s&&null!=r[i].id_employee_class&&null!=r[i].id_employee_class)for(u=0;u<o.length;u++)if(o[u]._id===r[i].id_employee_class&&null!=o[u].id_commission&&null!=o[u].id_commission)for(var _=0;_<e.length;_++)if(e[_]._id===o[u].id_commission){l.commission_name=e[_].name,1===e[_].method?(0!=e[_].level5.sales||0!=e[_].level5.commission)&&l.sales_btax>=e[_].level5.sales?1===e[_].type?(l.commission_btax=l.commission_btax+(e[_].level2.sales-e[_].level1.sales)*e[_].level1.commission/100,l.commission_btax=l.commission_btax+(e[_].level3.sales-e[_].level2.sales)*e[_].level2.commission/100,l.commission_btax=l.commission_btax+(e[_].level4.sales-e[_].level3.sales)*e[_].level3.commission/100,l.commission_btax=l.commission_btax+(e[_].level5.sales-e[_].level4.sales)*e[_].level4.commission/100,l.commission_btax=l.commission_btax+(l.sales_btax-e[_].level5.sales)*e[_].level5.commission/100):2===e[_].type&&(l.commission_btax=e[_].level1.commission,l.commission_btax=l.commission_btax+e[_].level2.commission,l.commission_btax=l.commission_btax+e[_].level3.commission,l.commission_btax=l.commission_btax+e[_].level4.commission,l.commission_btax=l.commission_btax+e[_].level5.commission):(0!=e[_].level4.sales||0!=e[_].level4.commission)&&l.sales_btax>=e[_].level4.sales?1===e[_].type?(l.commission_btax=l.commission_btax+(e[_].level2.sales-e[_].level1.sales)*e[_].level1.commission/100,l.commission_btax=l.commission_btax+(e[_].level3.sales-e[_].level2.sales)*e[_].level2.commission/100,l.commission_btax=l.commission_btax+(e[_].level4.sales-e[_].level3.sales)*e[_].level3.commission/100,l.commission_btax=l.commission_btax+(l.sales_btax-e[_].level4.sales)*e[_].level4.commission/100):2===e[_].type&&(l.commission_btax=e[_].level1.commission,l.commission_btax=l.commission_btax+e[_].level2.commission,l.commission_btax=l.commission_btax+e[_].level3.commission,l.commission_btax=l.commission_btax+e[_].level4.commission):(0!=e[_].level3.sales||0!=e[_].level3.commission)&&l.sales_btax>=e[_].level3.sales?1===e[_].type?(l.commission_btax=l.commission_btax+(e[_].level2.sales-e[_].level1.sales)*e[_].level1.commission/100,l.commission_btax=l.commission_btax+(e[_].level3.sales-e[_].level2.sales)*e[_].level2.commission/100,l.commission_btax=l.commission_btax+(l.sales_btax-e[_].level3.sales)*e[_].level3.commission/100):2===e[_].type&&(l.commission_btax=e[_].level1.commission,l.commission_btax=l.commission_btax+e[_].level2.commission,l.commission_btax=l.commission_btax+e[_].level3.commission):(0!=e[_].level2.sales||0!=e[_].level2.commission)&&l.sales_btax>=e[_].level2.sales?1===e[_].type?(l.commission_btax=l.commission_btax+(e[_].level2.sales-e[_].level1.sales)*e[_].level1.commission/100,l.commission_btax=l.commission_btax+(l.sales_btax-e[_].level2.sales)*e[_].level2.commission/100):2===e[_].type&&(l.commission_btax=e[_].level1.commission,l.commission_btax=l.commission_btax+e[_].level2.commission):(0!=e[_].level1.sales||0!=e[_].level1.commission)&&l.sales_btax>=e[_].level1.sales&&(1===e[_].type?l.commission_btax=l.commission_btax+(l.sales_btax-e[_].level1.sales)*e[_].level1.commission/100:2===e[_].type&&(l.commission_btax=e[_].level1.commission)):2===e[_].method&&((0!=e[_].level5.sales||0!=e[_].level5.commission)&&l.sales_btax>=e[_].level5.sales?1===e[_].type?l.commission_btax=l.sales_btax*e[_].level5.commission/100:2===e[_].type&&(l.commission_btax=e[_].level5.commission):(0!=e[_].level4.sales||0!=e[_].level4.commission)&&l.sales_btax>=e[_].level4.sales?1===e[_].type?l.commission_btax=l.sales_btax*e[_].level4.commission/100:2===e[_].type&&(l.commission_btax=e[_].level4.commission):(0!=e[_].level3.sales||0!=e[_].level3.commission)&&l.sales_btax>=e[_].level3.sales?1===e[_].type?l.commission_btax=l.sales_btax*e[_].level3.commission/100:2===e[_].type&&(l.commission_btax=e[_].level3.commission):(0!=e[_].level2.sales||0!=e[_].level2.commission)&&l.sales_btax>=e[_].level2.sales?1===e[_].type?l.commission_btax=l.sales_btax*e[_].level2.commission/100:2===e[_].type&&(l.commission_btax=e[_].level2.commission):(0!=e[_].level1.sales||0!=e[_].level1.commission)&&l.sales_btax>=e[_].level1.sales&&(1===e[_].type?l.commission_btax=l.sales_btax*e[_].level1.commission/100:2===e[_].type&&(l.commission_btax=e[_].level1.commission))),1===e[_].method?(0!=e[_].level5.sales||0!=e[_].level5.commission)&&l.sales_atax>=e[_].level5.sales?1===e[_].type?(l.commission_atax=l.commission_atax+(e[_].level2.sales-e[_].level1.sales)*e[_].level1.commission/100,l.commission_atax=l.commission_atax+(e[_].level3.sales-e[_].level2.sales)*e[_].level2.commission/100,l.commission_atax=l.commission_atax+(e[_].level4.sales-e[_].level3.sales)*e[_].level3.commission/100,l.commission_atax=l.commission_atax+(e[_].level5.sales-e[_].level4.sales)*e[_].level4.commission/100,l.commission_atax=l.commission_atax+(l.sales_atax-e[_].level5.sales)*e[_].level5.commission/100):2===e[_].type&&(l.commission_atax=e[_].level1.commission,l.commission_atax=l.commission_atax+e[_].level2.commission,l.commission_atax=l.commission_atax+e[_].level3.commission,l.commission_atax=l.commission_atax+e[_].level4.commission,l.commission_atax=l.commission_atax+e[_].level5.commission):(0!=e[_].level4.sales||0!=e[_].level4.commission)&&l.sales_atax>=e[_].level4.sales?1===e[_].type?(l.commission_atax=l.commission_atax+(e[_].level2.sales-e[_].level1.sales)*e[_].level1.commission/100,l.commission_atax=l.commission_atax+(e[_].level3.sales-e[_].level2.sales)*e[_].level2.commission/100,l.commission_atax=l.commission_atax+(e[_].level4.sales-e[_].level3.sales)*e[_].level3.commission/100,l.commission_atax=l.commission_atax+(l.sales_atax-e[_].level4.sales)*e[_].level4.commission/100):2===e[_].type&&(l.commission_atax=e[_].level1.commission,l.commission_atax=l.commission_atax+e[_].level2.commission,l.commission_atax=l.commission_atax+e[_].level3.commission,l.commission_atax=l.commission_atax+e[_].level4.commission):(0!=e[_].level3.sales||0!=e[_].level3.commission)&&l.sales_atax>=e[_].level3.sales?1===e[_].type?(l.commission_atax=l.commission_atax+(e[_].level2.sales-e[_].level1.sales)*e[_].level1.commission/100,l.commission_atax=l.commission_atax+(e[_].level3.sales-e[_].level2.sales)*e[_].level2.commission/100,l.commission_atax=l.commission_atax+(l.sales_atax-e[_].level3.sales)*e[_].level3.commission/100):2===e[_].type&&(l.commission_atax=e[_].level1.commission,l.commission_atax=l.commission_atax+e[_].level2.commission,l.commission_atax=l.commission_atax+e[_].level3.commission):(0!=e[_].level2.sales||0!=e[_].level2.commission)&&l.sales_atax>=e[_].level2.sales?1===e[_].type?(l.commission_atax=l.commission_atax+(e[_].level2.sales-e[_].level1.sales)*e[_].level1.commission/100,l.commission_atax=l.commission_atax+(l.sales_atax-e[_].level2.sales)*e[_].level2.commission/100):2===e[_].type&&(l.commission_atax=e[_].level1.commission,l.commission_atax=l.commission_atax+e[_].level2.commission):(0!=e[_].level1.sales||0!=e[_].level1.commission)&&l.sales_atax>=e[_].level1.sales&&(1===e[_].type?l.commission_atax=l.commission_atax+(l.sales_atax-e[_].level1.sales)*e[_].level1.commission/100:2===e[_].type&&(l.commission_atax=e[_].level1.commission)):2===e[_].method&&((0!=e[_].level5.sales||0!=e[_].level5.commission)&&l.sales_atax>=e[_].level5.sales?1===e[_].type?l.commission_atax=l.sales_atax*e[_].level5.commission/100:2===e[_].type&&(l.commission_atax=e[_].level5.commission):(0!=e[_].level4.sales||0!=e[_].level4.commission)&&l.sales_atax>=e[_].level4.sales?1===e[_].type?l.commission_atax=l.sales_atax*e[_].level4.commission/100:2===e[_].type&&(l.commission_atax=e[_].level4.commission):(0!=e[_].level3.sales||0!=e[_].level3.commission)&&l.sales_atax>=e[_].level3.sales?1===e[_].type?l.commission_atax=l.sales_atax*e[_].level3.commission/100:2===e[_].type&&(l.commission_atax=e[_].level3.commission):(0!=e[_].level2.sales||0!=e[_].level2.commission)&&l.sales_atax>=e[_].level2.sales?1===e[_].type?l.commission_atax=l.sales_atax*e[_].level2.commission/100:2===e[_].type&&(l.commission_atax=e[_].level2.commission):(0!=e[_].level1.sales||0!=e[_].level1.commission)&&l.sales_atax>=e[_].level1.sales&&(1===e[_].type?l.commission_atax=l.sales_atax*e[_].level1.commission/100:2===e[_].type&&(l.commission_atax=e[_].level1.commission))),c.sales_btax=c.sales_btax+l.sales_btax,c.sales_atax=c.sales_atax+l.sales_atax,c.commission_btax=c.commission_btax+l.commission_btax,c.commission_atax=c.commission_atax+l.commission_atax,l.index=c.size+1,c.docs.push(l),c.size++,c.empty=!1;break}}console.log("getReportCommission_Employees",c),a(c)}))}else a(c)}))},t.prototype.getReportCashBook=function(t,e,n,o){var i=this;t=new Date(t),e=new Date(e);var a=[1,7,10,11,34,2,8,12,33],s=this.vhAuth.getStore();return new Promise((function(r,l){var c,u=0,d=null;if("all"===n)if("all"===o||void 0===o){for(var _=i.getlocalWallets(),p=i.getDefaultBranch()._id,b=null,f=0;f<_.length;f++)if("id_cash"===_[f]._id&&null!=_[f][o]&&null!=_[f][o].cashbook)for(var h=0;h<_[f][p].cashbook.length&&!(new Date(_[f][p].cashbook[h].date).getTime()>t.getTime());h++)d=new Date(_[f][p].cashbook[h].date),b=h;if(d)for(f=0;f<_.length;f++)if("id_cash"===_[f]._id)for(var y=i.getlocalBranchs(),m=0;m<y.length;m++)u+=_[f][y[m]._id].cashbook[b].cashbook_first;else u+=_[f].cashbook[b].cashbook_first}else{for(_=i.getlocalWallets().filter((function(t){return t.id_branch===o||"id_cash"===t._id})),b=null,f=0;f<_.length;f++)if("id_cash"===_[f]._id&&null!=_[f][o]&&null!=_[f][o].cashbook)for(h=0;h<_[f][o].cashbook.length&&!(new Date(_[f][o].cashbook[h].date).getTime()>t.getTime());h++)d=new Date(_[f][o].cashbook[h].date),b=h;if(d)for(f=0;f<_.length;f++)"id_cash"===_[f]._id?u+=_[f][o].cashbook[b].cashbook_first:u+=_[f].cashbook[b].cashbook_first}else if("all"===o||void 0===o)console.log("trường hợp này chưa có hàm, liên hệ anh Huy viết");else{var v=i.getlocalWallet(n);if("id_cash"===v._id){if(null!=v[o]&&null!=v[o].cashbook)for(h=0;h<v[o].cashbook.length&&!(new Date(v[o].cashbook[h].date).getTime()>t.getTime());h++)d=new Date(v[o].cashbook[h].date),u=v[o].cashbook[h].cashbook_first}else if(null!=v.cashbook)for(h=0;h<v.cashbook.length&&!(new Date(v.cashbook[h].date).getTime()>t.getTime());h++)d=new Date(v.cashbook[h].date),u=v.cashbook[h].cashbook_first}d||(d=new Date(s.registrationdate));var g=new Array;if("all"===n)if("all"===o||void 0===o){var x={date:{$gte:d,$lte:e},bill_type:{$in:a},payment_type:{$eq:1}},q={date:{$gte:d,$lte:e},bill_type:{$in:a},payment_type:{$eq:3}};g.push(i.vhmongo_firebase.database().getDocsByFields("bills",x,{},{date:1},0)),g.push(i.vhmongo_firebase.database().getDocsByFields("bills",q,{},{date:1},0))}else{x={date:{$gte:d,$lte:e},id_branch:{$eq:o},bill_type:{$in:a},payment_type:{$eq:1}},q={date:{$gte:d,$lte:e},id_branch:{$eq:o},bill_type:{$in:a},payment_type:{$eq:3}};g.push(i.vhmongo_firebase.database().getDocsByFields("bills",x,{},{date:1},0)),g.push(i.vhmongo_firebase.database().getDocsByFields("bills",q,{},{date:1},0))}else"all"===o||void 0===o||(c={date:{$gte:d,$lte:e},id_wallet:{$eq:n},id_branch:{$eq:o},bill_type:{$in:a}},g.push(i.vhmongo_firebase.database().getDocsByFields("bills",c,{},{date:1},0)));Promise.all(g).then((function(e){var n=e.flat();n=i.vhAlgorithm.sortDatebyASC(n,"date");var o={docs:new Array,empty:!0,size:0,cashbook_first:u,income:0,expenditure:0,cashbook_last:0};if(n.length>0)for(var a=0;a<n.length;a++){var s=Object.assign({},n[a]);if(2!=(null==s?void 0:s.payment_type)){delete s.fee,delete s.discount,delete s.note,delete s.total,delete s.tax;var l=new Date(s.date);1===s.bill_type||7===s.bill_type||10===s.bill_type||11===s.bill_type||34===s.bill_type?l>=t?(o.income=o.income+s.payment,s.index=o.size+1,o.docs.push(s),o.size++,o.empty=!1):o.cashbook_first=o.cashbook_first+s.payment:2!==s.bill_type&&8!==s.bill_type&&12!==s.bill_type&&33!==s.bill_type||(l>=t?(o.expenditure=o.expenditure+s.payment,s.index=o.size+1,o.docs.push(s),o.size++,o.empty=!1):o.cashbook_first=o.cashbook_first-s.payment)}}o.cashbook_last=o.cashbook_first+o.income-o.expenditure,r(o)}))}))},t.prototype.getReportCashBook_old=function(t,e,n,o){var i=this;return t=new Date(t),e=new Date(e),new Promise((function(a,s){var r;r="all"===n?"all"===o||void 0===o?{date:{$lte:e}}:{date:{$lte:e},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$lte:e},id_wallet:{$eq:n}}:{date:{$lte:e},id_wallet:{$eq:n},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("bills",r,{},{date:1},0).then((function(e){var n={docs:new Array,empty:!0,size:0,cashbook_first:0,income:0,expenditure:0,cashbook_last:0};if(e.length>0)for(var o=0;o<e.length;o++){var i=Object.assign({},e[o]);if(2!=(null==i?void 0:i.payment_type)){delete i.fee,delete i.discount,delete i.note,delete i.total,delete i.tax;var s=new Date(i.date);1!==i.bill_type&&7!==i.bill_type&&10!==i.bill_type&&11!==i.bill_type&&34!==i.bill_type||(s>=t?(n.income=n.income+i.payment,i.index=n.size+1,n.docs.push(i),n.size++,n.empty=!1):n.cashbook_first=n.cashbook_first+i.payment),2!==i.bill_type&&8!==i.bill_type&&12!==i.bill_type&&33!==i.bill_type||(s>=t?(n.expenditure=n.expenditure+i.payment,i.index=n.size+1,n.docs.push(i),n.size++,n.empty=!1):n.cashbook_first=n.cashbook_first-i.payment)}}n.cashbook_last=n.cashbook_first+n.income-n.expenditure,a(n)}))}))},t.prototype.syncCashBookEveryDay_Stock1stDayOfMonth=function(){var t=this;return new Promise((function(e,n){var o=t.vhAuth.getStore(),i=[Object.assign({},t.getDefaultBranch())];t.vhmongo_firebase.auth().getServerDate().then((function(n){var a=t.get1stDayOfMonthArray(o.registrationdate,n);if(a.length>0){for(var s=new Array,r=function(n){for(var o=i[n]._id,r=t.getlocalWallets().filter((function(t){return t.id_branch===o||"id_cash"===t._id})),l=new Array,c=function(n){if("id_cash"===r[n]._id)if(null!=r[n][o]&&null!=r[n][o].cashbook){var i=r[n][o].cashbook[r[n][o].cashbook.length-1];if(new Date(i.date).getTime()!=new Date(a[a.length-1]).getTime()){for(var s=r[n][o].cashbook.length;s<a.length;s++)r[n][o].cashbook[s]={},r[n][o].cashbook[s].date=a[s],r[n][o].cashbook[s].cashbook_first=i.cashbook_first;l[n]=new Promise((function(e){for(var a=[],s=[1,7,10,11,34,2,8,12,33];s.length;){var l=s.splice(0,10),c={date:{$gte:new Date(i.date)},id_branch:{$eq:o},id_wallet:{$eq:"id_cash"},bill_type:{$in:l}};a.push(t.vhmongo_firebase.database().getDocsByFields("bills",c,{},{date:1},0))}Promise.all(a).then((function(t){var i=t.flat();if(i.length>0)for(var a=0;a<i.length;a++)if("id_cash"===i[a].id_wallet)for(var s=0;s<r[n][o].cashbook.length;s++)new Date(i[a].date)<new Date(r[n][o].cashbook[s].date)&&(1===i[a].bill_type||7===i[a].bill_type||10===i[a].bill_type||11===i[a].bill_type||34===i[a].bill_type?r[n][o].cashbook[s].cashbook_first=r[n][o].cashbook[s].cashbook_first+i[a].payment:2!==i[a].bill_type&&8!==i[a].bill_type&&12!==i[a].bill_type&&33!==i[a].bill_type||(r[n][o].cashbook[s].cashbook_first=r[n][o].cashbook[s].cashbook_first-i[a].payment));e(r[n])}))}))}else e(null)}else l[n]=new Promise((function(e){for(var i=[],s=[1,7,10,11,34,2,8,12,33];s.length;){var l=s.splice(0,10),c={id_branch:{$eq:o},id_wallet:{$eq:"id_cash"},bill_type:{$in:l}};i.push(t.vhmongo_firebase.database().getDocsByFields("bills",c,{},{date:1},0))}Promise.all(i).then((function(t){var i=t.flat();r[n][o]={},r[n][o].cashbook=new Array;for(var s=0;s<a.length;s++)r[n][o].cashbook[s]={},r[n][o].cashbook[s].date=a[s],r[n][o].cashbook[s].cashbook_first=0;if(i.length>0)for(var l=0;l<i.length;l++)if("id_cash"===i[l].id_wallet)for(s=0;s<r[n][o].cashbook.length;s++)new Date(i[l].date)<new Date(r[n][o].cashbook[s].date)&&(1===i[l].bill_type||7===i[l].bill_type||10===i[l].bill_type||11===i[l].bill_type||34===i[l].bill_type?r[n][o].cashbook[s].cashbook_first=r[n][o].cashbook[s].cashbook_first+i[l].payment:2!==i[l].bill_type&&8!==i[l].bill_type&&12!==i[l].bill_type&&33!==i[l].bill_type||(r[n][o].cashbook[s].cashbook_first=r[n][o].cashbook[s].cashbook_first-i[l].payment));e(r[n])}))}));else if("id_cash"!=r[n]._id)if(null!=r[n].cashbook){var c=r[n].cashbook[r[n].cashbook.length-1];if(new Date(c.date).getTime()!=new Date(a[a.length-1]).getTime()){for(s=r[n].cashbook.length;s<a.length;s++)r[n].cashbook[s]={},r[n].cashbook[s].date=a[s],r[n].cashbook[s].cashbook_first=c.cashbook_first;l[n]=new Promise((function(e){for(var i=[],a=[1,7,10,11,34,2,8,12,33];a.length;){var s=a.splice(0,10),l={date:{$gte:new Date(c.date)},id_branch:{$eq:o},id_wallet:{$eq:r[n]._id},bill_type:{$in:s}};i.push(t.vhmongo_firebase.database().getDocsByFields("bills",l,{},{date:1},0))}Promise.all(i).then((function(t){var o=t.flat();if(o.length>0)for(var i=0;i<o.length;i++)if(o[i].id_wallet===r[n]._id)for(var a=0;a<r[n].cashbook.length;a++)new Date(o[i].date)<new Date(r[n].cashbook[a].date)&&(1===o[i].bill_type||7===o[i].bill_type||10===o[i].bill_type||11===o[i].bill_type||34===o[i].bill_type?r[n].cashbook[a].cashbook_first=r[n].cashbook[a].cashbook_first+o[i].payment:2!==o[i].bill_type&&8!==o[i].bill_type&&12!==o[i].bill_type&&33!==o[i].bill_type||(r[n].cashbook[a].cashbook_first=r[n].cashbook[a].cashbook_first-o[i].payment));e(r[n])}))}))}else e(null)}else l[n]=new Promise((function(e){for(var i=[],s=[1,7,10,11,34,2,8,12,33];s.length;){var l=s.splice(0,10),c={id_branch:{$eq:o},id_wallet:{$eq:r[n]._id},bill_type:{$in:l}};i.push(t.vhmongo_firebase.database().getDocsByFields("bills",c,{},{date:1},0))}Promise.all(i).then((function(t){var o=t.flat();r[n].cashbook=new Array;for(var i=0;i<a.length;i++)r[n].cashbook[i]={},r[n].cashbook[i].date=a[i],r[n].cashbook[i].cashbook_first=0;if(o.length>0)for(var s=0;s<o.length;s++)if(o[s].id_wallet===r[n]._id)for(i=0;i<r[n].cashbook.length;i++)new Date(o[s].date)<new Date(r[n].cashbook[i].date)&&(1===o[s].bill_type||7===o[s].bill_type||10===o[s].bill_type||11===o[s].bill_type||34===o[s].bill_type?r[n].cashbook[i].cashbook_first=r[n].cashbook[i].cashbook_first+o[s].payment:2!==o[s].bill_type&&8!==o[s].bill_type&&12!==o[s].bill_type&&33!==o[s].bill_type||(r[n].cashbook[i].cashbook_first=r[n].cashbook[i].cashbook_first-o[s].payment));e(r[n])}))}))},u=0;u<r.length;u++)c(u);s[n]=new Promise((function(e){Promise.all(l).then((function(n){for(var i=0;i<n.length;i++)if(n[i])if("id_cash"===n[i]._id){var a={};a[o]=n[i][o],t.vhmongo_firebase.database().updateDoc("wallets",n[i]._id,Object.assign({},a))}else t.vhmongo_firebase.database().updateDoc("wallets",n[i]._id,{cashbook:n[i].cashbook});e(n)}))}))},l=0;l<i.length;l++)r(l);Promise.all(s).then((function(t){console.log("syncCashBookEveryDay",t),e(null)}))}else console.log("syncCashBookEveryDay"),e(null)}),(function(t){console.log("syncCashBookEveryDay",t)}))}))},t.prototype.get1stDayOfMonthArray=function(t,e){var n=new Array;for(e=new Date(e),(t=new Date(t)).setDate(1),t.setHours(0),t.setMinutes(0),t.setSeconds(0),t.setMilliseconds(0),t.setMonth(t.getMonth()+1),e.setDate(1),e.setHours(0),e.setMinutes(0),e.setSeconds(0),e.setMilliseconds(0),e.setMonth(e.getMonth()-1);t.getTime()<=e.getTime();)n.push(new Date(t)),t.setMonth(t.getMonth()+1);return n},t.prototype.getValidityDate=function(t){var e=this;return new Promise((function(n,o){t=new Date(t),e.vhmongo_firebase.auth().getServerDate().then((function(o){(o=new Date(o)).setMonth(o.getMonth()-1),o.setDate(1),o.setHours(0),o.setMinutes(0),o.setSeconds(0),t.getTime()>o.getTime()?t.getTime()<new Date(e.vhAuth.getStore().registrationdate).getTime()?n(new Date(e.vhAuth.getStore().registrationdate)):n(null):o.getTime()<new Date(e.vhAuth.getStore().registrationdate).getTime()?n(new Date(e.vhAuth.getStore().registrationdate)):n(o)}))}))},t.prototype.getReportIncomeExpenditureDiary=function(t,e,n,o,i,a){var s=this;return new Promise((function(r,l){var c;"all"===a||void 0===a?("all"===n&&"all"===o&&(c=s.vhmongo_firebase.database().getDocsByFields("bills",{date:{$gte:t,$lte:e},bill_type:{$in:i}},{},{date:1},0)),"all"===n&&"all"!=o&&(c=s.vhmongo_firebase.database().getDocsByFields("bills",{date:{$gte:t,$lte:e},id_employee:{$eq:o},bill_type:{$in:i}},{},{date:1},0)),"all"!=n&&"all"===o&&(c=s.vhmongo_firebase.database().getDocsByFields("bills",{date:{$gte:t,$lte:e},id_wallet:{$eq:n},bill_type:{$in:i}},{},{date:1},0)),"all"!=n&&"all"!=o&&(c=s.vhmongo_firebase.database().getDocsByFields("bills",{date:{$gte:t,$lte:e},id_wallet:{$eq:n},id_employee:{$eq:o},bill_type:{$in:i}},{},{date:1},0))):("all"===n&&"all"===o&&(c=s.vhmongo_firebase.database().getDocsByFields("bills",{date:{$gte:t,$lte:e},bill_type:{$in:i},id_branch:{$eq:a}},{},{date:1},0)),"all"===n&&"all"!=o&&(c=s.vhmongo_firebase.database().getDocsByFields("bills",{date:{$gte:t,$lte:e},id_employee:{$eq:o},bill_type:{$in:i},id_branch:{$eq:a}},{},{date:1},0)),"all"!=n&&"all"===o&&(c=s.vhmongo_firebase.database().getDocsByFields("bills",{date:{$gte:t,$lte:e},id_wallet:{$eq:n},bill_type:{$in:i},id_branch:{$eq:a}},{},{date:1},0)),"all"!=n&&"all"!=o&&(c=s.vhmongo_firebase.database().getDocsByFields("bills",{date:{$gte:t,$lte:e},id_wallet:{$eq:n},id_employee:{$eq:o},bill_type:{$in:i},id_branch:{$eq:a}},{},{date:1},0))),c.then((function(t){var e={docs:new Array,empty:!0,size:0,income:0,expenditure:0};if(t.length>0)for(var n=0;n<t.length;n++){var o=Object.assign({},t[n]);2!=(null==o?void 0:o.payment_type)&&(1!==o.bill_type&&7!==o.bill_type&&10!==o.bill_type&&11!==o.bill_type&&34!==o.bill_type||(e.income=e.income+o.payment,e.docs.push(o),e.size++,e.empty=!1),2!==o.bill_type&&8!==o.bill_type&&12!==o.bill_type&&33!==o.bill_type||(e.expenditure=e.expenditure+o.payment,e.docs.push(o),e.size++,e.empty=!1))}r(e)}))}))},t.prototype.getDebtSuppliers=function(t,e,n,o){var i=this;t=new Date(t),e=new Date(e);var a=this.vhAuth.getStore();return new Promise((function(s,r){var l=new Array;if("all"===n)l=i.vhAlgorithm.sortVietnamesebyASC(i.getlocalSuppliers(),"name");else{var c=i.getlocalSupplier(n);l.push(c)}var u,d=i.getlocalBranchs(),_=i.getDefaultBranch()._id,p=null,b=null;if(null!=l[0][_]&&null!=l[0][_].debt)for(var f=0;f<l[0][_].debt.length&&!(new Date(l[0][_].debt[f].date).getTime()>t.getTime());f++)b=new Date(l[0][_].debt[f].date),p=f;b||(b=new Date(a.registrationdate)),u="all"===n?"all"===o||void 0===o?{date:{$gte:b,$lte:e},bill_type:{$in:[2,10,12]}}:{date:{$gte:b,$lte:e},bill_type:{$in:[2,10,12]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$gte:b,$lte:e},id_supplier:{$eq:n},bill_type:{$in:[2,10,12]}}:{date:{$gte:b,$lte:e},id_supplier:{$eq:n},bill_type:{$in:[2,10,12]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("bills",u,{},{date:1},0).then((function(e){for(var n,i,a={docs:new Array,debt_beginning:0,payment:0,debt:0,rest:0},r=0;r<l.length;r++){var c={_id:l[r]._id,name:l[r].name};a.docs.push(c);for(var u=0,_=0,b=0,f=0,h=0;h<e.length;h++)e[h].id_supplier===l[r]._id&&(new Date(e[h].date).getTime()>=t.getTime()?2===e[h].bill_type?(u+=e[h].total*(1+e[h].tax/100),_+=e[h].payment):12===e[h].bill_type?_+=e[h].payment:10===e[h].bill_type&&(_+=e[h].total*(1+e[h].tax/100),u+=e[h].payment):2===e[h].bill_type?f=f+e[h].total*(1+e[h].tax/100)-e[h].payment:10===e[h].bill_type?f=f+e[h].payment-e[h].total*(1+e[h].tax/100):12===e[h].bill_type&&(f-=e[h].payment));if("all"===o||void 0===o)for(h=0;h<d.length;h++)null!=l[r][d[h]._id]&&null!=l[r][d[h]._id].debt_beginning&&(b+=l[r][d[h]._id].debt_beginning);else null!=l[r][o]&&null!=l[r][o].debt_beginning&&(b=l[r][o].debt_beginning),null!=l[r][o]&&null!=l[r][o].debt&&(p||null!=l[r][o].debt[p]&&(f+=l[r][o].debt[p].debt_first));u=b+f+u,a.docs[a.docs.length-1].index=a.docs.length,a.docs[a.docs.length-1].debt=u,a.docs[a.docs.length-1].payment=_,a.docs[a.docs.length-1].rest=u-_,a.debt_beginning=a.debt_beginning+b,a.debt=a.debt+u,a.payment=a.payment+_,a.rest=a.rest+u-_;var y={docs:new Array,empty:!0,size:0,debt_beginning:b+f,debt:b+f,payment:0,rest:b+f};for(h=0;h<e.length;h++)if(l[r]._id===e[h].id_supplier&&new Date(e[h].date).getTime()>=t.getTime()){var m=Object.assign({},e[h]);null==m||delete m.discount,null==m||delete m.fee,null==m||delete m.id_supplier,null==m||delete m.note,null==m||delete m.payment_type,null==m||delete m.tax,y.docs.push(m),y.docs[y.docs.length-1].debt=0,y.docs[y.docs.length-1].payment=0,2===e[h].bill_type?(y.docs[y.docs.length-1].debt=e[h].total*(1+(null===(n=e[h])||void 0===n?void 0:n.tax)/100),y.docs[y.docs.length-1].payment=e[h].payment,y.docs[y.docs.length-1].rest=y.docs[y.docs.length-1].debt-y.docs[y.docs.length-1].payment):10===e[h].bill_type?(y.docs[y.docs.length-1].payment=e[h].total*(1+(null===(i=e[h])||void 0===i?void 0:i.tax)/100),y.docs[y.docs.length-1].debt=e[h].payment,y.docs[y.docs.length-1].rest=y.docs[y.docs.length-1].debt-y.docs[y.docs.length-1].payment):12===e[h].bill_type&&(y.docs[y.docs.length-1].payment=e[h].payment,y.docs[y.docs.length-1].rest=-e[h].payment),y.debt=y.debt+y.docs[y.docs.length-1].debt,y.payment=y.payment+y.docs[y.docs.length-1].payment,y.rest=y.rest+y.docs[y.docs.length-1].debt-y.docs[y.docs.length-1].payment,y.size++,y.empty=!1,y.docs[y.docs.length-1].index=y.docs.length}a.docs[a.docs.length-1].json=y}console.log("json",a),s(a)}))}))},t.prototype.getDebtCustomers=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=i.vhAuth.getStore(),l=new Array;if("all"===n)l=i.vhAlgorithm.sortVietnamesebyASC(i.getlocalCustomers().filter((function(t){return"id_retail"!=t._id})),"name");else{var c=i.getlocalCustomer(n);l.push(c)}var u,d=i.getlocalBranchs(),_=i.getDefaultBranch()._id,p=null,b=null;if(null!=l[0][_]&&null!=l[0][_].debt)for(var f=0;f<l[0][_].debt.length&&!(new Date(l[0][_].debt[f].date).getTime()>t.getTime());f++)b=new Date(l[0][_].debt[f].date),p=f;b||(b=new Date(r.registrationdate)),u="all"===n?"all"===o||void 0===o?{date:{$gte:b,$lte:e},bill_type:{$in:[1,11]}}:{date:{$gte:b,$lte:e},bill_type:{$in:[1,11]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$gte:b,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1,11]}}:{date:{$gte:b,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1,11]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("bills",u,{},{date:1},0).then((function(e){for(var n,i={docs:new Array,debt_beginning:0,payment:0,debt:0,rest:0},s=0;s<l.length;s++){var r={_id:l[s]._id,name:l[s].name};i.docs.push(r);for(var c=0,u=0,_=0,b=0,f=0;f<e.length;f++)e[f].id_customer===l[s]._id&&(new Date(e[f].date).getTime()>=t.getTime()?1===e[f].bill_type?(c+=e[f].total*(1+e[f].tax/100),u+=e[f].payment):11===e[f].bill_type&&(u+=e[f].payment):1===e[f].bill_type?b=b+e[f].total*(1+e[f].tax/100)-e[f].payment:11===e[f].bill_type&&(b-=e[f].payment));if("all"===o||void 0===o)for(f=0;f<d.length;f++)null!=l[s][d[f]._id]&&null!=l[s][d[f]._id].debt_beginning&&(_+=l[s][d[f]._id].debt_beginning);else null!=l[s][o]&&null!=l[s][o].debt_beginning&&(_=l[s][o].debt_beginning),null!=l[s][o]&&null!=l[s][o].debt&&(p||null!=l[s][o].debt[p]&&(b+=l[s][o].debt[p].debt_first));c=_+b+c,i.docs[i.docs.length-1].index=i.docs.length,i.docs[i.docs.length-1].debt=c,i.docs[i.docs.length-1].payment=u,i.docs[i.docs.length-1].rest=c-u,i.debt_beginning=i.debt_beginning+_,i.debt=i.debt+c,i.payment=i.payment+u,i.rest=i.rest+c-u;var h={docs:new Array,empty:!0,size:0,debt_beginning:_+b,debt:_+b,payment:0,rest:_+b};for(f=0;f<e.length;f++)if(l[s]._id===e[f].id_customer&&new Date(e[f].date).getTime()>=t.getTime()){var y=Object.assign({},e[f]);null==y||delete y.discount,null==y||delete y.fee,null==y||delete y.id_customer,null==y||delete y.note,null==y||delete y.payment_type,null==y||delete y.tax,h.docs.push(y),h.docs[h.docs.length-1].debt=0,h.docs[h.docs.length-1].payment=0,1===e[f].bill_type?(h.docs[h.docs.length-1].debt=e[f].total*(1+(null===(n=e[f])||void 0===n?void 0:n.tax)/100),h.docs[h.docs.length-1].payment=e[f].payment,h.docs[h.docs.length-1].rest=h.docs[h.docs.length-1].debt-h.docs[h.docs.length-1].payment):11===e[f].bill_type&&(h.docs[h.docs.length-1].payment=e[f].payment,h.docs[h.docs.length-1].rest=-e[f].payment),h.debt=h.debt+h.docs[h.docs.length-1].debt,h.payment=h.payment+h.docs[h.docs.length-1].payment,h.rest=h.rest+h.docs[h.docs.length-1].debt-h.docs[h.docs.length-1].payment,h.size++,h.empty=!1,h.docs[h.docs.length-1].index=h.docs.length}i.docs[i.docs.length-1].json=h}console.log("json",i),a(i)}))}))},t.prototype.getReportSales_Categorys_byCategorys=function(t,e,n,o,i){var a=this;return console.log("type",o),o="all"===n?1234:this.getlocalCategory(n).type,console.log("_type",o),new Promise((function(s,r){var l,c,u,d=new Array;1===o?(u=1,c=[1,5]):2===o?(u=2,c=[2,5]):3===o?(u=3,c=[3,5]):4===o?(u=4,c=[4,1,5]):5===o?(u=5,c=[5]):1234===o&&(u=1234,c=[1,2,3,4,5]),"all"===n?(d=a.getlocalCategorys(u),l="all"===i||void 0===i?{date:{$gte:t,$lte:e},ptype:{$in:c},bill_type:{$eq:1}}:{date:{$gte:t,$lte:e},ptype:{$in:c},bill_type:{$eq:1},id_branch:{$eq:i}}):(d.push(a.getlocalCategory(n)),l="all"===i||void 0===i?{date:{$gte:t,$lte:e},ptype:{$in:c},bill_type:{$eq:1}}:{date:{$gte:t,$lte:e},ptype:{$in:c},bill_type:{$eq:1},id_branch:{$eq:i}});var _={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};d.length>0?a.vhmongo_firebase.database().getDocsByFields("vhbill_details",l,{},{date:1},0).then((function(t){if(t.length>0)for(var e=0;e<d.length;e++){for(var n=!1,i=Object.assign({},d[e]),a={id_category:i._id,name:i.name,sales_btax:0,sales_atax:0,quantity:0},r=0;r<t.length;r++)if(1===o||2===o||3===o){if(5===t[r].ptype){if(null!=t[r].combos)for(var l=0;l<t[r].combos.length;l++)d[e]._id===t[r].combos[l].id_category&&(a.quantity=a.quantity+t[r].combos[l].quantity*t[r].quantity,a.sales_btax=a.sales_btax+t[r].combos[l].price*t[r].combos[l].quantity*t[r].quantity,a.sales_atax=a.sales_atax+t[r].combos[l].price*t[r].combos[l].quantity*t[r].quantity*(1+t[r].tax/100))}else if(d[e]._id===t[r].id_category&&(n=!0,a.quantity=a.quantity+t[r].quantity,a.sales_btax=a.sales_btax+t[r].price*t[r].quantity,a.sales_atax=a.sales_atax+t[r].price*t[r].quantity*(1+t[r].tax/100),null!=t[r].toppings))for(l=0;l<t[r].toppings.length;l++)a.quantity=a.quantity+t[r].toppings[l].quantity,a.sales_btax=a.sales_btax+t[r].toppings[l].price*t[r].toppings[l].quantity,a.sales_atax=a.sales_atax+t[r].toppings[l].price*t[r].toppings[l].quantity*(1+t[r].tax/100)}else if(4===o){if(5===t[r].ptype){if(null!=t[r].combos)for(l=0;l<t[r].combos.length;l++)d[e]._id===t[r].combos[l].id_category&&(a.quantity=a.quantity+t[r].combos[l].quantity*t[r].quantity,a.sales_btax=a.sales_btax+t[r].combos[l].price*t[r].combos[l].quantity*t[r].quantity,a.sales_atax=a.sales_atax+t[r].combos[l].price*t[r].combos[l].quantity*t[r].quantity*(1+t[r].tax/100))}else if(4===t[r].ptype)d[e]._id===t[r].id_category&&(n=!0,a.quantity=a.quantity+t[r].quantity,a.sales_btax=a.sales_btax+t[r].price*t[r].quantity,a.sales_atax=a.sales_atax+t[r].price*t[r].quantity*(1+t[r].tax/100));else if(1===t[r].ptype&&null!=t[r].toppings)for(l=0;l<t[r].toppings.length;l++)d[e]._id===t[r].toppings[l].id_category&&(n=!0,a.quantity=a.quantity+t[r].toppings[l].quantity,a.sales_btax=a.sales_btax+t[r].toppings[l].price*t[r].toppings[l].quantity,a.sales_atax=a.sales_atax+t[r].toppings[l].price*t[r].toppings[l].quantity*(1+t[r].tax/100))}else if(5===o){if(5===t[r].ptype&&null!=t[r].combos)for(l=0;l<t[r].combos.length;l++)d[e]._id===t[r].combos[l].id_category&&(a.quantity=a.quantity+t[r].combos[l].quantity*t[r].quantity,a.sales_btax=a.sales_btax+t[r].combos[l].price*t[r].combos[l].quantity*t[r].quantity,a.sales_atax=a.sales_atax+t[r].combos[l].price*t[r].combos[l].quantity*t[r].quantity*(1+t[r].tax/100))}else if(1234===o)if(1===t[r].ptype){if(1===d[e].type&&d[e]._id===t[r].id_category&&(n=!0,a.quantity=a.quantity+t[r].quantity,a.sales_btax=a.sales_btax+t[r].price*t[r].quantity,a.sales_atax=a.sales_atax+t[r].price*t[r].quantity*(1+t[r].tax/100)),4===d[e].type&&null!=t[r].toppings)for(l=0;l<t[r].toppings.length;l++)d[e]._id===t[r].toppings[l].id_category&&(n=!0,a.quantity=a.quantity+t[r].toppings[l].quantity,a.sales_btax=a.sales_btax+t[r].toppings[l].price*t[r].toppings[l].quantity,a.sales_atax=a.sales_atax+t[r].toppings[l].price*t[r].toppings[l].quantity*(1+t[r].tax/100))}else if(2===t[r].ptype)d[e]._id===t[r].id_category&&(n=!0,a.quantity=a.quantity+t[r].quantity,a.sales_btax=a.sales_btax+t[r].price*t[r].quantity,a.sales_atax=a.sales_atax+t[r].price*t[r].quantity*(1+t[r].tax/100));else if(3===t[r].ptype)d[e]._id===t[r].id_category&&(n=!0,a.quantity=a.quantity+t[r].quantity,a.sales_btax=a.sales_btax+t[r].price*t[r].quantity,a.sales_atax=a.sales_atax+t[r].price*t[r].quantity*(1+t[r].tax/100));else if(4===t[r].ptype)d[e]._id===t[r].id_category&&(n=!0,a.quantity=a.quantity+t[r].quantity,a.sales_btax=a.sales_btax+t[r].price*t[r].quantity,a.sales_atax=a.sales_atax+t[r].price*t[r].quantity*(1+t[r].tax/100));else if(5===t[r].ptype)for(l=0;l<t[r].combos.length;l++)d[e]._id===t[r].combos[l].id_category&&(n=!0,a.quantity=a.quantity+t[r].combos[l].quantity*t[r].quantity,a.sales_btax=a.sales_btax+t[r].combos[l].price*t[r].combos[l].quantity*t[r].quantity,a.sales_atax=a.sales_atax+t[r].combos[l].price*t[r].combos[l].quantity*t[r].quantity*(1+t[r].tax/100));n&&(a.sales_atax=Math.round(1e6*a.sales_atax)/1e6,null!=a.subs&&a.subs.forEach((function(t){t.sales_atax=Math.round(1e6*t.sales_atax)/1e6})),null!=a.combos&&a.combos.forEach((function(t){t.sales_atax=Math.round(1e6*t.sales_atax)/1e6})),_.quantity=_.quantity+a.quantity,_.sales_btax=_.sales_btax+a.sales_btax,_.sales_atax=_.sales_atax+a.sales_atax,a.index=_.size+1,_.docs.push(a),_.size++,_.empty=!1)}console.log("getReportSales_Categorys_byCategorys"),s(_)})):s(_)}))},t.prototype.getReportSales_Categorys_byProducts=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l,c=i.getlocalProducts().filter((function(t){if(t.id_category===n)return!0})),u=i.getlocalCategory(n).type;1===u?r=[1,5]:2===u?r=[2,5]:3===u?r=[3,5]:4===u?r=[4,1,5]:5===u&&(r=[5]),l="all"===o||void 0===o?{date:{$gte:t,$lte:e},ptype:{$in:r},bill_type:{$eq:1}}:{date:{$gte:t,$lte:e},ptype:{$in:r},bill_type:{$eq:1},id_branch:{$eq:o}};var d={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};c.length>0?i.vhmongo_firebase.database().getDocsByFields("vhbill_details",l,{},{date:1},0).then((function(t){var e,n;if(t.length>0)for(var o=0;o<c.length;o++){var i=!1,s=Object.assign({},c[o]),r={id_product:s._id,name:s.name,unit:s.unit,barcode:s.barcode,img:s.img,sales_btax:0,sales_atax:0,quantity:0};if(null!=s.subs){r.subs=new Array;for(var l=0;l<s.subs.length;l++){var _={id_subproduct:s.subs[l]._id,name:null===(e=s.subs[l])||void 0===e?void 0:e.name,sales_btax:0,sales_atax:0,quantity:0};r.subs.push(_)}}if(null!=s.combos){r.combos=new Array;for(l=0;l<s.combos.length;l++){var p={id_product:s.combos[l].id_product,name:null===(n=s.combos[l])||void 0===n?void 0:n.name,sales_btax:0,sales_atax:0,quantity:0};null!=s.combos[l].id_subproduct&&(p.id_subproduct=s.combos[l].id_subproduct),r.combos.push(p)}}for(var b=0;b<t.length;b++)if(1===u){if(1===t[b].ptype){if(c[o]._id===t[b].id_product&&(i=!0,r.quantity=r.quantity+t[b].quantity,r.sales_btax=r.sales_btax+t[b].price*t[b].quantity,r.sales_atax=r.sales_atax+t[b].price*t[b].quantity*(1+t[b].tax/100),null!=r.subs))for(l=0;l<r.subs.length;l++)if(c[o].subs[l]._id===t[b].id_subproduct){r.subs[l].quantity=r.subs[l].quantity+t[b].quantity,r.subs[l].sales_btax=r.subs[l].sales_btax+t[b].price*t[b].quantity,r.subs[l].sales_atax=r.subs[l].sales_atax+t[b].price*t[b].quantity*(1+t[b].tax/100);break}}else if(5===t[b].ptype)for(var f=0;f<t[b].combos.length;f++)if(c[o]._id===t[b].combos[f].id_product&&(i=!0,r.quantity=r.quantity+t[b].combos[f].quantity*t[b].quantity,r.sales_btax=r.sales_btax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity,r.sales_atax=r.sales_atax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity*(1+t[b].tax/100),null!=r.subs))for(l=0;l<r.subs.length;l++)if(c[o].subs[l]._id===t[b].combos[f].id_subproduct){r.subs[l].quantity=r.subs[l].quantity+t[b].combos[f].quantity*t[b].quantity,r.subs[l].sales_btax=r.subs[l].sales_btax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity,r.subs[l].sales_atax=r.subs[l].sales_atax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity*(1+t[b].tax/100);break}}else if(2===u){if(2===t[b].ptype)c[o]._id===t[b].id_product&&(i=!0,r.quantity=r.quantity+t[b].quantity,r.sales_btax=r.sales_btax+t[b].price*t[b].quantity,r.sales_atax=r.sales_atax+t[b].price*t[b].quantity*(1+t[b].tax/100));else if(5===t[b].ptype)for(f=0;f<t[b].combos.length;f++)c[o]._id===t[b].combos[f].id_product&&(i=!0,r.quantity=r.quantity+t[b].combos[f].quantity*t[b].quantity,r.sales_btax=r.sales_btax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity,r.sales_atax=r.sales_atax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity*(1+t[b].tax/100))}else if(3===u){if(3===t[b].ptype)c[o]._id===t[b].id_product&&(i=!0,r.quantity=r.quantity+t[b].quantity,r.sales_btax=r.sales_btax+t[b].price*t[b].quantity,r.sales_atax=r.sales_atax+t[b].price*t[b].quantity*(1+t[b].tax/100));else if(5===t[b].ptype)for(f=0;f<t[b].combos.length;f++)c[o]._id===t[b].combos[f].id_product&&(i=!0,r.quantity=r.quantity+t[b].combos[f].quantity*t[b].quantity,r.sales_btax=r.sales_btax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity,r.sales_atax=r.sales_atax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity*(1+t[b].tax/100))}else if(4===u){if(4===t[b].ptype)c[o]._id===t[b].id_product&&(i=!0,r.quantity=r.quantity+t[b].quantity,r.sales_btax=r.sales_btax+t[b].price*t[b].quantity,r.sales_atax=r.sales_atax+t[b].price*t[b].quantity*(1+t[b].tax/100));else if(1===t[b].ptype){if(null!=t[b].toppings)for(f=0;f<t[b].toppings.length;f++)c[o]._id===t[b].toppings[f].id_product&&(i=!0,r.quantity=r.quantity+t[b].toppings[f].quantity,r.sales_btax=r.sales_btax+t[b].toppings[f].price*t[b].toppings[f].quantity,r.sales_atax=r.sales_atax+t[b].toppings[f].price*t[b].toppings[f].quantity*(1+t[b].tax/100))}else if(5===t[b].ptype)for(f=0;f<t[b].combos.length;f++)c[o]._id===t[b].combos[f].id_product&&(i=!0,r.quantity=r.quantity+t[b].combos[f].quantity*t[b].quantity,r.sales_btax=r.sales_btax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity,r.sales_atax=r.sales_atax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity*(1+t[b].tax/100))}else if(5===u&&5===t[b].ptype&&c[o]._id===t[b].id_product&&(i=!0,r.quantity=r.quantity+t[b].quantity,r.sales_btax=r.sales_btax+t[b].price*t[b].quantity,r.sales_atax=r.sales_atax+t[b].price*t[b].quantity*(1+t[b].tax/100),null!=r.combos))for(l=0;l<r.combos.length;l++)c[o].combos[l].id_product===t[b].combos[l].id_product&&(r.combos[l].quantity=r.combos[l].quantity+t[b].combos[l].quantity*t[b].quantity,r.combos[l].sales_btax=r.combos[l].sales_btax+t[b].combos[l].price*t[b].combos[l].quantity*t[b].quantity,r.combos[l].sales_atax=r.combos[l].sales_atax+t[b].combos[l].price*t[b].combos[l].quantity*t[b].quantity*(1+t[b].tax/100));i&&(r.sales_atax=Math.round(1e6*r.sales_atax)/1e6,null!=r.subs&&r.subs.forEach((function(t){t.sales_atax=Math.round(1e6*t.sales_atax)/1e6})),null!=r.combos&&r.combos.forEach((function(t){t.sales_atax=Math.round(1e6*t.sales_atax)/1e6})),d.quantity=d.quantity+r.quantity,d.sales_btax=d.sales_btax+r.sales_btax,d.sales_atax=d.sales_atax+r.sales_atax,r.index=d.size+1,d.docs.push(r),d.size++,d.empty=!1)}console.log("jsons",d),a(d)})):a(d)}))},t.prototype.getReportSales_Categorys_byProduct=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=i.getlocalProduct(n),l=new Array;i.getlocalProductAndCombosAndToppings(n).forEach((function(t){l.push(t._id)}));var c,u=r.type,d={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};c="all"===o||void 0===o?{date:{$gte:t,$lte:e},id_product:{$in:l},bill_type:{$eq:1}}:{date:{$gte:t,$lte:e},id_product:{$in:l},bill_type:{$eq:1},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("vhbill_details",c,{},{date:1},0).then((function(t){var e;if(t.length>0)for(var n=0;n<t.length;n++){var o=new Array;if(o[0]={id_product:r._id,name:r.name,unit:r.unit,barcode:r.barcode,img:r.img,bill_code:t[n].bill_code,bill_type:t[n].bill_type,id_bill:t[n].id_bill,date:t[n].date,tax:t[n].tax,salesman:null===(e=i.vhAuth.getlocalEmployee(t[n].id_employee))||void 0===e?void 0:e.name,customer:i.getlocalCustomer(t[n].id_customer).name},1===u){if(null!=t[n].combos){for(var s=0,l=Object.assign({},o[0]),c=0;c<t[n].combos.length;c++)if(t[n].combos[c].id_product===r._id)if(null!=r.subs)for(var _=0;_<r.subs.length;_++)t[n].combos[c].id_subproduct===r.subs[_]._id&&(0==s?(o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price,o[0].id_subproduct=r.subs[_]._id,o[0].name=o[0].name+"("+r.subs[_].name+")"):(o[s]=Object.assign({},l),o[s].quantity=t[n].combos[c].quantity*t[n].quantity,o[s].price=t[n].combos[c].price,o[s].id_subproduct=r.subs[_]._id,o[s].name=o[s].name+"("+r.subs[_].name+")"),s++);else o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price}else if(o[0].quantity=t[n].quantity,o[0].price=t[n].price,null!=r.subs)for(_=0;_<r.subs.length;_++)if(t[n].id_subproduct===r.subs[_]._id){o[0].id_subproduct=r.subs[_]._id,o[0].name=o[0].name+"("+r.subs[_].name+")";break}}else if(2===u||3===u)if(null!=t[n].combos){for(c=0;c<t[n].combos.length;c++)if(t[n].combos[c].id_product===r._id){o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price;break}}else o[0].quantity=t[n].quantity,o[0].price=t[n].price;else if(4===u)if(null!=t[n].toppings){for(c=0;c<t[n].toppings.length;c++)if(t[n].toppings[c].id_product===r._id){o[0].quantity=t[n].toppings[c].quantity,o[0].price=t[n].toppings[c].price;break}}else o[0].quantity=t[n].quantity,o[0].price=t[n].price;else 5===u&&(o[0].quantity=t[n].quantity,o[0].price=t[n].price);o.forEach((function(t){t.sales_btax=t.price*t.quantity,t.sales_atax=t.price*t.quantity*(1+t.tax/100),t.index=d.size+1,d.docs.push(t),d.size++,d.empty=!1,d.quantity=d.quantity+t.quantity,d.sales_btax=d.sales_btax+t.price*t.quantity,d.sales_atax=d.sales_atax+t.price*t.quantity*(1+Number(t.tax)/100)}))}console.log("json",d),a(d)}))}))},t.prototype.getReportSales_Areas_byAreas=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Array;if("all"===n)r=i.getlocalAreas();else{var l=i.getlocalArea(n);r.push(l)}var c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};if(r.length>0){var u=void 0;u="all"===n?"all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$gte:t,$lte:e},id_area:{$eq:n},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},id_area:{$eq:n},bill_type:{$in:[1]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0).then((function(t){if(t.length>0)for(var e=0;e<r.length;e++){for(var n=!1,o={id_area:r[e]._id,name:r[e].name,sales_btax:0,sales_atax:0,quantity:0},i=0;i<t.length;i++)if(r[e]._id===t[i].id_area)if(5===t[i].ptype){if(null!=t[i].combos)for(var s=0;s<t[i].combos.length;s++)o.quantity=o.quantity+t[i].combos[s].quantity*t[i].quantity,o.sales_btax=o.sales_btax+t[i].combos[s].price*t[i].combos[s].quantity*t[i].quantity,o.sales_atax=o.sales_atax+t[i].combos[s].price*t[i].combos[s].quantity*t[i].quantity*(1+t[i].tax/100)}else if(n=!0,o.quantity=o.quantity+t[i].quantity,o.sales_btax=o.sales_btax+t[i].price*t[i].quantity,o.sales_atax=o.sales_atax+t[i].price*t[i].quantity*(1+t[i].tax/100),null!=t[i].toppings)for(s=0;s<t[i].toppings.length;s++)o.quantity=o.quantity+t[i].toppings[s].quantity,o.sales_btax=o.sales_btax+t[i].toppings[s].price*t[i].toppings[s].quantity,o.sales_atax=o.sales_atax+t[i].toppings[s].price*t[i].toppings[s].quantity*(1+t[i].tax/100);n&&(c.quantity=c.quantity+o.quantity,c.sales_btax=c.sales_btax+o.sales_btax,c.sales_atax=c.sales_atax+o.sales_atax,o.index=c.size+1,c.docs.push(o),c.size++,c.empty=!1)}a(c)}))}else a(c)}))},t.prototype.getReportSales_Areas_byProducts=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l=i.getlocalProducts(1234);r=r="all"===o||void 0===o?{date:{$gte:t,$lte:e},id_area:{$eq:n},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},id_area:{$eq:n},bill_type:{$in:[1]},id_branch:{$eq:o}};var c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};l.length>0?i.vhmongo_firebase.database().getDocsByFields("vhbill_details",r,{},{date:1},0).then((function(t){var e;if(t.length>0)for(var n=0;n<l.length;n++){var o=!1,i=Object.assign({},l[n]),s={id_product:i._id,name:i.name,unit:i.unit,barcode:i.barcode,img:i.img,sales_btax:0,sales_atax:0,quantity:0,subs:new Array};if(null!=i.subs)for(var r=0;r<i.subs.length;r++){var u={id_subproduct:i.subs[r]._id,name:null===(e=i.subs[r])||void 0===e?void 0:e.name,sales_btax:0,sales_atax:0,quantity:0};s.subs.push(u)}for(var d=0;d<t.length;d++)if(1===t[d].ptype){if(1===l[n].type&&l[n]._id===t[d].id_product&&(o=!0,s.quantity=s.quantity+t[d].quantity,s.sales_btax=s.sales_btax+t[d].price*t[d].quantity,s.sales_atax=s.sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100),null!=s.subs))for(r=0;r<s.subs.length;r++)if(l[n].subs[r]._id===t[d].id_subproduct){s.subs[r].quantity=s.subs[r].quantity+t[d].quantity,s.subs[r].sales_btax=s.subs[r].sales_btax+t[d].price*t[d].quantity,s.subs[r].sales_atax=s.subs[r].sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100);break}if(4===l[n].type&&null!=t[d].toppings)for(var _=0;_<t[d].toppings.length;_++)l[n]._id===t[d].toppings[_].id_product&&(o=!0,s.quantity=s.quantity+t[d].toppings[_].quantity,s.sales_btax=s.sales_btax+t[d].toppings[_].price*t[d].toppings[_].quantity,s.sales_atax=s.sales_atax+t[d].toppings[_].price*t[d].toppings[_].quantity*(1+t[d].tax/100))}else if(2===t[d].ptype)l[n]._id===t[d].id_product&&(o=!0,s.quantity=s.quantity+t[d].quantity,s.sales_btax=s.sales_btax+t[d].price*t[d].quantity,s.sales_atax=s.sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100));else if(3===t[d].ptype)l[n]._id===t[d].id_product&&(o=!0,s.quantity=s.quantity+t[d].quantity,s.sales_btax=s.sales_btax+t[d].price*t[d].quantity,s.sales_atax=s.sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100));else if(4===t[d].ptype)l[n]._id===t[d].id_product&&(o=!0,s.quantity=s.quantity+t[d].quantity,s.sales_btax=s.sales_btax+t[d].price*t[d].quantity,s.sales_atax=s.sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100));else if(5===t[d].ptype)for(_=0;_<t[d].combos.length;_++)if(l[n]._id===t[d].combos[_].id_product&&(o=!0,s.quantity=s.quantity+t[d].combos[_].quantity*t[d].quantity,s.sales_btax=s.sales_btax+t[d].combos[_].price*t[d].combos[_].quantity*t[d].quantity,s.sales_atax=s.sales_atax+t[d].combos[_].price*t[d].combos[_].quantity*t[d].quantity*(1+t[d].tax/100),null!=s.subs))for(r=0;r<s.subs.length;r++)if(l[n].subs[r]._id===t[d].combos[_].id_subproduct){s.subs[r].quantity=s.subs[r].quantity+t[d].combos[_].quantity*t[d].quantity,s.subs[r].sales_btax=s.subs[r].sales_btax+t[d].combos[_].price*t[d].combos[_].quantity*t[d].quantity,s.subs[r].sales_atax=s.subs[r].sales_atax+t[d].combos[_].price*t[d].combos[_].quantity*t[d].quantity*(1+t[d].tax/100);break}o&&(s.sales_atax=Math.round(1e6*s.sales_atax)/1e6,null!=s.subs&&s.subs.forEach((function(t){t.sales_atax=Math.round(1e6*t.sales_atax)/1e6})),c.quantity=c.quantity+s.quantity,c.sales_btax=c.sales_btax+s.sales_btax,c.sales_atax=c.sales_atax+s.sales_atax,s.index=c.size+1,c.docs.push(s),c.size++,c.empty=!1)}console.log("getReportSales_Areas_byProducts"),a(c)})):a(c)}))},t.prototype.getReportSales_Areas_byProduct=function(t,e,n,o,i){var a=this;return new Promise((function(s,r){var l=a.getlocalProduct(o),c=new Array;a.getlocalProductAndCombosAndToppings(o).forEach((function(t){c.push(t._id)}));var u,d=l.type,_={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};u="all"===i||void 0===i?{date:{$gte:t,$lte:e},id_area:{$eq:n},id_product:{$in:c},bill_type:{$eq:1}}:{date:{$gte:t,$lte:e},id_area:{$eq:n},id_product:{$in:c},bill_type:{$eq:1},id_branch:{$eq:i}},a.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0).then((function(t){var e;if(t.length>0)for(var n=0;n<t.length;n++){var o=new Array;if(o[0]={id_product:l._id,name:l.name,unit:l.unit,barcode:l.barcode,img:l.img,bill_code:t[n].bill_code,bill_type:t[n].bill_type,id_bill:t[n].id_bill,date:t[n].date,tax:t[n].tax,salesman:null===(e=a.vhAuth.getlocalEmployee(t[n].id_employee))||void 0===e?void 0:e.name,customer:a.getlocalCustomer(t[n].id_customer).name},1===d){if(null!=t[n].combos){for(var i=0,r=Object.assign({},o[0]),c=0;c<t[n].combos.length;c++)if(t[n].combos[c].id_product===l._id)if(null!=l.subs)for(var u=0;u<l.subs.length;u++)t[n].combos[c].id_subproduct===l.subs[u]._id&&(0==i?(o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price,o[0].id_subproduct=l.subs[u]._id,o[0].name=o[0].name+"("+l.subs[u].name+")"):(o[i]=Object.assign({},r),o[i].quantity=t[n].combos[c].quantity*t[n].quantity,o[i].price=t[n].combos[c].price,o[i].id_subproduct=l.subs[u]._id,o[i].name=o[i].name+"("+l.subs[u].name+")"),i++);else o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price}else if(o[0].quantity=t[n].quantity,o[0].price=t[n].price,null!=l.subs)for(u=0;u<l.subs.length;u++)if(t[n].id_subproduct===l.subs[u]._id){o[0].id_subproduct=l.subs[u]._id,o[0].name=o[0].name+"("+l.subs[u].name+")";break}}else if(2===d||3===d)if(null!=t[n].combos){for(c=0;c<t[n].combos.length;c++)if(t[n].combos[c].id_product===l._id){o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price;break}}else o[0].quantity=t[n].quantity,o[0].price=t[n].price;else if(4===d)if(null!=t[n].toppings){for(c=0;c<t[n].toppings.length;c++)if(t[n].toppings[c].id_product===l._id){o[0].quantity=t[n].toppings[c].quantity,o[0].price=t[n].toppings[c].price;break}}else o[0].quantity=t[n].quantity,o[0].price=t[n].price;else 5===d&&(o[0].quantity=t[n].quantity,o[0].price=t[n].price);o.forEach((function(t){t.sales_btax=t.price*t.quantity,t.sales_atax=t.price*t.quantity*(1+t.tax/100),t.index=_.size+1,_.docs.push(t),_.size++,_.empty=!1,_.quantity=_.quantity+t.quantity,_.sales_btax=_.sales_btax+t.price*t.quantity,_.sales_atax=_.sales_atax+t.price*t.quantity*(1+Number(t.tax)/100)}))}console.log("getReportSales_Areas_byProduct"),s(_)}))}))},t.prototype.getReportSales_Products_byProducts=function(t,e,n,o,i){var a=this;return console.log("type",o),new Promise((function(s,r){var l,c,u,d=new Array;if(1===o?(u=1,c=[1,5]):2===o?(u=2,c=[2,5]):3===o?(u=3,c=[3,5]):4===o?(u=4,c=[4,1,5]):5===o?(u=5,c=[5]):1234===o&&(u=1234,c=[1,2,3,4,5]),"all"===n)d=a.getlocalProducts(u),l="all"===i||void 0===i?{date:{$gte:t,$lte:e},ptype:{$in:c},bill_type:{$eq:1}}:{date:{$gte:t,$lte:e},ptype:{$in:c},bill_type:{$eq:1},id_branch:{$eq:i}};else{d.push(a.getlocalProduct(n));var _=new Array;a.getlocalProductAndCombosAndToppings(n).forEach((function(t){_.push(t._id)})),l="all"===i||void 0===i?{date:{$gte:t,$lte:e},id_product:{$in:_},bill_type:{$eq:1}}:{date:{$gte:t,$lte:e},id_product:{$in:_},bill_type:{$eq:1},id_branch:{$eq:i}}}var p={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};d.length>0?a.vhmongo_firebase.database().getDocsByFields("vhbill_details",l,{},{date:1},0).then((function(t){var e,n;if(t.length>0)for(var i=0;i<d.length;i++){var a=!1,r=Object.assign({},d[i]),l={id_product:r._id,name:r.name,unit:r.unit,barcode:r.barcode,img:r.img,sales_btax:0,sales_atax:0,quantity:0};if(null!=r.subs){l.subs=new Array;for(var c=0;c<r.subs.length;c++){var u={id_subproduct:r.subs[c]._id,name:null===(e=r.subs[c])||void 0===e?void 0:e.name,sales_btax:0,sales_atax:0,quantity:0};l.subs.push(u)}}if(null!=r.combos){l.combos=new Array;for(c=0;c<r.combos.length;c++){var _={id_product:r.combos[c].id_product,name:null===(n=r.combos[c])||void 0===n?void 0:n.name,sales_btax:0,sales_atax:0,quantity:0};null!=r.combos[c].id_subproduct&&(_.id_subproduct=r.combos[c].id_subproduct),l.combos.push(_)}}for(var b=0;b<t.length;b++)if(1===o){if(1===t[b].ptype){if(d[i]._id===t[b].id_product&&(a=!0,l.quantity=l.quantity+t[b].quantity,l.sales_btax=l.sales_btax+t[b].price*t[b].quantity,l.sales_atax=l.sales_atax+t[b].price*t[b].quantity*(1+t[b].tax/100),null!=l.subs))for(c=0;c<l.subs.length;c++)if(d[i].subs[c]._id===t[b].id_subproduct){l.subs[c].quantity=l.subs[c].quantity+t[b].quantity,l.subs[c].sales_btax=l.subs[c].sales_btax+t[b].price*t[b].quantity,l.subs[c].sales_atax=l.subs[c].sales_atax+t[b].price*t[b].quantity*(1+t[b].tax/100);break}}else if(5===t[b].ptype)for(var f=0;f<t[b].combos.length;f++)if(d[i]._id===t[b].combos[f].id_product&&(a=!0,l.quantity=l.quantity+t[b].combos[f].quantity*t[b].quantity,l.sales_btax=l.sales_btax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity,l.sales_atax=l.sales_atax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity*(1+t[b].tax/100),null!=l.subs))for(c=0;c<l.subs.length;c++)if(d[i].subs[c]._id===t[b].combos[f].id_subproduct){l.subs[c].quantity=l.subs[c].quantity+t[b].combos[f].quantity*t[b].quantity,l.subs[c].sales_btax=l.subs[c].sales_btax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity,l.subs[c].sales_atax=l.subs[c].sales_atax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity*(1+t[b].tax/100);break}}else if(2===o){if(2===t[b].ptype)d[i]._id===t[b].id_product&&(a=!0,l.quantity=l.quantity+t[b].quantity,l.sales_btax=l.sales_btax+t[b].price*t[b].quantity,l.sales_atax=l.sales_atax+t[b].price*t[b].quantity*(1+t[b].tax/100));else if(5===t[b].ptype)for(f=0;f<t[b].combos.length;f++)d[i]._id===t[b].combos[f].id_product&&(a=!0,l.quantity=l.quantity+t[b].combos[f].quantity*t[b].quantity,l.sales_btax=l.sales_btax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity,l.sales_atax=l.sales_atax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity*(1+t[b].tax/100))}else if(3===o){if(3===t[b].ptype)d[i]._id===t[b].id_product&&(a=!0,l.quantity=l.quantity+t[b].quantity,l.sales_btax=l.sales_btax+t[b].price*t[b].quantity,l.sales_atax=l.sales_atax+t[b].price*t[b].quantity*(1+t[b].tax/100));else if(5===t[b].ptype)for(f=0;f<t[b].combos.length;f++)d[i]._id===t[b].combos[f].id_product&&(a=!0,l.quantity=l.quantity+t[b].combos[f].quantity*t[b].quantity,l.sales_btax=l.sales_btax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity,l.sales_atax=l.sales_atax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity*(1+t[b].tax/100))}else if(4===o){if(4===t[b].ptype)d[i]._id===t[b].id_product&&(a=!0,l.quantity=l.quantity+t[b].quantity,l.sales_btax=l.sales_btax+t[b].price*t[b].quantity,l.sales_atax=l.sales_atax+t[b].price*t[b].quantity*(1+t[b].tax/100));else if(1===t[b].ptype){if(null!=t[b].toppings)for(f=0;f<t[b].toppings.length;f++)d[i]._id===t[b].toppings[f].id_product&&(a=!0,l.quantity=l.quantity+t[b].toppings[f].quantity,l.sales_btax=l.sales_btax+t[b].toppings[f].price*t[b].toppings[f].quantity,l.sales_atax=l.sales_atax+t[b].toppings[f].price*t[b].toppings[f].quantity*(1+t[b].tax/100))}else if(5===t[b].ptype)for(f=0;f<t[b].combos.length;f++)d[i]._id===t[b].combos[f].id_product&&(a=!0,l.quantity=l.quantity+t[b].combos[f].quantity*t[b].quantity,l.sales_btax=l.sales_btax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity,l.sales_atax=l.sales_atax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity*(1+t[b].tax/100))}else if(5===o){if(5===t[b].ptype&&d[i]._id===t[b].id_product&&(a=!0,l.quantity=l.quantity+t[b].quantity,l.sales_btax=l.sales_btax+t[b].price*t[b].quantity,l.sales_atax=l.sales_atax+t[b].price*t[b].quantity*(1+t[b].tax/100),null!=l.combos))for(c=0;c<l.combos.length;c++)d[i].combos[c].id_product===t[b].combos[c].id_product&&(l.combos[c].quantity=l.combos[c].quantity+t[b].combos[c].quantity*t[b].quantity,l.combos[c].sales_btax=l.combos[c].sales_btax+t[b].combos[c].price*t[b].combos[c].quantity*t[b].quantity,l.combos[c].sales_atax=l.combos[c].sales_atax+t[b].combos[c].price*t[b].combos[c].quantity*t[b].quantity*(1+t[b].tax/100))}else if(1234===o)if(1===t[b].ptype){if(1===d[i].type&&d[i]._id===t[b].id_product&&(a=!0,l.quantity=l.quantity+t[b].quantity,l.sales_btax=l.sales_btax+t[b].price*t[b].quantity,l.sales_atax=l.sales_atax+t[b].price*t[b].quantity*(1+t[b].tax/100),null!=l.subs))for(c=0;c<l.subs.length;c++)if(d[i].subs[c]._id===t[b].id_subproduct){l.subs[c].quantity=l.subs[c].quantity+t[b].quantity,l.subs[c].sales_btax=l.subs[c].sales_btax+t[b].price*t[b].quantity,l.subs[c].sales_atax=l.subs[c].sales_atax+t[b].price*t[b].quantity*(1+t[b].tax/100);break}if(4===d[i].type&&null!=t[b].toppings)for(f=0;f<t[b].toppings.length;f++)d[i]._id===t[b].toppings[f].id_product&&(a=!0,l.quantity=l.quantity+t[b].toppings[f].quantity,l.sales_btax=l.sales_btax+t[b].toppings[f].price*t[b].toppings[f].quantity,l.sales_atax=l.sales_atax+t[b].toppings[f].price*t[b].toppings[f].quantity*(1+t[b].tax/100))}else if(2===t[b].ptype)d[i]._id===t[b].id_product&&(a=!0,l.quantity=l.quantity+t[b].quantity,l.sales_btax=l.sales_btax+t[b].price*t[b].quantity,l.sales_atax=l.sales_atax+t[b].price*t[b].quantity*(1+t[b].tax/100));else if(3===t[b].ptype)d[i]._id===t[b].id_product&&(a=!0,l.quantity=l.quantity+t[b].quantity,l.sales_btax=l.sales_btax+t[b].price*t[b].quantity,l.sales_atax=l.sales_atax+t[b].price*t[b].quantity*(1+t[b].tax/100));else if(4===t[b].ptype)d[i]._id===t[b].id_product&&(a=!0,l.quantity=l.quantity+t[b].quantity,l.sales_btax=l.sales_btax+t[b].price*t[b].quantity,l.sales_atax=l.sales_atax+t[b].price*t[b].quantity*(1+t[b].tax/100));else if(5===t[b].ptype)for(f=0;f<t[b].combos.length;f++)if(d[i]._id===t[b].combos[f].id_product&&(a=!0,l.quantity=l.quantity+t[b].combos[f].quantity*t[b].quantity,l.sales_btax=l.sales_btax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity,l.sales_atax=l.sales_atax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity*(1+t[b].tax/100),null!=l.subs))for(c=0;c<l.subs.length;c++)if(d[i].subs[c]._id===t[b].combos[f].id_subproduct){l.subs[c].quantity=l.subs[c].quantity+t[b].combos[f].quantity*t[b].quantity,l.subs[c].sales_btax=l.subs[c].sales_btax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity,l.subs[c].sales_atax=l.subs[c].sales_atax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity*(1+t[b].tax/100);break}a&&(l.sales_atax=Math.round(1e6*l.sales_atax)/1e6,null!=l.subs&&l.subs.forEach((function(t){t.sales_atax=Math.round(1e6*t.sales_atax)/1e6})),null!=l.combos&&l.combos.forEach((function(t){t.sales_atax=Math.round(1e6*t.sales_atax)/1e6})),p.quantity=p.quantity+l.quantity,p.sales_btax=p.sales_btax+l.sales_btax,p.sales_atax=p.sales_atax+l.sales_atax,l.index=p.size+1,p.docs.push(l),p.size++,p.empty=!1)}console.log("jsons",p),s(p)})):s(p)}))},t.prototype.getReportSales_Products_byProduct=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=i.getlocalProduct(n),l=new Array;i.getlocalProductAndCombosAndToppings(n).forEach((function(t){l.push(t._id)}));var c,u=r.type,d={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};c="all"===o||void 0===o?{date:{$gte:t,$lte:e},id_product:{$in:l},bill_type:{$eq:1}}:{date:{$gte:t,$lte:e},id_product:{$in:l},bill_type:{$eq:1},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("vhbill_details",c,{},{date:1},0).then((function(t){var e;if(t.length>0)for(var n=0;n<t.length;n++){var o=new Array;if(o[0]={id_product:r._id,name:r.name,unit:r.unit,barcode:r.barcode,img:r.img,bill_code:t[n].bill_code,bill_type:t[n].bill_type,id_bill:t[n].id_bill,date:t[n].date,tax:t[n].tax,salesman:null===(e=i.vhAuth.getlocalEmployee(t[n].id_employee))||void 0===e?void 0:e.name,customer:i.getlocalCustomer(t[n].id_customer).name},1===u){if(null!=t[n].combos){for(var s=0,l=Object.assign({},o[0]),c=0;c<t[n].combos.length;c++)if(t[n].combos[c].id_product===r._id)if(null!=r.subs)for(var _=0;_<r.subs.length;_++)t[n].combos[c].id_subproduct===r.subs[_]._id&&(0==s?(o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price,o[0].id_subproduct=r.subs[_]._id,o[0].name=o[0].name+"("+r.subs[_].name+")"):(o[s]=Object.assign({},l),o[s].quantity=t[n].combos[c].quantity*t[n].quantity,o[s].price=t[n].combos[c].price,o[s].id_subproduct=r.subs[_]._id,o[s].name=o[s].name+"("+r.subs[_].name+")"),s++);else o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price}else if(o[0].quantity=t[n].quantity,o[0].price=t[n].price,null!=r.subs)for(_=0;_<r.subs.length;_++)if(t[n].id_subproduct===r.subs[_]._id){o[0].id_subproduct=r.subs[_]._id,o[0].name=o[0].name+"("+r.subs[_].name+")";break}}else if(2===u||3===u)if(null!=t[n].combos){for(c=0;c<t[n].combos.length;c++)if(t[n].combos[c].id_product===r._id){o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price;break}}else o[0].quantity=t[n].quantity,o[0].price=t[n].price;else if(4===u)if(null!=t[n].combos){for(c=0;c<t[n].combos.length;c++)if(t[n].combos[c].id_product===r._id){o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price;break}}else if(null!=t[n].toppings){for(c=0;c<t[n].toppings.length;c++)if(t[n].toppings[c].id_product===r._id){o[0].quantity=t[n].toppings[c].quantity,o[0].price=t[n].toppings[c].price;break}}else o[0].quantity=t[n].quantity,o[0].price=t[n].price;else 5===u&&(o[0].quantity=t[n].quantity,o[0].price=t[n].price);o.forEach((function(t){t.sales_btax=t.price*t.quantity,t.sales_atax=t.price*t.quantity*(1+t.tax/100),t.index=d.size+1,d.docs.push(t),d.size++,d.empty=!1,d.quantity=d.quantity+t.quantity,d.sales_btax=d.sales_btax+t.price*t.quantity,d.sales_atax=d.sales_atax+t.price*t.quantity*(1+Number(t.tax)/100)}))}console.log("json",d),a(d)}))}))},t.prototype.getReportSales_Customers_byCustomers=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Array;if("all"===n)r=i.getlocalCustomers();else{var l=i.getlocalCustomer(n);r.push(l)}var c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};if(r.length>0){var u=void 0;u="all"===n?"all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$gte:t,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0).then((function(t){if(t.length>0)for(var e=0;e<r.length;e++){for(var n=!1,o={id_customer:r[e]._id,name:r[e].name,sales_btax:0,sales_atax:0,quantity:0},i=0;i<t.length;i++)if(r[e]._id===t[i].id_customer)if(5===t[i].ptype){if(null!=t[i].combos)for(var s=0;s<t[i].combos.length;s++)o.quantity=o.quantity+t[i].combos[s].quantity*t[i].quantity,o.sales_btax=o.sales_btax+t[i].combos[s].price*t[i].combos[s].quantity*t[i].quantity,o.sales_atax=o.sales_atax+t[i].combos[s].price*t[i].combos[s].quantity*t[i].quantity*(1+t[i].tax/100)}else if(n=!0,o.quantity=o.quantity+t[i].quantity,o.sales_btax=o.sales_btax+t[i].price*t[i].quantity,o.sales_atax=o.sales_atax+t[i].price*t[i].quantity*(1+t[i].tax/100),null!=t[i].toppings)for(s=0;s<t[i].toppings.length;s++)o.quantity=o.quantity+t[i].toppings[s].quantity,o.sales_btax=o.sales_btax+t[i].toppings[s].price*t[i].toppings[s].quantity,o.sales_atax=o.sales_atax+t[i].toppings[s].price*t[i].toppings[s].quantity*(1+t[i].tax/100);n&&(c.quantity=c.quantity+o.quantity,c.sales_btax=c.sales_btax+o.sales_btax,c.sales_atax=c.sales_atax+o.sales_atax,o.index=c.size+1,c.docs.push(o),c.size++,c.empty=!1)}a(c)}))}else a(c)}))},t.prototype.getReportSales_Customers_byProducts=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l=i.getlocalProducts(1234);r=r="all"===o||void 0===o?{date:{$gte:t,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1]},id_branch:{$eq:o}};var c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};l.length>0?i.vhmongo_firebase.database().getDocsByFields("vhbill_details",r,{},{date:1},0).then((function(t){var e;if(t.length>0)for(var n=0;n<l.length;n++){var o=!1,i=Object.assign({},l[n]),s={id_product:i._id,name:i.name,unit:i.unit,barcode:i.barcode,img:i.img,sales_btax:0,sales_atax:0,quantity:0};if(null!=i.subs){s.subs=new Array;for(var r=0;r<i.subs.length;r++){var u={id_subproduct:i.subs[r]._id,name:null===(e=i.subs[r])||void 0===e?void 0:e.name,sales_btax:0,sales_atax:0,quantity:0};s.subs.push(u)}}for(var d=0;d<t.length;d++)if(1===t[d].ptype){if(1===l[n].type&&l[n]._id===t[d].id_product&&(o=!0,s.quantity=s.quantity+t[d].quantity,s.sales_btax=s.sales_btax+t[d].price*t[d].quantity,s.sales_atax=s.sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100),null!=s.subs))for(r=0;r<s.subs.length;r++)if(l[n].subs[r]._id===t[d].id_subproduct){s.subs[r].quantity=s.subs[r].quantity+t[d].quantity,s.subs[r].sales_btax=s.subs[r].sales_btax+t[d].price*t[d].quantity,s.subs[r].sales_atax=s.subs[r].sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100);break}if(4===l[n].type&&null!=t[d].toppings)for(var _=0;_<t[d].toppings.length;_++)l[n]._id===t[d].toppings[_].id_product&&(o=!0,s.quantity=s.quantity+t[d].toppings[_].quantity,s.sales_btax=s.sales_btax+t[d].toppings[_].price*t[d].toppings[_].quantity,s.sales_atax=s.sales_atax+t[d].toppings[_].price*t[d].toppings[_].quantity*(1+t[d].tax/100))}else if(2===t[d].ptype)l[n]._id===t[d].id_product&&(o=!0,s.quantity=s.quantity+t[d].quantity,s.sales_btax=s.sales_btax+t[d].price*t[d].quantity,s.sales_atax=s.sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100));else if(3===t[d].ptype)l[n]._id===t[d].id_product&&(o=!0,s.quantity=s.quantity+t[d].quantity,s.sales_btax=s.sales_btax+t[d].price*t[d].quantity,s.sales_atax=s.sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100));else if(4===t[d].ptype)l[n]._id===t[d].id_product&&(o=!0,s.quantity=s.quantity+t[d].quantity,s.sales_btax=s.sales_btax+t[d].price*t[d].quantity,s.sales_atax=s.sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100));else if(5===t[d].ptype)for(_=0;_<t[d].combos.length;_++)if(l[n]._id===t[d].combos[_].id_product&&(o=!0,s.quantity=s.quantity+t[d].combos[_].quantity*t[d].quantity,s.sales_btax=s.sales_btax+t[d].combos[_].price*t[d].combos[_].quantity*t[d].quantity,s.sales_atax=s.sales_atax+t[d].combos[_].price*t[d].combos[_].quantity*t[d].quantity*(1+t[d].tax/100),null!=s.subs))for(r=0;r<s.subs.length;r++)if(l[n].subs[r]._id===t[d].combos[_].id_subproduct){s.subs[r].quantity=s.subs[r].quantity+t[d].combos[_].quantity*t[d].quantity,s.subs[r].sales_btax=s.subs[r].sales_btax+t[d].combos[_].price*t[d].combos[_].quantity*t[d].quantity,s.subs[r].sales_atax=s.subs[r].sales_atax+t[d].combos[_].price*t[d].combos[_].quantity*t[d].quantity*(1+t[d].tax/100);break}o&&(s.sales_atax=Math.round(1e6*s.sales_atax)/1e6,null!=s.subs&&s.subs.forEach((function(t){t.sales_atax=Math.round(1e6*t.sales_atax)/1e6})),c.quantity=c.quantity+s.quantity,c.sales_btax=c.sales_btax+s.sales_btax,c.sales_atax=c.sales_atax+s.sales_atax,s.index=c.size+1,c.docs.push(s),c.size++,c.empty=!1)}console.log("getReportSales_Customers_byProducts"),a(c)})):a(c)}))},t.prototype.getReportSales_Customers_byProduct=function(t,e,n,o,i){var a=this;return new Promise((function(s,r){var l=a.getlocalProduct(o),c=new Array;a.getlocalProductAndCombosAndToppings(o).forEach((function(t){c.push(t._id)}));var u,d=l.type,_={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};u="all"===i||void 0===i?{date:{$gte:t,$lte:e},id_customer:{$eq:n},id_product:{$in:c},bill_type:{$eq:1}}:{date:{$gte:t,$lte:e},id_customer:{$eq:n},id_product:{$in:c},bill_type:{$eq:1},id_branch:{$eq:i}},a.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0).then((function(t){var e;if(t.length>0)for(var n=0;n<t.length;n++){var o=new Array;if(o[0]={id_product:l._id,name:l.name,unit:l.unit,barcode:l.barcode,img:l.img,bill_code:t[n].bill_code,bill_type:t[n].bill_type,id_bill:t[n].id_bill,date:t[n].date,tax:t[n].tax,salesman:null===(e=a.vhAuth.getlocalEmployee(t[n].id_employee))||void 0===e?void 0:e.name,customer:a.getlocalCustomer(t[n].id_customer).name},1===d){if(null!=t[n].combos){for(var i=0,r=Object.assign({},o[0]),c=0;c<t[n].combos.length;c++)if(t[n].combos[c].id_product===l._id)if(null!=l.subs)for(var u=0;u<l.subs.length;u++)t[n].combos[c].id_subproduct===l.subs[u]._id&&(0==i?(o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price,o[0].id_subproduct=l.subs[u]._id,o[0].name=o[0].name+"("+l.subs[u].name+")"):(o[i]=Object.assign({},r),o[i].quantity=t[n].combos[c].quantity*t[n].quantity,o[i].price=t[n].combos[c].price,o[i].id_subproduct=l.subs[u]._id,o[i].name=o[i].name+"("+l.subs[u].name+")"),i++);else o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price}else if(o[0].quantity=t[n].quantity,o[0].price=t[n].price,null!=l.subs)for(u=0;u<l.subs.length;u++)if(t[n].id_subproduct===l.subs[u]._id){o[0].id_subproduct=l.subs[u]._id,o[0].name=o[0].name+"("+l.subs[u].name+")";break}}else if(2===d||3===d)if(null!=t[n].combos){for(c=0;c<t[n].combos.length;c++)if(t[n].combos[c].id_product===l._id){o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price;break}}else o[0].quantity=t[n].quantity,o[0].price=t[n].price;else if(4===d)if(null!=t[n].toppings){for(c=0;c<t[n].toppings.length;c++)if(t[n].toppings[c].id_product===l._id){o[0].quantity=t[n].toppings[c].quantity,o[0].price=t[n].toppings[c].price;break}}else o[0].quantity=t[n].quantity,o[0].price=t[n].price;else 5===d&&(o[0].quantity=t[n].quantity,o[0].price=t[n].price);o.forEach((function(t){t.sales_btax=t.price*t.quantity,t.sales_atax=t.price*t.quantity*(1+t.tax/100),t.index=_.size+1,_.docs.push(t),_.size++,_.empty=!1,_.quantity=_.quantity+t.quantity,_.sales_btax=_.sales_btax+t.price*t.quantity,_.sales_atax=_.sales_atax+t.price*t.quantity*(1+Number(t.tax)/100)}))}console.log("getReportSales_Customers_byProduct"),s(_)}))}))},t.prototype.getReportSales_Employees_byEmployees=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Array;if("all"===n)r=i.vhAuth.getlocalEmployees();else{var l=i.vhAuth.getlocalEmployee(n);r.push(l)}var c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};if(r.length>0){var u=void 0;u="all"===n?"all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$gte:t,$lte:e},id_employee:{$eq:n},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},id_employee:{$eq:n},bill_type:{$in:[1]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0).then((function(t){if(t.length>0)for(var e=0;e<r.length;e++){for(var n=!1,o={id_employee:r[e]._id,name:r[e].name,sales_btax:0,sales_atax:0,quantity:0},i=0;i<t.length;i++)if(r[e]._id===t[i].id_employee)if(5===t[i].ptype){if(null!=t[i].combos)for(var s=0;s<t[i].combos.length;s++)o.quantity=o.quantity+t[i].combos[s].quantity*t[i].quantity,o.sales_btax=o.sales_btax+t[i].combos[s].price*t[i].combos[s].quantity*t[i].quantity,o.sales_atax=o.sales_atax+t[i].combos[s].price*t[i].combos[s].quantity*t[i].quantity*(1+t[i].tax/100)}else if(n=!0,o.quantity=o.quantity+t[i].quantity,o.sales_btax=o.sales_btax+t[i].price*t[i].quantity,o.sales_atax=o.sales_atax+t[i].price*t[i].quantity*(1+t[i].tax/100),null!=t[i].toppings)for(s=0;s<t[i].toppings.length;s++)o.quantity=o.quantity+t[i].toppings[s].quantity,o.sales_btax=o.sales_btax+t[i].toppings[s].price*t[i].toppings[s].quantity,o.sales_atax=o.sales_atax+t[i].toppings[s].price*t[i].toppings[s].quantity*(1+t[i].tax/100);n&&(c.quantity=c.quantity+o.quantity,c.sales_btax=c.sales_btax+o.sales_btax,c.sales_atax=c.sales_atax+o.sales_atax,o.index=c.size+1,c.docs.push(o),c.size++,c.empty=!1)}console.log("getReportSales_Employees_byEmployees"),a(c)}))}else a(c)}))},t.prototype.getReportSales_Employees_byProducts=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l=i.getlocalProducts(1234);r=r="all"===o||void 0===o?{date:{$gte:t,$lte:e},id_employee:{$eq:n},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},id_employee:{$eq:n},bill_type:{$in:[1]},id_branch:{$eq:o}};var c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};l.length>0?i.vhmongo_firebase.database().getDocsByFields("vhbill_details",r,{},{date:1},0).then((function(t){var e;if(t.length>0)for(var n=0;n<l.length;n++){var o=!1,i=Object.assign({},l[n]),s={id_product:i._id,name:i.name,unit:i.unit,barcode:i.barcode,img:i.img,sales_btax:0,sales_atax:0,quantity:0};if(null!=i.subs){s.subs=new Array;for(var r=0;r<i.subs.length;r++){var u={id_subproduct:i.subs[r]._id,name:null===(e=i.subs[r])||void 0===e?void 0:e.name,sales_btax:0,sales_atax:0,quantity:0};s.subs.push(u)}}for(var d=0;d<t.length;d++)if(1===t[d].ptype){if(1===l[n].type&&l[n]._id===t[d].id_product&&(o=!0,s.quantity=s.quantity+t[d].quantity,s.sales_btax=s.sales_btax+t[d].price*t[d].quantity,s.sales_atax=s.sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100),null!=s.subs))for(r=0;r<s.subs.length;r++)if(l[n].subs[r]._id===t[d].id_subproduct){s.subs[r].quantity=s.subs[r].quantity+t[d].quantity,s.subs[r].sales_btax=s.subs[r].sales_btax+t[d].price*t[d].quantity,s.subs[r].sales_atax=s.subs[r].sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100);break}if(4===l[n].type&&null!=t[d].toppings)for(var _=0;_<t[d].toppings.length;_++)l[n]._id===t[d].toppings[_].id_product&&(o=!0,s.quantity=s.quantity+t[d].toppings[_].quantity,s.sales_btax=s.sales_btax+t[d].toppings[_].price*t[d].toppings[_].quantity,s.sales_atax=s.sales_atax+t[d].toppings[_].price*t[d].toppings[_].quantity*(1+t[d].tax/100))}else if(2===t[d].ptype)l[n]._id===t[d].id_product&&(o=!0,s.quantity=s.quantity+t[d].quantity,s.sales_btax=s.sales_btax+t[d].price*t[d].quantity,s.sales_atax=s.sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100));else if(3===t[d].ptype)l[n]._id===t[d].id_product&&(o=!0,s.quantity=s.quantity+t[d].quantity,s.sales_btax=s.sales_btax+t[d].price*t[d].quantity,s.sales_atax=s.sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100));else if(4===t[d].ptype)l[n]._id===t[d].id_product&&(o=!0,s.quantity=s.quantity+t[d].quantity,s.sales_btax=s.sales_btax+t[d].price*t[d].quantity,s.sales_atax=s.sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100));else if(5===t[d].ptype)for(_=0;_<t[d].combos.length;_++)if(l[n]._id===t[d].combos[_].id_product&&(o=!0,s.quantity=s.quantity+t[d].combos[_].quantity*t[d].quantity,s.sales_btax=s.sales_btax+t[d].combos[_].price*t[d].combos[_].quantity*t[d].quantity,s.sales_atax=s.sales_atax+t[d].combos[_].price*t[d].combos[_].quantity*t[d].quantity*(1+t[d].tax/100),null!=s.subs))for(r=0;r<s.subs.length;r++)if(l[n].subs[r]._id===t[d].combos[_].id_subproduct){s.subs[r].quantity=s.subs[r].quantity+t[d].combos[_].quantity*t[d].quantity,s.subs[r].sales_btax=s.subs[r].sales_btax+t[d].combos[_].price*t[d].combos[_].quantity*t[d].quantity,s.subs[r].sales_atax=s.subs[r].sales_atax+t[d].combos[_].price*t[d].combos[_].quantity*t[d].quantity*(1+t[d].tax/100);break}o&&(s.sales_atax=Math.round(1e6*s.sales_atax)/1e6,null!=s.subs&&s.subs.forEach((function(t){t.sales_atax=Math.round(1e6*t.sales_atax)/1e6})),c.quantity=c.quantity+s.quantity,c.sales_btax=c.sales_btax+s.sales_btax,c.sales_atax=c.sales_atax+s.sales_atax,s.index=c.size+1,c.docs.push(s),c.size++,c.empty=!1)}console.log("getReportSales_Employees_byProduct"),a(c)})):a(c)}))},t.prototype.getReportSales_Employees_byProduct=function(t,e,n,o,i){var a=this;return new Promise((function(s,r){var l=a.getlocalProduct(o),c=new Array;a.getlocalProductAndCombosAndToppings(o).forEach((function(t){c.push(t._id)}));var u,d=l.type,_={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};u="all"===i||void 0===i?{date:{$gte:t,$lte:e},id_employee:{$eq:n},id_product:{$in:c},bill_type:{$eq:1}}:{date:{$gte:t,$lte:e},id_employee:{$eq:n},id_product:{$in:c},bill_type:{$eq:1},id_branch:{$eq:i}},a.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0).then((function(t){var e;if(t.length>0)for(var n=0;n<t.length;n++){var o=new Array;if(o[0]={id_product:l._id,name:l.name,unit:l.unit,barcode:l.barcode,img:l.img,bill_code:t[n].bill_code,bill_type:t[n].bill_type,id_bill:t[n].id_bill,date:t[n].date,tax:t[n].tax,salesman:null===(e=a.vhAuth.getlocalEmployee(t[n].id_employee))||void 0===e?void 0:e.name,customer:a.getlocalCustomer(t[n].id_customer).name},1===d){if(null!=t[n].combos){for(var i=0,r=Object.assign({},o[0]),c=0;c<t[n].combos.length;c++)if(t[n].combos[c].id_product===l._id)if(null!=l.subs)for(var u=0;u<l.subs.length;u++)t[n].combos[c].id_subproduct===l.subs[u]._id&&(0==i?(o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price,o[0].id_subproduct=l.subs[u]._id,o[0].name=o[0].name+"("+l.subs[u].name+")"):(o[i]=Object.assign({},r),o[i].quantity=t[n].combos[c].quantity*t[n].quantity,o[i].price=t[n].combos[c].price,o[i].id_subproduct=l.subs[u]._id,o[i].name=o[i].name+"("+l.subs[u].name+")"),i++);else o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price}else if(o[0].quantity=t[n].quantity,o[0].price=t[n].price,null!=l.subs)for(u=0;u<l.subs.length;u++)if(t[n].id_subproduct===l.subs[u]._id){o[0].id_subproduct=l.subs[u]._id,o[0].name=o[0].name+"("+l.subs[u].name+")";break}}else if(2===d||3===d)if(null!=t[n].combos){for(c=0;c<t[n].combos.length;c++)if(t[n].combos[c].id_product===l._id){o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price;break}}else o[0].quantity=t[n].quantity,o[0].price=t[n].price;else if(4===d)if(null!=t[n].toppings){for(c=0;c<t[n].toppings.length;c++)if(t[n].toppings[c].id_product===l._id){o[0].quantity=t[n].toppings[c].quantity,o[0].price=t[n].toppings[c].price;break}}else o[0].quantity=t[n].quantity,o[0].price=t[n].price;else 5===d&&(o[0].quantity=t[n].quantity,o[0].price=t[n].price);o.forEach((function(t){t.sales_btax=t.price*t.quantity,t.sales_atax=t.price*t.quantity*(1+t.tax/100),t.index=_.size+1,_.docs.push(t),_.size++,_.empty=!1,_.quantity=_.quantity+t.quantity,_.sales_btax=_.sales_btax+t.price*t.quantity,_.sales_atax=_.sales_atax+t.price*t.quantity*(1+Number(t.tax)/100)}))}console.log("getReportSales_Employees_byProduct"),s(_)}))}))},t.prototype.getReportSales_Tables_byTables=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Array;if("all"===n)r=i.getlocalTables();else{var l=i.getlocalTable(n);r.push(l)}var c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};if(r.length>0){var u=void 0;u="all"===n?"all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$gte:t,$lte:e},id_table:{$eq:n},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},id_table:{$eq:n},bill_type:{$in:[1]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0).then((function(t){if(t.length>0)for(var e=0;e<r.length;e++)if("go_home"!=r[e]._id){for(var n=!1,o={id_table:r[e]._id,name:r[e].name,sales_btax:0,sales_atax:0,quantity:0},i=0;i<t.length;i++)if(r[e]._id===t[i].id_table)if(5===t[i].ptype){if(null!=t[i].combos)for(var s=0;s<t[i].combos.length;s++)o.quantity=o.quantity+t[i].combos[s].quantity*t[i].quantity,o.sales_btax=o.sales_btax+t[i].combos[s].price*t[i].combos[s].quantity*t[i].quantity,o.sales_atax=o.sales_atax+t[i].combos[s].price*t[i].combos[s].quantity*t[i].quantity*(1+t[i].tax/100)}else if(n=!0,o.quantity=o.quantity+t[i].quantity,o.sales_btax=o.sales_btax+t[i].price*t[i].quantity,o.sales_atax=o.sales_atax+t[i].price*t[i].quantity*(1+t[i].tax/100),null!=t[i].toppings)for(s=0;s<t[i].toppings.length;s++)o.quantity=o.quantity+t[i].toppings[s].quantity,o.sales_btax=o.sales_btax+t[i].toppings[s].price*t[i].toppings[s].quantity,o.sales_atax=o.sales_atax+t[i].toppings[s].price*t[i].toppings[s].quantity*(1+t[i].tax/100);n&&(c.quantity=c.quantity+o.quantity,c.sales_btax=c.sales_btax+o.sales_btax,c.sales_atax=c.sales_atax+o.sales_atax,o.index=c.size+1,c.docs.push(o),c.size++,c.empty=!1)}console.log("getReportSales_Tables_byTables"),a(c)}))}else a(c)}))},t.prototype.getReportSales_Tables_byProducts=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l=i.getlocalProducts(1234);r=r="all"===o||void 0===o?{date:{$gte:t,$lte:e},id_table:{$eq:n},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},id_table:{$eq:n},bill_type:{$in:[1]},id_branch:{$eq:o}};var c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};l.length>0?i.vhmongo_firebase.database().getDocsByFields("vhbill_details",r,{},{date:1},0).then((function(t){var e;if(t.length>0)for(var n=0;n<l.length;n++){var o=!1,i=Object.assign({},l[n]),s={id_product:i._id,name:i.name,unit:i.unit,barcode:i.barcode,img:i.img,sales_btax:0,sales_atax:0,quantity:0};if(null!=i.subs){s.subs=new Array;for(var r=0;r<i.subs.length;r++){var u={id_subproduct:i.subs[r]._id,name:null===(e=i.subs[r])||void 0===e?void 0:e.name,sales_btax:0,sales_atax:0,quantity:0};s.subs.push(u)}}for(var d=0;d<t.length;d++)if(1===t[d].ptype){if(1===l[n].type&&l[n]._id===t[d].id_product&&(o=!0,s.quantity=s.quantity+t[d].quantity,s.sales_btax=s.sales_btax+t[d].price*t[d].quantity,s.sales_atax=s.sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100),null!=s.subs))for(r=0;r<s.subs.length;r++)if(l[n].subs[r]._id===t[d].id_subproduct){s.subs[r].quantity=s.subs[r].quantity+t[d].quantity,s.subs[r].sales_btax=s.subs[r].sales_btax+t[d].price*t[d].quantity,s.subs[r].sales_atax=s.subs[r].sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100);break}if(4===l[n].type&&null!=t[d].toppings)for(var _=0;_<t[d].toppings.length;_++)l[n]._id===t[d].toppings[_].id_product&&(o=!0,s.quantity=s.quantity+t[d].toppings[_].quantity,s.sales_btax=s.sales_btax+t[d].toppings[_].price*t[d].toppings[_].quantity,s.sales_atax=s.sales_atax+t[d].toppings[_].price*t[d].toppings[_].quantity*(1+t[d].tax/100))}else if(2===t[d].ptype)l[n]._id===t[d].id_product&&(o=!0,s.quantity=s.quantity+t[d].quantity,s.sales_btax=s.sales_btax+t[d].price*t[d].quantity,s.sales_atax=s.sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100));else if(3===t[d].ptype)l[n]._id===t[d].id_product&&(o=!0,s.quantity=s.quantity+t[d].quantity,s.sales_btax=s.sales_btax+t[d].price*t[d].quantity,s.sales_atax=s.sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100));else if(4===t[d].ptype)l[n]._id===t[d].id_product&&(o=!0,s.quantity=s.quantity+t[d].quantity,s.sales_btax=s.sales_btax+t[d].price*t[d].quantity,s.sales_atax=s.sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100));else if(5===t[d].ptype)for(_=0;_<t[d].combos.length;_++)if(l[n]._id===t[d].combos[_].id_product&&(o=!0,s.quantity=s.quantity+t[d].combos[_].quantity*t[d].quantity,s.sales_btax=s.sales_btax+t[d].combos[_].price*t[d].combos[_].quantity*t[d].quantity,s.sales_atax=s.sales_atax+t[d].combos[_].price*t[d].combos[_].quantity*t[d].quantity*(1+t[d].tax/100),null!=s.subs))for(r=0;r<s.subs.length;r++)if(l[n].subs[r]._id===t[d].combos[_].id_subproduct){s.subs[r].quantity=s.subs[r].quantity+t[d].combos[_].quantity*t[d].quantity,s.subs[r].sales_btax=s.subs[r].sales_btax+t[d].combos[_].price*t[d].combos[_].quantity*t[d].quantity,s.subs[r].sales_atax=s.subs[r].sales_atax+t[d].combos[_].price*t[d].combos[_].quantity*t[d].quantity*(1+t[d].tax/100);break}o&&(s.sales_atax=Math.round(1e6*s.sales_atax)/1e6,null!=s.subs&&s.subs.forEach((function(t){t.sales_atax=Math.round(1e6*t.sales_atax)/1e6})),c.quantity=c.quantity+s.quantity,c.sales_btax=c.sales_btax+s.sales_btax,c.sales_atax=c.sales_atax+s.sales_atax,s.index=c.size+1,c.docs.push(s),c.size++,c.empty=!1)}console.log("getReportSales_Tables_byProducts"),a(c)})):a(c)}))},t.prototype.getReportSales_Tables_byProduct=function(t,e,n,o,i){var a=this;return new Promise((function(s,r){var l=a.getlocalProduct(o),c=new Array;a.getlocalProductAndCombosAndToppings(o).forEach((function(t){c.push(t._id)}));var u,d=l.type,_={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};u="all"===i||void 0===i?{date:{$gte:t,$lte:e},id_table:{$eq:n},id_product:{$in:c},bill_type:{$eq:1}}:{date:{$gte:t,$lte:e},id_table:{$eq:n},id_product:{$in:c},bill_type:{$eq:1},id_branch:{$eq:i}},a.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0).then((function(t){var e;if(t.length>0)for(var n=0;n<t.length;n++){var o=new Array;if(o[0]={id_product:l._id,name:l.name,unit:l.unit,barcode:l.barcode,img:l.img,bill_code:t[n].bill_code,bill_type:t[n].bill_type,id_bill:t[n].id_bill,date:t[n].date,tax:t[n].tax,salesman:null===(e=a.vhAuth.getlocalEmployee(t[n].id_employee))||void 0===e?void 0:e.name,customer:a.getlocalCustomer(t[n].id_customer).name},1===d){if(null!=t[n].combos){for(var i=0,r=Object.assign({},o[0]),c=0;c<t[n].combos.length;c++)if(t[n].combos[c].id_product===l._id)if(null!=l.subs)for(var u=0;u<l.subs.length;u++)t[n].combos[c].id_subproduct===l.subs[u]._id&&(0==i?(o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price,o[0].id_subproduct=l.subs[u]._id,o[0].name=o[0].name+"("+l.subs[u].name+")"):(o[i]=Object.assign({},r),o[i].quantity=t[n].combos[c].quantity*t[n].quantity,o[i].price=t[n].combos[c].price,o[i].id_subproduct=l.subs[u]._id,o[i].name=o[i].name+"("+l.subs[u].name+")"),i++);else o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price}else if(o[0].quantity=t[n].quantity,o[0].price=t[n].price,null!=l.subs)for(u=0;u<l.subs.length;u++)if(t[n].id_subproduct===l.subs[u]._id){o[0].id_subproduct=l.subs[u]._id,o[0].name=o[0].name+"("+l.subs[u].name+")";break}}else if(2===d||3===d)if(null!=t[n].combos){for(c=0;c<t[n].combos.length;c++)if(t[n].combos[c].id_product===l._id){o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price;break}}else o[0].quantity=t[n].quantity,o[0].price=t[n].price;else if(4===d)if(null!=t[n].toppings){for(c=0;c<t[n].toppings.length;c++)if(t[n].toppings[c].id_product===l._id){o[0].quantity=t[n].toppings[c].quantity,o[0].price=t[n].toppings[c].price;break}}else o[0].quantity=t[n].quantity,o[0].price=t[n].price;else 5===d&&(o[0].quantity=t[n].quantity,o[0].price=t[n].price);o.forEach((function(t){t.sales_btax=t.price*t.quantity,t.sales_atax=t.price*t.quantity*(1+t.tax/100),t.index=_.size+1,_.docs.push(t),_.size++,_.empty=!1,_.quantity=_.quantity+t.quantity,_.sales_btax=_.sales_btax+t.price*t.quantity,_.sales_atax=_.sales_atax+t.price*t.quantity*(1+Number(t.tax)/100)}))}console.log("getReportSales_Tables_byProduct"),s(_)}))}))},t.prototype.getReportInputOutputReturns_byTime_byIDMaterial_byBillTypeArray=function(t,e,n,o,i){var a=this;return new Promise((function(s,r){var l=new Array;if("all"===n)l=a.vhAlgorithm.sortVietnamesebyASC(a.getlocalProducts(3),"name");else{var c=a.getlocalProduct(n);l.push(c)}var u={docs:new Array,empty:!0,size:0,quantity:0,pay_btax:0,pay_atax:0};if(l.length>0){var d=void 0;d="all"===n?"all"===i||void 0===i?{date:{$gte:t,$lte:e},ptype:{$eq:3},bill_type:{$in:o}}:{date:{$gte:t,$lte:e},ptype:{$eq:3},bill_type:{$in:o},id_branch:{$eq:i}}:"all"===i||void 0===i?{date:{$gte:t,$lte:e},id_product:{$eq:n},bill_type:{$in:o}}:{date:{$gte:t,$lte:e},id_product:{$eq:n},bill_type:{$in:o},id_branch:{$eq:i}},a.vhmongo_firebase.database().getDocsByFields("vhbill_details",d,{},{date:1},0).then((function(t){for(var e=0;e<l.length;e++){for(var n=!1,o={_id:l[e]._id,name:l[e].name,type:l[e].type,unit:l[e].unit,quantity:0,pay_btax:0,pay_atax:0},i=0;i<t.length;i++)t[i].id_product===l[e]._id&&(n=!0,3===t[i].bill_type||16===t[i].bill_type||(o.pay_btax=o.pay_btax+t[i].price*t[i].quantity,o.pay_atax=o.pay_atax+t[i].price*t[i].quantity*(1+t[i].tax/100)),o.quantity=o.quantity+t[i].quantity);n&&(u.pay_btax=u.pay_btax+o.price*o.quantity,u.pay_atax=u.pay_atax+o.price*o.quantity*(1+o.tax/100),u.quantity=u.quantity+o.quantity,u.docs.push(o),u.size++,u.empty=!1)}console.log("json",u),s(u)}))}else console.log("server -> products khong ton tai trong CSDL: "),s(u)}))},t.prototype.getReportInputOutputReturns_Detail_byTime_byIDMaterial_byBillTypeArray=function(t,e,n,o,i){var a=this;return new Promise((function(s,r){var l,c=a.getlocalProduct(n),u={docs:new Array,empty:!0,size:0,quantity:0,pay_btax:0,pay_atax:0};l="all"===i||void 0===i?{date:{$gte:t,$lte:e},id_product:{$eq:n},bill_type:{$in:o}}:{date:{$gte:t,$lte:e},id_product:{$eq:n},bill_type:{$in:o},id_branch:{$eq:i}},a.vhmongo_firebase.database().getDocsByFields("vhbill_details",l,{},{date:1},0).then((function(t){for(var e,n,o,i,a,r,l,d,_,p,b,f,h,y,m,v,g,x,q,w=0;w<t.length;w++){var P={id_bill:null===(e=t[w])||void 0===e?void 0:e.id_bill,bill_code:null===(n=t[w])||void 0===n?void 0:n.bill_code,bill_type:null===(o=t[w])||void 0===o?void 0:o.bill_type,date:null===(i=t[w])||void 0===i?void 0:i.date,price_btax:null===(a=t[w])||void 0===a?void 0:a.price,price_atax:(null===(r=t[w])||void 0===r?void 0:r.price)*(1+t[w].tax/100),pay_btax:(null===(l=t[w])||void 0===l?void 0:l.price)*(null===(d=t[w])||void 0===d?void 0:d.quantity),pay_atax:(null===(_=t[w])||void 0===_?void 0:_.price)*(null===(p=t[w])||void 0===p?void 0:p.quantity)*(1+t[w].tax/100),quantity:null===(b=t[w])||void 0===b?void 0:b.quantity,name:c.name,unit:c.unit};(null===(f=t[w])||void 0===f?void 0:f.id_cashier)&&(P.id_cashier=null===(h=t[w])||void 0===h?void 0:h.id_cashier),(null===(y=t[w])||void 0===y?void 0:y.id_employee)&&(P.id_employee=null===(m=t[w])||void 0===m?void 0:m.id_employee),(null===(v=t[w])||void 0===v?void 0:v.id_customer)&&(P.id_customer=null===(g=t[w])||void 0===g?void 0:g.id_customer),(null===(x=t[w])||void 0===x?void 0:x.id_supplier)&&(P.id_supplier=null===(q=t[w])||void 0===q?void 0:q.id_supplier),u.quantity=u.quantity+t[w].quantity,u.pay_btax=u.pay_btax+t[w].price*t[w].quantity,u.pay_atax=u.pay_atax+t[w].price*t[w].quantity*(1+t[w].tax/100),u.docs.push(P),u.size++,u.empty=!1}s(u)}))}))},t.prototype.getReportInputOutputInventory_byTime_byIDMaterial=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r={docs:new Array,empty:!0,size:0,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0,stock_first:0,stock_last:0,cost_stock_first_btax:0,cost_stock_first_atax:0,cost_stock_last_btax:0,cost_stock_last_atax:0},l=i.vhAuth.getStore(),c=new Array;if("all"===n)c=i.vhAlgorithm.sortVietnamesebyASC(i.getlocalProducts(3),"name");else{var u=i.getlocalProduct(n);c.push(u)}var d=null,_=null;if("all"===n)if("all"===o||void 0===o)console.log("trường hợp này chưa có hàm, liên hệ anh Huy viết");else{if(null!=c[0][o]&&null!=c[0][o].inventory)for(var p=0;p<c[0][o].inventory.length&&!(new Date(c[0][o].inventory[p].date).getTime()>t.getTime());p++)_=new Date(c[0][o].inventory[p].date),d=p;if(_){for(var b=!1,f=0;f<c.length;f++)null!=c[f][o]&&null!=c[f][o].inventory||(b=!0);if(b)return console.log("Vui lòng đồng bộ kho để lấy về dữ liệu mới nhất"),a(r)}}else if("all"===o||void 0===o)console.log("trường hợp này chưa có hàm, liên hệ anh Huy viết");else if(null!=c[0][o]&&null!=c[0][o].inventory)for(p=0;p<c[0][o].inventory.length&&!(new Date(c[0][o].inventory[p].date).getTime()>t.getTime());p++)_=new Date(c[0][o].inventory[p].date),d=p;if(_||(_=new Date(l.registrationdate)),c.length>0){var h,y=new Array;"all"===n?(h="all"===o||void 0===o?{date:{$gte:_,$lte:e},ptype:{$eq:3},bill_type:{$in:[1,3,10,30,2,9,16,31]}}:{date:{$gte:_,$lte:e},ptype:{$eq:3},bill_type:{$in:[1,3,10,30,2,9,16,31]},id_branch:{$eq:o}},y[0]=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",h,{},{date:1},0)):(h="all"===o||void 0===o?{date:{$gte:_,$lte:e},id_product:{$eq:c[0]._id},bill_type:{$in:[1,3,10,30,2,9,16,31]}}:{date:{$gte:_,$lte:e},id_product:{$eq:c[0]._id},bill_type:{$in:[1,3,10,30,2,9,16,31]},id_branch:{$eq:o}},y[0]=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",h,{},{date:1},0)),Promise.all(y).then((function(e){for(var n=e.flat(),i=0;i<c.length;i++){for(var s={stock_first:0,cost_stock_first_btax:0,cost_stock_first_atax:0,unit_cost_stock_first_btax:0,unit_cost_stock_first_atax:0,inquantity_tofirst:0,outquantity_tofirst:0,pay_tofirst_btax:0,pay_tofirst_atax:0,profit_first_btax:0,profit_first_atax:0,sales_tofirst_btax:0,sales_tofirst_atax:0},l={_id:c[i]._id,name:c[i].name,type:c[i].type,unit:c[i].unit,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0,stock_first:0,stock_last:0,cost_stock_first_btax:0,cost_stock_first_atax:0,cost_stock_last_btax:0,cost_stock_last_atax:0},u=0,_=0,p=0,b=0,f=0,h=0,y=0,m=0;m<n.length;m++)if(3===n[m].ptype&&n[m].id_product===c[i]._id){var v=new Date(n[m].date);1===n[m].bill_type||3===n[m].bill_type||10===n[m].bill_type||30===n[m].bill_type?v>=new Date(t)?(l.revenue_btax=l.revenue_btax+n[m].price*n[m].quantity,l.revenue_atax=l.revenue_atax+n[m].price*n[m].quantity*(1+n[m].tax/100),l.outquantity=l.outquantity+n[m].quantity,r.revenue_btax=r.revenue_btax+n[m].price*n[m].quantity,r.revenue_atax=r.revenue_atax+n[m].price*n[m].quantity*(1+n[m].tax/100),r.outquantity=r.outquantity+n[m].quantity):u+=n[m].quantity:2===n[m].bill_type||16===n[m].bill_type||31===n[m].bill_type?(v>=new Date(t)?(l.cost_btax=l.cost_btax+n[m].price*n[m].quantity,l.cost_atax=l.cost_atax+n[m].price*n[m].quantity*(1+n[m].tax/100),l.inquantity=l.inquantity+n[m].quantity,r.cost_btax=r.cost_btax+n[m].price*n[m].quantity,r.cost_atax=r.cost_atax+n[m].price*n[m].quantity*(1+n[m].tax/100),r.inquantity=r.inquantity+n[m].quantity):(_+=n[m].quantity,p+=n[m].price*n[m].quantity,b+=n[m].price*n[m].quantity*(1+n[m].tax/100)),f+=n[m].quantity,h+=n[m].price*n[m].quantity,y+=n[m].price*n[m].quantity*(1+n[m].tax/100)):9===n[m].bill_type&&(s.stock_first=s.stock_first+n[m].quantity,s.cost_stock_first_btax=s.cost_stock_first_btax+n[m].price*n[m].quantity,s.cost_stock_first_atax=s.cost_stock_first_btax+n[m].price*n[m].quantity*(1+n[m].tax/100))}null!=d&&(s=Object.assign({},c[i][o].inventory[d])),l.stock_first=s.stock_first+_-u,l.stock_last=l.stock_first+l.inquantity-l.outquantity,s.stock_first+_!=0&&(l.cost_stock_first_btax=(s.cost_stock_first_btax+p)/(s.stock_first+_)*l.stock_first,l.cost_stock_first_atax=(s.cost_stock_first_atax+b)/(s.stock_first+_)*l.stock_first),s.stock_first+f!=0&&(l.cost_stock_last_btax=(s.cost_stock_first_btax+h)/(s.stock_first+f)*l.stock_last,l.cost_stock_last_atax=(s.cost_stock_first_atax+y)/(s.stock_first+f)*l.stock_last),r.stock_first=r.stock_first+l.stock_first,r.stock_last=r.stock_last+l.stock_last,r.cost_stock_first_btax=r.cost_stock_first_btax+l.cost_stock_first_btax,r.cost_stock_first_atax=r.cost_stock_first_atax+l.cost_stock_first_atax,r.cost_stock_last_btax=r.cost_stock_last_btax+l.cost_stock_last_btax,r.cost_stock_last_atax=r.cost_stock_last_atax+l.cost_stock_last_atax,l.revenue_atax=Math.round(1e6*l.revenue_atax)/1e6,l.cost_atax=Math.round(1e6*l.cost_atax)/1e6,l.cost_stock_first_atax=Math.round(1e6*l.cost_stock_first_atax)/1e6,l.cost_stock_last_atax=Math.round(1e6*l.cost_stock_last_atax)/1e6,l.index=r.size+1,r.docs.push(l),r.size++,r.empty=!1}a(r),console.log("getReportInputOutputInventory_byTime_byIDMaterial",r)}))}else console.log("server -> products khong ton tai trong CSDL: "),a(r)}))},t.prototype.getReportInputOutputInventory_byTime_byIDMaterial1=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Array;if("all"===n)r=i.vhAlgorithm.sortVietnamesebyASC(i.getlocalProducts(3),"name");else{var l=i.getlocalProduct(n);r.push(l)}var c={docs:new Array,empty:!0,size:0,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0,stock_first:0,stock_last:0,cost_stock_first_btax:0,cost_stock_first_atax:0,cost_stock_last_btax:0,cost_stock_last_atax:0};if(r.length>0){var u=void 0;u="all"===n?"all"===o||void 0===o?{date:{$lte:e},ptype:{$eq:3},bill_type:{$in:[1,3,10,30,2,9,16,31]}}:{date:{$lte:e},ptype:{$eq:3},bill_type:{$in:[1,3,10,30,2,9,16,31]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$lte:e},ptype:{$eq:3},id_product:{$eq:n},bill_type:{$in:[1,3,10,30,2,9,16,31]}}:{date:{$lte:e},ptype:{$eq:3},id_product:{$eq:n},bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0).then((function(e){for(var n=0;n<r.length;n++){for(var o={_id:r[n]._id,name:r[n].name,type:r[n].type,unit:r[n].unit,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0,stock_first:0,stock_last:0,cost_stock_first_btax:0,cost_stock_first_atax:0,cost_stock_last_btax:0,cost_stock_last_atax:0},i=0,s=0,l=0,u=0,d=0,_=0,p=0,b=0;b<e.length;b++)if(e[b].id_product===r[n]._id){var f=new Date(e[b].date);1===e[b].bill_type||3===e[b].bill_type||10===e[b].bill_type||30===e[b].bill_type?f>=new Date(t)?(o.revenue_btax=o.revenue_btax+e[b].price*e[b].quantity,o.revenue_atax=o.revenue_atax+e[b].price*e[b].quantity*(1+e[b].tax/100),o.outquantity=o.outquantity+e[b].quantity,c.revenue_btax=c.revenue_btax+e[b].price*e[b].quantity,c.revenue_atax=c.revenue_atax+e[b].price*e[b].quantity*(1+e[b].tax/100),c.outquantity=c.outquantity+e[b].quantity):i+=e[b].quantity:3===e[b].bill_type?f>=new Date(t)?(o.outquantity=o.outquantity+e[b].quantity,c.outquantity=c.outquantity+e[b].quantity):i+=e[b].quantity:2===e[b].bill_type||9===e[b].bill_type||31===e[b].bill_type?(f>=new Date(t)?(o.cost_btax=o.cost_btax+e[b].price*e[b].quantity,o.cost_atax=o.cost_atax+e[b].price*e[b].quantity*(1+e[b].tax/100),o.inquantity=o.inquantity+e[b].quantity,c.cost_btax=c.cost_btax+e[b].price*e[b].quantity,c.cost_atax=c.cost_atax+e[b].price*e[b].quantity*(1+e[b].tax/100),c.inquantity=c.inquantity+e[b].quantity):(s+=e[b].quantity,l+=e[b].price*e[b].quantity,u+=e[b].price*e[b].quantity*(1+e[b].tax/100)),d+=e[b].quantity,_+=e[b].price*e[b].quantity,p+=e[b].price*e[b].quantity*(1+e[b].tax/100)):16===e[b].bill_type&&(f>=new Date(t)?(o.inquantity=o.inquantity+e[b].quantity,c.inquantity=c.inquantity+e[b].quantity):s+=e[b].quantity,d+=e[b].quantity)}o.stock_first=s-i,o.stock_last=o.stock_first+o.inquantity-o.outquantity,0!=s&&(o.cost_stock_first_btax=l/s*o.stock_first),0!=s&&(o.cost_stock_first_atax=u/s*o.stock_first),0!=d&&(o.cost_stock_last_btax=_/d*o.stock_last),0!=d&&(o.cost_stock_last_atax=p/d*o.stock_last),c.stock_first=c.stock_first+o.stock_first,c.stock_last=c.stock_last+o.stock_last,c.cost_stock_first_btax=c.cost_stock_first_btax+o.cost_stock_first_btax,c.cost_stock_first_atax=c.cost_stock_first_atax+o.cost_stock_first_atax,c.cost_stock_last_btax=c.cost_stock_last_btax+o.cost_stock_last_btax,c.cost_stock_last_atax=c.cost_stock_last_atax+o.cost_stock_last_atax,0==o.stock_first&&0==o.inquantity&&0==o.outquantity||(o.index=c.size+1,c.docs.push(o),c.size++,c.empty=!1)}a(c)}))}else console.log("server -> products khong ton tai trong CSDL: "),a(c)}))},t.prototype.syncInventoryEveryDay_Stock1stDayOfMonth=function(){var t=this;return new Promise((function(e,n){var o=t.vhAuth.getStore(),i=100,a=[Object.assign({},t.getDefaultBranch())];t.vhmongo_firebase.auth().getServerDate().then((function(n){var s=t.get1stDayOfMonthArray(o.registrationdate,n);if(s.length>0){for(var r=new Array,l=function(e){r[e]=new Promise((function(n){for(var o=a[e]._id,r=t.getlocalProducts(3),l=new Array,c=0;c<r.length;c++)l.push(c);var u=!0,d=l.splice(0,10),_=setInterval((function(){if(u){u=!1;for(var a=new Array,c=function(e){a[a.length]=new Promise((function(n){if(null!=r[e][o]&&null!=r[e][o].inventory){var a=r[e][o].inventory[r[e][o].inventory.length-1],l=r[e][o].inventory.length;if(new Date(a.date).getTime()<new Date(s[s.length-1]).getTime()){for(var c=l;c<s.length;c++)r[e][o].inventory[c]={},r[e][o].inventory[c].date=s[c],r[e][o].inventory[c].inquantity_tofirst=a.inquantity_tofirst,r[e][o].inventory[c].pay_tofirst_btax=a.pay_tofirst_btax,r[e][o].inventory[c].pay_tofirst_atax=a.pay_tofirst_atax,r[e][o].inventory[c].outquantity_tofirst=a.outquantity_tofirst,r[e][o].inventory[c].sales_tofirst_btax=a.sales_tofirst_btax,r[e][o].inventory[c].sales_tofirst_atax=a.sales_tofirst_atax,r[e][o].inventory[c].stock_first=0,r[e][o].inventory[c].unit_cost_stock_first_btax=0,r[e][o].inventory[c].unit_cost_stock_first_atax=0,r[e][o].inventory[c].cost_stock_first_btax=0,r[e][o].inventory[c].cost_stock_first_atax=0,r[e][o].inventory[c].profit_first_btax=0,r[e][o].inventory[c].profit_first_atax=0;var u={date:{$gte:new Date(a.date),$lte:new Date(s[s.length-1])},bill_type:{$in:[1,3,10,30,2,9,16,31]},id_branch:{$eq:o},id_product:{$eq:r[e]._id}};t.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0).then((function(a){if(a.length>0)for(var c=0;c<a.length;c++)if(3===a[c].ptype&&a[c].id_product===r[e]._id)for(var u=l;u<s.length;u++)new Date(a[c].date).getTime()<new Date(r[e][o].inventory[u].date).getTime()&&(1===a[c].bill_type||3===a[c].bill_type||10===a[c].bill_type||30===a[c].bill_type?(r[e][o].inventory[u].outquantity_tofirst=r[e][o].inventory[u].outquantity_tofirst+a[c].quantity,r[e][o].inventory[u].sales_tofirst_btax=r[e][o].inventory[u].sales_tofirst_btax+a[c].price*a[c].quantity,r[e][o].inventory[u].sales_tofirst_atax=r[e][o].inventory[u].sales_tofirst_atax+a[c].price*a[c].quantity*(1+a[c].tax/100)):2!==a[c].bill_type&&9!==a[c].bill_type&&16!==a[c].bill_type&&31!==a[c].bill_type||(r[e][o].inventory[u].inquantity_tofirst=r[e][o].inventory[u].inquantity_tofirst+a[c].quantity,r[e][o].inventory[u].pay_tofirst_btax=r[e][o].inventory[u].pay_tofirst_btax+a[c].price*a[c].quantity,r[e][o].inventory[u].pay_tofirst_atax=r[e][o].inventory[u].pay_tofirst_atax+a[c].price*a[c].quantity*(1+a[c].tax/100)));for(u=l;u<s.length;u++){var d=r[e][o].inventory[u].inquantity_tofirst-r[e][o].inventory[u-1].inquantity_tofirst,_=r[e][o].inventory[u].pay_tofirst_btax-r[e][o].inventory[u-1].pay_tofirst_btax,p=r[e][o].inventory[u].pay_tofirst_atax-r[e][o].inventory[u-1].pay_tofirst_atax;r[e][o].inventory[u].stock_first=r[e][o].inventory[u].inquantity_tofirst-r[e][o].inventory[u].outquantity_tofirst,r[e][o].inventory[u-1].stock_first+d!=0&&(r[e][o].inventory[u].unit_cost_stock_first_btax=(r[e][o].inventory[u-1].cost_stock_first_btax+_)/(r[e][o].inventory[u-1].stock_first+d),r[e][o].inventory[u].unit_cost_stock_first_atax=(r[e][o].inventory[u-1].cost_stock_first_atax+p)/(r[e][o].inventory[u-1].stock_first+d),r[e][o].inventory[u].cost_stock_first_btax=r[e][o].inventory[u].unit_cost_stock_first_btax*r[e][o].inventory[u].stock_first,r[e][o].inventory[u].cost_stock_first_atax=r[e][o].inventory[u].unit_cost_stock_first_atax*r[e][o].inventory[u].stock_first);var b=r[e][o].inventory[u].outquantity_tofirst-r[e][o].inventory[u-1].outquantity_tofirst,f=r[e][o].inventory[u].unit_cost_stock_first_btax*b,h=r[e][o].inventory[u].unit_cost_stock_first_atax*b,y=r[e][o].inventory[u].sales_tofirst_btax-r[e][o].inventory[u-1].sales_tofirst_btax,m=r[e][o].inventory[u].sales_tofirst_atax-r[e][o].inventory[u-1].sales_tofirst_atax;r[e][o].inventory[u].profit_first_btax=y-f,r[e][o].inventory[u].profit_first_atax=m-h}i--;var v=t.getlocalProduct(r[e]._id),g={};null!=v[o]?(g[o]=v[o],g[o].inventory=r[e][o].inventory):g[o]=r[e][o],t.vhmongo_firebase.database().updateDoc("products",r[e]._id,Object.assign({},g)).then((function(){console.log(e,r[e]),n(!0)}))}))}else n(null)}else{u={bill_type:{$in:[1,3,10,30,2,9,16,31]},id_branch:{$eq:o},id_product:{$eq:r[e]._id}};t.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0).then((function(a){r[e][o]={},r[e][o].inventory=new Array;for(var l=0;l<s.length;l++)r[e][o].inventory[l]={},r[e][o].inventory[l].date=s[l],r[e][o].inventory[l].inquantity_tofirst=0,r[e][o].inventory[l].pay_tofirst_btax=0,r[e][o].inventory[l].pay_tofirst_atax=0,r[e][o].inventory[l].outquantity_tofirst=0,r[e][o].inventory[l].sales_tofirst_btax=0,r[e][o].inventory[l].sales_tofirst_atax=0,r[e][o].inventory[l].stock_first=0,r[e][o].inventory[l].unit_cost_stock_first_btax=0,r[e][o].inventory[l].unit_cost_stock_first_atax=0,r[e][o].inventory[l].cost_stock_first_btax=0,r[e][o].inventory[l].cost_stock_first_atax=0,r[e][o].inventory[l].profit_first_btax=0,r[e][o].inventory[l].profit_first_atax=0;if(a.length>0){for(var c=0;c<a.length;c++)if(3===a[c].ptype&&a[c].id_product===r[e]._id)for(l=0;l<r[e][o].inventory.length;l++)new Date(a[c].date).getTime()<new Date(r[e][o].inventory[l].date).getTime()&&(1===a[c].bill_type||3===a[c].bill_type||10===a[c].bill_type||30===a[c].bill_type?(r[e][o].inventory[l].outquantity_tofirst=r[e][o].inventory[l].outquantity_tofirst+a[c].quantity,r[e][o].inventory[l].sales_tofirst_btax=r[e][o].inventory[l].sales_tofirst_btax+a[c].price*a[c].quantity,r[e][o].inventory[l].sales_tofirst_atax=r[e][o].inventory[l].sales_tofirst_atax+a[c].price*a[c].quantity*(1+a[c].tax/100)):2!==a[c].bill_type&&9!==a[c].bill_type&&16!==a[c].bill_type&&31!==a[c].bill_type||(r[e][o].inventory[l].inquantity_tofirst=r[e][o].inventory[l].inquantity_tofirst+a[c].quantity,r[e][o].inventory[l].pay_tofirst_btax=r[e][o].inventory[l].pay_tofirst_btax+a[c].price*a[c].quantity,r[e][o].inventory[l].pay_tofirst_atax=r[e][o].inventory[l].pay_tofirst_atax+a[c].price*a[c].quantity*(1+a[c].tax/100)));for(l=0;l<r[e][o].inventory.length;l++)if(0===l){var u=r[e][o].inventory[0].inquantity_tofirst,d=r[e][o].inventory[0].pay_tofirst_btax,_=r[e][o].inventory[0].pay_tofirst_atax;r[e][o].inventory[0].stock_first=r[e][o].inventory[0].inquantity_tofirst-r[e][o].inventory[0].outquantity_tofirst,0!=u&&(r[e][o].inventory[0].unit_cost_stock_first_btax=d/u,r[e][o].inventory[0].unit_cost_stock_first_atax=_/u,r[e][o].inventory[0].cost_stock_first_btax=r[e][o].inventory[0].unit_cost_stock_first_btax*r[e][o].inventory[0].stock_first,r[e][o].inventory[0].cost_stock_first_atax=r[e][o].inventory[0].unit_cost_stock_first_atax*r[e][o].inventory[0].stock_first);var p=r[e][o].inventory[0].outquantity_tofirst,b=r[e][o].inventory[0].unit_cost_stock_first_btax*p,f=r[e][o].inventory[0].unit_cost_stock_first_atax*p,h=r[e][o].inventory[0].sales_tofirst_btax,y=r[e][o].inventory[0].sales_tofirst_atax;r[e][o].inventory[0].profit_first_btax=h-b,r[e][o].inventory[0].profit_first_atax=y-f}else{u=r[e][o].inventory[l].inquantity_tofirst-r[e][o].inventory[l-1].inquantity_tofirst,d=r[e][o].inventory[l].pay_tofirst_btax-r[e][o].inventory[l-1].pay_tofirst_btax,_=r[e][o].inventory[l].pay_tofirst_atax-r[e][o].inventory[l-1].pay_tofirst_atax;r[e][o].inventory[l].stock_first=r[e][o].inventory[l].inquantity_tofirst-r[e][o].inventory[l].outquantity_tofirst,r[e][o].inventory[l-1].stock_first+u!=0&&(r[e][o].inventory[l].unit_cost_stock_first_btax=(r[e][o].inventory[l-1].cost_stock_first_btax+d)/(r[e][o].inventory[l-1].stock_first+u),r[e][o].inventory[l].unit_cost_stock_first_atax=(r[e][o].inventory[l-1].cost_stock_first_atax+_)/(r[e][o].inventory[l-1].stock_first+u),r[e][o].inventory[l].cost_stock_first_btax=r[e][o].inventory[l].unit_cost_stock_first_btax*r[e][o].inventory[l].stock_first,r[e][o].inventory[l].cost_stock_first_atax=r[e][o].inventory[l].unit_cost_stock_first_atax*r[e][o].inventory[l].stock_first);p=r[e][o].inventory[l].outquantity_tofirst-r[e][o].inventory[l-1].outquantity_tofirst,b=r[e][o].inventory[l].unit_cost_stock_first_btax*p,f=r[e][o].inventory[l].unit_cost_stock_first_atax*p,h=r[e][o].inventory[l].sales_tofirst_btax-r[e][o].inventory[l-1].sales_tofirst_btax,y=r[e][o].inventory[l].sales_tofirst_atax-r[e][o].inventory[l-1].sales_tofirst_atax;r[e][o].inventory[l].profit_first_btax=h-b,r[e][o].inventory[l].profit_first_atax=y-f}}i--;var m=t.getlocalProduct(r[e]._id),v={};null!=m[o]?(v[o]=m[o],v[o].inventory=r[e][o].inventory):v[o]=r[e][o],t.vhmongo_firebase.database().updateDoc("products",r[e]._id,Object.assign({},v)).then((function(){console.log(e,r[e]),n(!0)}))}))}}))},p=d[0];p<=d[d.length-1];p++)c(p);Promise.all(a).then((function(){i<=0&&(n(e),clearInterval(_)),l.length>0?(u=!0,d=l.splice(0,10)):(n(e),clearInterval(_))}))}}),10)}))},c=0;c<a.length;c++)l(c);Promise.all(r).then((function(t){console.log("syncInventoryEveryDay_Stock1stDayOfMonth",t),e(null)}))}else console.log("syncInventoryEveryDay_Stock1stDayOfMonth"),e(null)}))}))},t.prototype.getReportInputOutputInventory_byEndTime_byIDMaterial=function(t,e,n){var o=this;return new Promise((function(i,a){var s=new Array;if("all"===e)s=o.vhAlgorithm.sortVietnamesebyASC(o.getlocalProducts(3),"name");else{var r=o.getlocalProduct(n);s.push(r)}var l={docs:new Array,empty:!0,size:0,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0,stock_last:0,cost_stock_last_btax:0,cost_stock_last_atax:0};if(s.length>0){var c=void 0;c="all"===e?"all"===n||void 0===n?{date:{$lte:t},ptype:{$eq:3},bill_type:{$in:[1,3,10,30,2,9,16,31]}}:{date:{$lte:t},ptype:{$eq:3},bill_type:{$in:[1,3,10,30,2,9,16,31]},id_branch:{$eq:n}}:"all"===n||void 0===n?{date:{$lte:t},ptype:{$eq:3},id_product:{$eq:e},bill_type:{$in:[1,3,10,30,2,9,16,31]}}:{date:{$lte:t},ptype:{$eq:3},id_product:{$eq:e},bill_type:{$in:[1,3,10,30,2,9,16,31]},id_branch:{$eq:n}},o.vhmongo_firebase.database().getDocsByFields("vhbill_details",c,{},{date:1},0).then((function(t){for(var e=0;e<s.length;e++){for(var n={_id:s[e]._id,name:s[e].name,type:s[e].type,unit:s[e].unit,img:s[e].img,allow_sell:s[e].allow_sell,barcode:s[e].barcode,price:s[e].price,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0,stock_last:0,cost_stock_last_btax:0,cost_stock_last_atax:0},o=0;o<t.length;o++)if(t[o].id_product===s[e]._id){new Date(t[o].date);1===t[o].bill_type||10===t[o].bill_type||30===t[o].bill_type?(n.revenue_btax=n.revenue_btax+t[o].price*t[o].quantity,n.revenue_atax=n.revenue_atax+t[o].price*t[o].quantity*(1+t[o].tax/100),n.outquantity=n.outquantity+t[o].quantity,l.revenue_btax=l.revenue_btax+t[o].price*t[o].quantity,l.revenue_atax=l.revenue_atax+t[o].price*t[o].quantity*(1+t[o].tax/100),l.outquantity=l.outquantity+t[o].quantity):2===t[o].bill_type||9===t[o].bill_type||31===t[o].bill_type?(n.cost_btax=n.cost_btax+t[o].price*t[o].quantity,n.cost_atax=n.cost_atax+t[o].price*t[o].quantity*(1+t[o].tax/100),n.inquantity=n.inquantity+t[o].quantity,l.cost_btax=l.cost_btax+t[o].price*t[o].quantity,l.cost_atax=l.cost_atax+t[o].price*t[o].quantity*(1+t[o].tax/100),l.inquantity=l.inquantity+t[o].quantity):3===t[o].bill_type?(n.outquantity=n.outquantity+t[o].quantity,l.outquantity=l.outquantity+t[o].quantity):16===t[o].bill_type&&(n.inquantity=n.inquantity+t[o].quantity,l.inquantity=l.inquantity+t[o].quantity)}n.stock_last=n.inquantity-n.outquantity,0!=n.inquantity&&(n.cost_stock_last_btax=n.cost_btax/n.inquantity*n.stock_last),0!=n.inquantity&&(n.cost_stock_last_atax=n.cost_atax/n.inquantity*n.stock_last),n.cost_stock_last_btax=Math.round(1e6*n.cost_stock_last_btax)/1e6,n.cost_stock_last_atax=Math.round(1e6*n.cost_stock_last_atax)/1e6,n.cost_atax=Math.round(1e6*n.cost_atax)/1e6,l.stock_last=l.stock_last+n.stock_last,l.cost_stock_last_btax=l.cost_stock_last_btax+n.cost_stock_last_btax,l.cost_stock_last_atax=l.cost_stock_last_atax+n.cost_stock_last_atax,0==n.inquantity&&0==n.outquantity||(l.cost_atax=Math.round(1e6*l.cost_atax)/1e6,n.index=l.size+1,l.docs.push(n),l.size++,l.empty=!1)}i(l)}))}else console.log("server -> products khong ton tai trong CSDL: "),i(l)}))},t.prototype.getReportInputOutputInventory_Detail_byEndTime_byIDMaterial=function(t,e,n){var o=this;return new Promise((function(i,a){var s,r=o.getlocalProduct(e),l={docs:new Array,empty:!0,size:0,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0};s="all"===n||void 0===n?{date:{$lte:t},id_product:{$eq:e},bill_type:{$in:[1,3,10,30,2,9,16,31]}}:{date:{$lte:t},id_product:{$eq:e},bill_type:{$in:[1,3,10,30,2,9,16,31]},id_branch:{$eq:n}},o.vhmongo_firebase.database().getDocsByFields("vhbill_details",s,{},{date:1},0).then((function(t){for(var e,n,o,a,s,c,u,d,_,p,b,f,h,y,m,v,g,x,q,w,P=0;P<t.length;P++){var D={id_bill:null===(e=t[P])||void 0===e?void 0:e.id_bill,bill_code:null===(n=t[P])||void 0===n?void 0:n.bill_code,bill_type:null===(o=t[P])||void 0===o?void 0:o.bill_type,date:null===(a=t[P])||void 0===a?void 0:a.date,tax:null===(s=t[P])||void 0===s?void 0:s.tax,price_btax:null===(c=t[P])||void 0===c?void 0:c.price,price_atax:(null===(u=t[P])||void 0===u?void 0:u.price)*(1+t[P].tax/100),payment_btax:(null===(d=t[P])||void 0===d?void 0:d.price)*(null===(_=t[P])||void 0===_?void 0:_.quantity),payment_atax:(null===(p=t[P])||void 0===p?void 0:p.price)*(null===(b=t[P])||void 0===b?void 0:b.quantity)*(1+t[P].tax/100),quantity:null===(f=t[P])||void 0===f?void 0:f.quantity,name:r.name,unit:r.unit};(null===(h=t[P])||void 0===h?void 0:h.id_cashier)&&(D.id_cashier=null===(y=t[P])||void 0===y?void 0:y.id_cashier),(null===(m=t[P])||void 0===m?void 0:m.id_employee)&&(D.id_employee=null===(v=t[P])||void 0===v?void 0:v.id_employee),(null===(g=t[P])||void 0===g?void 0:g.id_customer)&&(D.id_customer=null===(x=t[P])||void 0===x?void 0:x.id_customer),(null===(q=t[P])||void 0===q?void 0:q.id_supplier)&&(D.id_supplier=null===(w=t[P])||void 0===w?void 0:w.id_supplier),1===t[P].bill_type||10===t[P].bill_type||30===t[P].bill_type?(D.type="output",l.revenue_btax=l.revenue_btax+t[P].price*t[P].quantity,l.revenue_atax=l.revenue_atax+t[P].price*t[P].quantity*(1+t[P].tax/100),l.outquantity=l.outquantity+t[P].quantity):2===t[P].bill_type||31===t[P].bill_type?(D.type="input",l.cost_btax=l.cost_btax+t[P].price*t[P].quantity,l.cost_atax=l.cost_atax+t[P].price*t[P].quantity*(1+t[P].tax/100),l.inquantity=l.inquantity+t[P].quantity):9===t[P].bill_type?(D.type="beginning",l.cost_btax=l.cost_btax+t[P].price*t[P].quantity,l.cost_atax=l.cost_atax+t[P].price*t[P].quantity*(1+t[P].tax/100),l.inquantity=l.inquantity+t[P].quantity):3===t[P].bill_type?(D.type="output",l.outquantity=l.outquantity+t[P].quantity):16===t[P].bill_type&&(D.type="input",l.inquantity=l.inquantity+t[P].quantity),l.docs.push(D),l.size++,l.empty=!1}i(l)}))}))},t.prototype.getReportInputOutputInventory_Detail_byTime_byIDMaterial=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l=i.getlocalProduct(n),c={docs:new Array,empty:!0,size:0,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0};r="all"===o||void 0===o?{date:{$gte:t,$lte:e},id_product:{$eq:n},bill_type:{$in:[1,3,10,30,2,9,16,31]}}:{date:{$gte:t,$lte:e},id_product:{$eq:n},bill_type:{$in:[1,3,10,30,2,9,16,31]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("vhbill_details",r,{},{date:1},0).then((function(t){for(var e,n,o,i,s,r,u,d,_,p,b,f,h,y,m,v,g,x,q,w=0;w<t.length;w++){var P={id_bill:null===(e=t[w])||void 0===e?void 0:e.id_bill,bill_code:null===(n=t[w])||void 0===n?void 0:n.bill_code,bill_type:null===(o=t[w])||void 0===o?void 0:o.bill_type,date:null===(i=t[w])||void 0===i?void 0:i.date,price_btax:null===(s=t[w])||void 0===s?void 0:s.price,price_atax:(null===(r=t[w])||void 0===r?void 0:r.price)*(1+t[w].tax/100),payment_btax:(null===(u=t[w])||void 0===u?void 0:u.price)*(null===(d=t[w])||void 0===d?void 0:d.quantity),payment_atax:(null===(_=t[w])||void 0===_?void 0:_.price)*(null===(p=t[w])||void 0===p?void 0:p.quantity)*(1+t[w].tax/100),quantity:null===(b=t[w])||void 0===b?void 0:b.quantity,name:l.name,unit:l.unit};(null===(f=t[w])||void 0===f?void 0:f.id_cashier)&&(P.id_cashier=null===(h=t[w])||void 0===h?void 0:h.id_cashier),(null===(y=t[w])||void 0===y?void 0:y.id_employee)&&(P.id_employee=null===(m=t[w])||void 0===m?void 0:m.id_employee),(null===(v=t[w])||void 0===v?void 0:v.id_customer)&&(P.id_customer=null===(g=t[w])||void 0===g?void 0:g.id_customer),(null===(x=t[w])||void 0===x?void 0:x.id_supplier)&&(P.id_supplier=null===(q=t[w])||void 0===q?void 0:q.id_supplier),1===t[w].bill_type||10===t[w].bill_type||30===t[w].bill_type?(P.type="output",c.revenue_btax=c.revenue_btax+t[w].price*t[w].quantity,c.revenue_atax=c.revenue_atax+t[w].price*t[w].quantity*(1+t[w].tax/100),c.outquantity=c.outquantity+t[w].quantity):2===t[w].bill_type||31===t[w].bill_type?(P.type="input",c.cost_btax=c.cost_btax+t[w].price*t[w].quantity,c.cost_atax=c.cost_atax+t[w].price*t[w].quantity*(1+t[w].tax/100),c.inquantity=c.inquantity+t[w].quantity):9===t[w].bill_type?(P.type="beginning",c.cost_btax=c.cost_btax+t[w].price*t[w].quantity,c.cost_atax=c.cost_atax+t[w].price*t[w].quantity*(1+t[w].tax/100),c.inquantity=c.inquantity+t[w].quantity):3===t[w].bill_type?(P.type="output",c.outquantity=c.outquantity+t[w].quantity):16===t[w].bill_type&&(P.type="input",c.inquantity=c.inquantity+t[w].quantity),c.docs.push(P),c.size++,c.empty=!1}a(c)}))}))},t.prototype.getReportInputOutput_byTime_byIDMaterial=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Array;if("all"===n)r=i.vhAlgorithm.sortVietnamesebyASC(i.getlocalProducts(3),"name");else{var l=i.getlocalProduct(n);r.push(l)}var c={docs:new Array,empty:!0,size:0,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0};if(r.length>0){var u=void 0;u="all"===n?"all"===o||void 0===o?{date:{$gte:t,$lte:e},ptype:{$eq:3},bill_type:{$in:[1,3,10,30,2,16,31]}}:{date:{$gte:t,$lte:e},ptype:{$eq:3},bill_type:{$in:[1,3,10,30,2,16,31]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$gte:t,$lte:e},ptype:{$eq:3},id_product:{$eq:n},bill_type:{$in:[1,3,10,30,2,16,31]}}:{date:{$gte:t,$lte:e},ptype:{$eq:3},id_product:{$eq:n},bill_type:{$in:[1,3,10,30,2,16,31]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0).then((function(t){for(var e=0;e<r.length;e++){for(var n={_id:r[e]._id,name:r[e].name,type:r[e].type,unit:r[e].unit,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0},o=0;o<t.length;o++)t[o].id_product===r[e]._id&&(1===t[o].bill_type||10===t[o].bill_type||30===t[o].bill_type?(n.revenue_btax=n.revenue_btax+t[o].price*t[o].quantity,n.revenue_atax=n.revenue_atax+t[o].price*t[o].quantity*(1+t[o].tax/100),n.outquantity=n.outquantity+t[o].quantity,c.revenue_btax=c.revenue_btax+t[o].price*t[o].quantity,c.revenue_atax=c.revenue_atax+t[o].price*t[o].quantity*(1+t[o].tax/100),c.outquantity=c.outquantity+t[o].quantity):2===t[o].bill_type||31===t[o].bill_type?(n.cost_btax=n.cost_btax+t[o].price*t[o].quantity,n.cost_atax=n.cost_atax+t[o].price*t[o].quantity*(1+t[o].tax/100),n.inquantity=n.inquantity+t[o].quantity,c.cost_btax=c.cost_btax+t[o].price*t[o].quantity,c.cost_atax=c.cost_atax+t[o].price*t[o].quantity*(1+t[o].tax/100),c.inquantity=c.inquantity+t[o].quantity):3===t[o].bill_type?(n.outquantity=n.outquantity+t[o].quantity,c.outquantity=c.outquantity+t[o].quantity):16===t[o].bill_type&&(n.inquantity=n.inquantity+t[o].quantity,c.inquantity=c.inquantity+t[o].quantity));0==n.inquantity&&0==n.outquantity||(n.index=c.size+1,c.docs.push(n),c.size++,c.empty=!1)}a(c)}))}else console.log("server -> products khong ton tai trong CSDL: "),a(c)}))},t.prototype.getReportInputOutput_Detail_byTime_byIDMaterial=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l=i.getlocalProduct(n),c={docs:new Array,empty:!0,size:0,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0};r="all"===o||void 0===o?{date:{$gte:t,$lte:e},id_product:{$eq:n},bill_type:{$in:[1,3,10,30,2,16,31]}}:{date:{$gte:t,$lte:e},id_product:{$eq:n},bill_type:{$in:[1,3,10,30,2,16,31]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("vhbill_details",r,{},{date:1},0).then((function(t){for(var e,n,o,i,s,r,u,d,_,p,b,f,h,y,m,v,g,x,q,w=0;w<t.length;w++){var P={id_bill:null===(e=t[w])||void 0===e?void 0:e.id_bill,bill_code:null===(n=t[w])||void 0===n?void 0:n.bill_code,bill_type:null===(o=t[w])||void 0===o?void 0:o.bill_type,date:null===(i=t[w])||void 0===i?void 0:i.date,price_btax:null===(s=t[w])||void 0===s?void 0:s.price,price_atax:(null===(r=t[w])||void 0===r?void 0:r.price)*(1+t[w].tax/100),payment_btax:(null===(u=t[w])||void 0===u?void 0:u.price)*(null===(d=t[w])||void 0===d?void 0:d.quantity),payment_atax:(null===(_=t[w])||void 0===_?void 0:_.price)*(null===(p=t[w])||void 0===p?void 0:p.quantity)*(1+t[w].tax/100),quantity:null===(b=t[w])||void 0===b?void 0:b.quantity,name:l.name,unit:l.unit};(null===(f=t[w])||void 0===f?void 0:f.id_cashier)&&(P.id_cashier=null===(h=t[w])||void 0===h?void 0:h.id_cashier),(null===(y=t[w])||void 0===y?void 0:y.id_employee)&&(P.id_employee=null===(m=t[w])||void 0===m?void 0:m.id_employee),(null===(v=t[w])||void 0===v?void 0:v.id_customer)&&(P.id_customer=null===(g=t[w])||void 0===g?void 0:g.id_customer),(null===(x=t[w])||void 0===x?void 0:x.id_supplier)&&(P.id_supplier=null===(q=t[w])||void 0===q?void 0:q.id_supplier),1===t[w].bill_type||10===t[w].bill_type||30===t[w].bill_type?(P.type="output",c.revenue_btax=c.revenue_btax+t[w].price*t[w].quantity,c.revenue_atax=c.revenue_atax+t[w].price*t[w].quantity*(1+t[w].tax/100),c.outquantity=c.outquantity+t[w].quantity):2===t[w].bill_type||31===t[w].bill_type?(P.type="input",c.cost_btax=c.cost_btax+t[w].price*t[w].quantity,c.cost_atax=c.cost_atax+t[w].price*t[w].quantity*(1+t[w].tax/100),c.inquantity=c.inquantity+t[w].quantity):3===t[w].bill_type?(P.type="output",c.outquantity=c.outquantity+t[w].quantity):16===t[w].bill_type&&(P.type="input",c.inquantity=c.inquantity+t[w].quantity),c.docs.push(P),c.size++,c.empty=!1}a(c)}))}))},t.prototype.getReportRevenue_byHoursOut_hourArray=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l={docs:new Array,empty:!0,size:0,revenue:0};r="all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1,7,10,11]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1,7,10,11]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("bills",r,{},{date:1},0).then((function(t){if(t.length>0){for(var e=new Array,o=0;o<n.length;o++)e[o]={},e[o].revenue=0;for(var i=0;i<t.length;i++){var s=Object.assign({},t[i]);if(s.date){var r=new Date(s.date).getHours();for(o=0;o<n.length;o++)n[o]===r&&(e[o].revenue=e[o].revenue+Number(s.payment),l.revenue=l.revenue+Number(s.payment))}}l.docs=e,l.size=n.length,l.empty=!1}a(l)}))}))},t.prototype.getReportRevenue_byDaysOut_dayArray=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l={docs:new Array,empty:!0,size:0,revenue:0};r="all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1,7,10,11]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1,7,10,11]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("bills",r,{},{date:1},0).then((function(t){if(t.length>0){for(var e=new Array,o=0;o<n.length;o++)e[o]={},e[o].revenue=0;for(var i=0;i<t.length;i++){var s=t[i];if(s.date){var r=new Date(s.date).getDate();for(o=0;o<n.length;o++)n[o]===r&&(e[o].revenue=e[o].revenue+Number(s.payment),l.revenue=l.revenue+Number(s.payment))}}l.docs=e,l.size=n.length,l.empty=!1}a(l)}))}))},t.prototype.getReportRevenue_byMonthsOut_monthArray=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l={docs:new Array,empty:!0,size:0,revenue:0};r="all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1,7,10,11]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1,7,10,11]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("bills",r,{},{date:1},0).then((function(t){if(t.length>0){for(var e=new Array,o=0;o<n.length;o++)e[o]={},e[o].revenue=0;for(var i=0;i<t.length;i++){var s=t[i];if(s.date){var r=new Date(s.date).getMonth();for(o=0;o<n.length;o++)n[o]===r&&(e[o].revenue=e[o].revenue+Number(s.payment),l.revenue=l.revenue+Number(s.payment))}}l.docs=e,l.size=n.length,l.empty=!1}a(l)}))}))},t.prototype.getReportRevenue_byIDbranch=function(t,e,n){var o=this;return new Promise((function(i,a){var s,r={docs:new Array,empty:!0,size:0,revenue:0},l=new Array;if("all"===n||void 0===n)l=o.vhAlgorithm.sortVietnamesebyASC(o.getlocalBranchs(),"name"),s={date:{$gte:t,$lte:e},bill_type:{$in:[1,7,10,11]}};else{var c=o.getlocalBranch(n);l.push(c),s={date:{$gte:t,$lte:e},bill_type:{$in:[1,7,10,11]},id_branch:{$eq:n}}}o.vhmongo_firebase.database().getDocsByFields("bills",s,{},{date:1},0).then((function(t){if(t.length>0){for(var e=new Array,n=0;n<l.length;n++)e[n]={},e[n].id_branch=l[n]._id,e[n].name=l[n].name,e[n].revenue=0;for(var o=0;o<t.length;o++)for(n=0;n<l.length;n++)l[n]._id===t[o].id_branch&&(e[n].revenue=e[n].revenue+Number(t[o].payment),r.revenue=r.revenue+Number(t[o].payment));r.docs=e,r.size=l.length,r.empty=!1}i(r)}))}))},t.prototype.getReportSales_byHoursOut_hourArray=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0};r="all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("vhbill_details",r,{},{date:1},0).then((function(t){if(t.length>0){for(var e=new Array,o=0;o<n.length;o++)e[o]={},e[o].sales_btax=0,e[o].sales_atax=0;for(var i=0;i<t.length;i++){var s=Object.assign({},t[i]);if(s.date){var r=new Date(s.date).getHours();for(o=0;o<n.length;o++)n[o]===r&&(e[o].sales_btax=e[o].sales_btax+Number(s.price)*s.quantity,e[o].sales_atax=e[o].sales_atax+Number(s.price)*s.quantity*(1+s.tax/100),l.sales_btax=l.sales_btax+Number(s.price)*s.quantity,l.sales_atax=l.sales_atax+Number(s.price)*s.quantity*(1+s.tax/100))}}l.docs=e,l.size=n.length,l.empty=!1}a(l)}))}))},t.prototype.getReportSales_byDaysOut_dayArray=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0};r="all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("vhbill_details",r,{},{date:1},0).then((function(t){if(t.length>0){for(var e=new Array,o=0;o<n.length;o++)e[o]={},e[o].sales_btax=0,e[o].sales_atax=0;for(var i=0;i<t.length;i++){var s=Object.assign({},t[i]);if(s.date){var r=new Date(s.date).getDate();for(o=0;o<n.length;o++)n[o]===r&&(e[o].sales_btax=e[o].sales_btax+Number(s.price)*s.quantity,e[o].sales_atax=e[o].sales_atax+Number(s.price)*s.quantity*(1+s.tax/100),l.sales_btax=l.sales_btax+Number(s.price)*s.quantity,l.sales_atax=l.sales_atax+Number(s.price)*s.quantity*(1+s.tax/100))}}l.docs=e,l.size=n.length,l.empty=!1}a(l)}))}))},t.prototype.getReportSales_byMonthsOut_monthArray=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0};r="all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("vhbill_details",r,{},{date:1},0).then((function(t){if(t.length>0){for(var e=new Array,o=0;o<n.length;o++)e[o]={},e[o].sales_btax=0,e[o].sales_atax=0;for(var i=0;i<t.length;i++){var s=t[i];if(s.date){var r=new Date(s.date).getMonth();for(o=0;o<n.length;o++)n[o]===r&&(e[o].sales_btax=e[o].sales_btax+Number(s.price)*s.quantity,e[o].sales_atax=e[o].sales_atax+Number(s.price)*s.quantity*(1+s.tax/100),l.sales_btax=l.sales_btax+Number(s.price)*s.quantity,l.sales_atax=l.sales_atax+Number(s.price)*s.quantity*(1+s.tax/100))}}l.docs=e,l.size=n.length,l.empty=!1}a(l)}))}))},t.prototype.getReportSales_byIDbranch=function(t,e,n){var o=this;return new Promise((function(i,a){var s,r={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0},l=new Array;if("all"===n||void 0===n)l=o.vhAlgorithm.sortVietnamesebyASC(o.getlocalBranchs(),"name"),s={date:{$gte:t,$lte:e},bill_type:{$eq:1}};else{var c=o.getlocalBranch(n);l.push(c),s={date:{$gte:t,$lte:e},bill_type:{$eq:1},id_branch:{$eq:n}}}o.vhmongo_firebase.database().getDocsByFields("vhbill_details",s,{},{date:1},0).then((function(t){if(t.length>0){for(var e=new Array,n=0;n<l.length;n++)e[n]={},e[n].id_branch=l[n]._id,e[n].name=l[n].name,e[n].sales_btax=0,e[n].sales_atax=0;for(var o=0;o<t.length;o++){var a=t[o];for(n=0;n<l.length;n++)l[n]._id===a.id_branch&&(3===a.bill_type?(e[n].sales_btax=e[n].sales_btax-Number(a.price)*a.quantity,e[n].sales_atax=e[n].sales_atax-Number(a.price)*a.quantity*(1+a.tax/100),r.sales_btax=r.sales_btax-Number(a.price)*a.quantity,r.sales_atax=r.sales_atax-Number(a.price)*a.quantity*(1+a.tax/100)):(e[n].sales_btax=e[n].sales_btax+Number(a.price)*a.quantity,e[n].sales_atax=e[n].sales_atax+Number(a.price)*a.quantity*(1+a.tax/100),r.sales_btax=r.sales_btax+Number(a.price)*a.quantity,r.sales_atax=r.sales_atax+Number(a.price)*a.quantity*(1+a.tax/100)))}r.docs=e,r.size=l.length,r.empty=!1}i(r)}))}))},t.prototype.getReportSales_Products_byTime_DESC=function(t,e){var n=this;return new Promise((function(o,i){var a,s=n.getlocalProducts();a={date:{$gte:t,$lte:e},bill_type:{$in:[1]}};var r={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};s.length>0?n.vhmongo_firebase.database().getDocsByFields("vhbill_details",a,{},{date:1},0).then((function(t){var e;if(t.length>0)for(var i=0;i<s.length;i++){var a=!1,l=Object.assign({},s[i]),c={id_product:l._id,name:l.name,unit:l.unit,barcode:l.barcode,img:l.img,sales_btax:0,sales_atax:0,quantity:0,subs:new Array};if(null!=l.subs)for(var u=0;u<l.subs.length;u++){var d={id_subproduct:l.subs[u]._id,name:null===(e=l.subs[u])||void 0===e?void 0:e.name,sales_btax:0,sales_atax:0,quantity:0};c.subs.push(d)}for(var _=0;_<t.length;_++)if(s[i]._id===t[_].id_product){a=!0,c.quantity=c.quantity+t[_].quantity,c.sales_btax=c.sales_btax+t[_].price*t[_].quantity,c.sales_atax=c.sales_atax+t[_].price*t[_].quantity*(1+t[_].tax/100);for(u=0;u<c.subs.length;u++)if(c.subs[u].id_subproduct===t[_].id_subproduct){c.subs[u].quantity=c.subs[u].quantity+t[_].quantity,c.subs[u].sales_btax=c.subs[u].sales_btax+t[_].price*t[_].quantity,c.subs[u].sales_atax=c.subs[u].sales_atax+t[_].price*t[_].quantity*(1+t[_].tax/100);break}}a&&(r.quantity=r.quantity+c.quantity,r.sales_btax=r.sales_btax+c.sales_btax,r.sales_atax=r.sales_atax+c.sales_atax,c.index=r.size+1,r.docs.push(c),r.size++,r.empty=!1)}r.docs=n.vhAlgorithm.sortNumberbyDESC(r.docs,"sales_atax"),o(r)})):o(r)}))},t.prototype.getReportSales_Categorys_byTime_DESC=function(t,e){var n=this;return new Promise((function(o,i){var a=new Array;a=n.getlocalCategorys();var s={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};if(a.length>0){var r={date:{$gte:t,$lte:e},bill_type:{$in:[1]}};n.vhmongo_firebase.database().getDocsByFields("vhbill_details",r,{},{date:1},0).then((function(t){if(t.length>0){for(var e=0;e<t.length;e++){var i=n.getlocalProduct(t[e].id_product);t[e].id_category=i.id_category}for(e=0;e<a.length;e++){for(var r={id_category:a[e]._id,name:a[e].name,sales_btax:0,sales_atax:0,quantity:0},l=0;l<t.length;l++)a[e]._id===t[l].id_category&&(r.quantity=r.quantity+t[l].quantity,r.sales_btax=r.sales_btax+t[l].price*t[l].quantity,r.sales_atax=r.sales_atax+t[l].price*t[l].quantity*(1+t[l].tax/100));0!=r.quantity&&(s.quantity=s.quantity+r.quantity,s.sales_btax=s.sales_btax+r.sales_btax,s.sales_atax=s.sales_atax+r.sales_atax,r.index=s.size+1,s.docs.push(r),s.size++,s.empty=!1)}}s.docs=n.vhAlgorithm.sortNumberbyDESC(s.docs,"sales_atax"),o(s)}))}else o(s)}))},t.prototype.getReportMaterials_byOutOfStock=function(t){var e=this;return new Promise((function(n,o){var i=e.getlocalProducts(3),a=e.getlocalBranchs(),s=new Array;if("all"===t||void 0===t){for(var r=0;r<i.length;r++){i[r].quantity=0,i[r].branchs=new Array;for(var l=0;l<a.length;l++)if(void 0===i[r].quantity_branch[a[l]._id]&&(i[r].quantity_branch[a[l]._id]=0),i[r].quantity_branch[a[l]._id]<=0){i[r].quantity=i[r].quantity+i[r].quantity_branch[a[l]._id];var c={id_branch:a[l]._id,name:a[l].name,quantity:i[r].quantity_branch[a[l]._id]};i[r].branchs.push(c)}delete i[r].quantity_branch}s=i.filter((function(t){return t.branchs.length>0}))}else{for(r=0;r<i.length;r++){i[r].quantity=0,i[r].branchs=new Array,void 0===i[r].quantity_branch[t]&&(i[r].quantity_branch[t]=0),i[r].quantity=i[r].quantity_branch[t];c={id_branch:t,name:e.getlocalBranch(t).name,quantity:i[r].quantity_branch[t]};i[r].branchs.push(c),delete i[r].quantity_branch}s=i.filter((function(t){if(t.quantity<=0)return!0}))}n(s)}))},t.prototype.getReportMaterials_byLowInStock=function(t){var e=this;return new Promise((function(n,o){var i=e.getlocalProducts(3),a=e.getlocalBranchs(),s=new Array;if("all"===t||void 0===t){for(var r=0;r<i.length;r++){i[r].quantity=0,i[r].branchs=new Array;for(var l=0;l<a.length;l++)if(void 0===i[r].quantity_branch[a[l]._id]&&(i[r].quantity_branch[a[l]._id]=0),i[r].quantity_branch[a[l]._id]<=i[r].warning_number){i[r].quantity=i[r].quantity+i[r].quantity_branch[a[l]._id];var c={id_branch:a[l]._id,name:a[l].name,quantity:i[r].quantity_branch[a[l]._id]};i[r].branchs.push(c)}delete i[r].quantity_branch}s=i.filter((function(t){return t.branchs.length>0}))}else{for(r=0;r<i.length;r++){i[r].quantity=0,i[r].branchs=new Array,void 0===i[r].quantity_branch[t]&&(i[r].quantity_branch[t]=0),i[r].quantity=i[r].quantity_branch[t];c={id_branch:t,name:e.getlocalBranch(t).name,quantity:i[r].quantity_branch[t]};i[r].branchs.push(c),delete i[r].quantity_branch}s=i.filter((function(t){if(t.quantity<=t.warning_number)return!0}))}n(s)}))},t.prototype.makeCorrectQuantityMaterials=function(){var t=this;return new Promise((function(e,n){var o=t.getlocalProducts(3),i=t.getlocalBranchs();t.vhmongo_firebase.database().getDocsByFields("vhbill_details",{ptype:{$eq:3},bill_type:{$in:[1,3,10,30,2,9,16,31]}},{},{date:1},0).then((function(n){if(o.length>0&&n.length>0){for(var a=new Array,s=0;s<o.length;s++){for(var r=0,l={},c=0;c<i.length;c++)l[i[c]._id]=0;for(var u=0;u<n.length;u++){var d=n[u];o[s]._id===d.id_product&&(1===d.bill_type||3===d.bill_type||10===d.bill_type||30===n[u].bill_type?(r-=d.quantity,null!=l[d.id_branch]?l[d.id_branch]=l[d.id_branch]-d.quantity:l[d.id_branch]=-d.quantity):2!==d.bill_type&&9!==d.bill_type&&16!==d.bill_type&&31!==n[u].bill_type||(r+=d.quantity,null!=l[d.id_branch]?l[d.id_branch]=l[d.id_branch]+d.quantity:l[d.id_branch]=d.quantity))}var _=!1;for(var p in o[s].quantity!=r&&(_=!0),o[s].quantity_branch)for(var b in l)p===b&&o[s].quantity_branch[p]===l[b]&&(_=!0);_&&a.push(t.updateProduct(o[s]._id,{quantity:r,quantity_branch:l}))}Promise.all(a).then((function(){e(null)}))}else e(null)}))}))},t.prototype.getReportInventoryTime_byTimes=function(t){var e=this;return new Promise((function(n,o){var i=e.getlocalInventorytime(t),a=e.getlocalProducts(3),s={docs:new Array,empty:!0,size:0};if(a.length>0){s={docs:new Array,empty:!0,size:0,total_stock:0,total_realstock:0,total_inventorynotes:new Array};var r=new Array,l=new Array,c=new Array,u=new Array,d={date:{$lte:i.date},ptype:{$eq:3},bill_type:{$in:[1,3,10,2,9,16]}};u[0]=e.vhmongo_firebase.database().getDocsByFields("vhbill_details",d,{},{date:1},0).then((function(t){r=E(t)}));var _={id_inventorytime:{$eq:t},bill_type:{$in:[13]}};u[1]=e.vhmongo_firebase.database().getDocsByFields("vhbill_details",_,{},{date:1},0).then((function(t){l=E(t)}));var p={id_inventorytime:{$eq:t},bill_type:{$in:[13]}};u[2]=e.vhmongo_firebase.database().getDocsByFields("bills",p,{},{date:1},0).then((function(t){c=E(t)})),Promise.all(u).then((function(){for(var t=0,e=0,o=new Array,i=0;i<c.length;i++){var u={bill_code:c[i].bill_code,quantity:0};o.push(u)}for(var d=function(n){if(3===a[n].type){for(var i=0,u=0;u<r.length;u++)a[n]._id===r[u].id_product&&(1===r[u].bill_type||3===r[u].bill_type||10===r[u].bill_type?i-=r[u].quantity:2!==r[u].bill_type&&9!==r[u].bill_type&&16!==r[u].bill_type||(i+=r[u].quantity));var d=new Array,_=0;for(u=0;u<c.length;u++){var p={bill_code:c[u].bill_code,quantity:0};d.push(p)}for(u=0;u<l.length;u++)for(var b=0;b<d.length;b++)a[n]._id===l[u].id_product&&d[b].bill_code===l[u].bill_code&&(d[b].quantity=l[u].quantity,_+=l[u].quantity,o[b].quantity=o[b].quantity+l[u].quantity);t+=i,e+=_;var f={_id:a[n]._id,data:function(){var t=a[n];return delete a[n]._id,t},stock:i,realstock:_,inventorynotes:d};s.docs.push(f),s.empty=!1,s.size++}},_=0;_<a.length;_++)d(_);s.total_stock=t,s.total_realstock=e,s.total_inventorynotes=E(o),n(s)}))}}))},t}();W.decorators=[{type:e.Injectable}],W.ctorParameters=function(){return[{type:o.Vhmongo_firebase},{type:V},{type:F},{type:L}]};var Q=function(){function t(t){this.vhmongo_firebase=t}return t.prototype.startLocalStorage=function(){return new Promise((function(t){t(null)}))},t.prototype.callbackMessagesFromChatStores=function(){return c.Observable.create((function(t){t.next()}))},t.prototype.removeAllCallback=function(){},t.prototype.connect=function(){},t.prototype.callbackChatStoreList=function(){var t=this;return c.Observable.create((function(e){t.callbackChatStore((function(){t.getchatStoreList().then((function(t){e.next(t)}))}))}))},t.prototype.callbackChatStore=function(t){t()},t.prototype.getchatStoreList=function(){return new Promise((function(t,e){t({})}))},t.prototype.selectChatStore=function(t){return new Promise((function(t,e){t(!0)}))},t.prototype.unselectChatStore=function(t){return new Promise((function(t,e){t(!0)}))},t.prototype.finishChatStore=function(t){return new Promise((function(t,e){t(!0)}))},t.prototype.connectChatStore=function(t){},t.prototype.sendMessageToChatStore=function(t,e){},t.prototype.sendImageToChatStore=function(t,e){},t}();Q.decorators=[{type:e.Injectable}],Q.ctorParameters=function(){return[{type:o.Vhmongo_firebase}]};var J=function(){function t(t,e,n,o){var i=this;this.vhmongo_firebase=t,this.vhQuery=e,this.vhAuth=n,this.vhAlgorithm=o,this.utoken=null,this.cameras=new Array,this.cloudcams=new Array,this.rooms=new Array,this.mainboards=new Array,this.functions=new Array,this.components=new Array,this.icons=new Array,this.appsettingstations=new Array,this.scripts=new Array,this.script_details=new Array,this.logs=new Array,this.hwinfo={},this.subjectcameras=new c.Subject,this.subjectappsettingstations=new c.Subject,this.subjectrooms=new c.Subject,this.subjectmainboards=new c.Subject,this.subjectfunctions=new c.Subject,this.subjecticons=new c.Subject,this.subjectcomponents=new c.Subject,r.Device.getId().then((function(t){var e=i.vhAuth.localStorageGET("hwinfo");null!=e&&null!=e?i.hwinfo=e:(i.hwinfo=Object.assign({},t),i.vhAuth.localStorageSET("hwinfo",i.hwinfo))}))}return t.prototype.syncCollections=function(){var t=this;return new Promise((function(e,n){t.initSyncCollections(),t.callbackCollectionInsert().subscribe(),t.callbackCollectionUpdate().subscribe(),t.callbackCollectionDelete().subscribe(),t.getEUtokenfromDatabase(),setTimeout((function(){e(!0)}),5e3)}))},t.prototype.initSyncCollections=function(){var t=new Array;return t[0]="rooms",t[1]="mainboards",t[2]="components",t[3]="icons",t[4]="functions",t[5]="vhemployees",t[6]="appsettingstations",this.vhmongo_firebase.socketMongoDB().initSyncCollections(t)},t.prototype.closeSyncCollections=function(){this.vhmongo_firebase.socketMongoDB().closeSyncCollections()},t.prototype.callbackCollectionInsert=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackCollectionInsert().subscribe((function(n){if("vhemployees"===n.colname?n.colname="employees":"appsettingstations"===n.colname&&(n.colname="appsettingstations"),"cameras"===n.colname)t.getlocalCamera(n._id)||((o=Object.assign({},n.data))._id=n._id,t.cameras.push(o),t.publishObservableEventCameras(),e.next(n.colname));else if("rooms"===n.colname){if(!t.getlocalRoom(n._id))(o=Object.assign({},n.data))._id=n._id,t.rooms.push(o),t.publishObservableEventRooms(),e.next(n.colname)}else if("mainboards"===n.colname){if(!t.getlocalMainboard(n._id))(o=Object.assign({},n.data))._id=n._id,t.mainboards.push(o),t.publishObservableEventMainboards(),e.next(n.colname)}else if("components"===n.colname){if(!t.getlocalComponent(n._id))(o=Object.assign({},n.data))._id=n._id,t.components.push(o),t.publishObservableEventComponents(),e.next(n.colname)}else if("icons"===n.colname){if(!t.getlocalIcon(n._id))(o=Object.assign({},n.data))._id=n._id,t.icons.push(o),t.publishObservableEventIcons(),e.next(n.colname)}else if("functions"===n.colname){if(!t.getlocalFunction(n._id))(o=Object.assign({},n.data))._id=n._id,t.functions.push(o),t.publishObservableEventFunctions(),e.next(n.colname)}else if("employees"===n.colname){(o=Object.assign({},n.data))._id=n._id,t.vhAuth.insertlocalEmployeeFromSyncCollection(o),t.vhAuth.publishObservableEventEmployees(),e.next(n.colname)}else if("appsettingstations"===n.colname){var o;if(!t.getLocalAppSettingStation(n._id))if(n.data.uuid===t.hwinfo.uuid)(o=Object.assign({},n.data))._id=n._id,delete o.uuid,t.appsettingstations.push(o),t.publishObservableEventAppSettingNameStations(),e.next(n.colname)}console.log("inserted",n.colname)}))}))},t.prototype.callbackCollectionUpdate=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackCollectionUpdate().subscribe((function(n){if("vhemployees"===n.colname?n.colname="employees":"appsettingstations"===n.colname&&(n.colname="appsettingstations"),"cameras"===n.colname){for(var o=0;o<t.cameras.length;o++)if(t.cameras[o]._id===n._id){t.cameras[o]=Object.assign(Object.assign({},t.cameras[o]),n.data),t.publishObservableEventCameras(),e.next(n.colname);break}}else if("rooms"===n.colname){for(o=0;o<t.rooms.length;o++)if(t.rooms[o]._id===n._id){t.rooms[o]=Object.assign(Object.assign({},t.rooms[o]),n.data),t.publishObservableEventRooms(),e.next(n.colname);break}}else if("mainboards"===n.colname){for(o=0;o<t.mainboards.length;o++)if(t.mainboards[o]._id===n._id){t.mainboards[o]=Object.assign(Object.assign({},t.mainboards[o]),n.data),t.publishObservableEventMainboards(),e.next(n.colname);break}}else if("components"===n.colname){for(o=0;o<t.components.length;o++)if(t.rooms[o]._id===n._id){t.rooms[o]=Object.assign(Object.assign({},t.components[o]),n.data),t.publishObservableEventComponents(),e.next(n.colname);break}}else if("icons"===n.colname){for(o=0;o<t.icons.length;o++)if(t.icons[o]._id===n._id){t.icons[o]=Object.assign(Object.assign({},t.icons[o]),n.data),t.publishObservableEventIcons(),e.next(n.colname);break}}else if("functions"===n.colname){for(o=0;o<t.icons.functions;o++)if(t.functions[o]._id===n._id){t.functions[o]=Object.assign(Object.assign({},t.functions[o]),n.data),t.publishObservableEventFunctions(),e.next(n.colname);break}}else if("employees"===n.colname)t.vhAuth.updateLocalEmployeeFromSyncCollection(n._id,n.data),t.vhAuth.publishObservableEventEmployees(),e.next(n.colname);else if("appsettingstations"===n.colname)for(o=0;o<t.appsettingstations.length;o++)if(t.appsettingstations[o]._id===n._id){t.appsettingstations[o]=Object.assign(Object.assign({},t.appsettingstations[o]),n.data),t.publishObservableEventAppSettingNameStations(),e.next(n.colname);break}console.log("updated",n.colname)}))}))},t.prototype.callbackCollectionDelete=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackCollectionDelete().subscribe((function(n){if("vhemployees"===n.colname?n.colname="employees":"appsettingstations"===n.colname&&(n.colname="appsettingstations"),"cameras"===n.colname){for(var o=0;o<t.cameras.length;o++)if(t.cameras[o]._id===n._id){t.cameras.splice(o,1),t.publishObservableEventCameras(),e.next(n.colname);break}}else if("rooms"===n.colname){for(o=0;o<t.rooms.length;o++)if(t.rooms[o]._id===n._id){t.rooms.splice(o,1),t.publishObservableEventRooms(),e.next(n.colname);break}}else if("mainboards"===n.colname){for(o=0;o<t.mainboards.length;o++)if(t.mainboards[o]._id===n._id){t.mainboards.splice(o,1),t.publishObservableEventMainboards(),e.next(n.colname);break}}else if("components"===n.colname){for(o=0;o<t.components.length;o++)if(t.components[o]._id===n._id){t.components.splice(o,1),t.publishObservableEventComponents(),e.next(n.colname);break}}else if("icons"===n.colname){for(o=0;o<t.icons.length;o++)if(t.icons[o]._id===n._id){t.icons.splice(o,1),t.publishObservableEventIcons(),e.next(n.colname);break}}else if("functions"===n.colname){for(o=0;o<t.functions.length;o++)if(t.functions[o]._id===n._id){t.functions.splice(o,1),t.publishObservableEventFunctions(),e.next(n.colname);break}}else if("employees"===n.colname)t.vhAuth.deleteLocalEmployeeFromSyncCollection(n._id),t.vhAuth.publishObservableEventEmployees(),e.next(n.colname);else if("appsettingstations"===n.colname)for(o=0;o<t.appsettingstations.length;o++)if(t.appsettingstations[o]._id===n._id){t.appsettingstations.splice(o,1),t.publishObservableEventAppSettingNameStations(),e.next(n.colname);break}console.log("deleted",n.colname)}))}))},t.prototype.startLocalStorage=function(){var t=this;return new Promise((function(e){var n=new Array;n[0]=t.vhAuth.refreshLocalMyPermission(),n[1]=t.refreshLocalCloudCams(),n[2]=t.getEUtokenfromDatabase(),t.vhQuery.asyncPromiseAll(n).then((function(){e(null)}))}))},t.prototype.getCloudCamServer=function(){return this.vhmongo_firebase.f3rdclouds().getCloudCamServer()},t.prototype.createPaymentVnpay=function(t,e,n,o,i,a){var s={projectName:this.vhmongo_firebase.auth().getProjectName(),sid:this.vhmongo_firebase.auth().getDatabase(),data:n};this.vhmongo_firebase.f3rdclouds().createPaymentVnpay(t,e,"billpayment","thanh toan","vn",s,o,i,a).then((function(t){window.location=t.data}),(function(t){console.log("error",t)}))},t.prototype.getDiscountFromCode=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.f3rdclouds().getDiscountFromCode(t).then((function(t){t.size>0?n(t.docs[0].data().discount):n(0)}),(function(t){console.error(t),o(t)}))}))},t.prototype.getPriceList_Records=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.clouds().getPriceList_Records().then((function(n){var o=new Array;n.size>0&&n.forEach((function(t){o.push(t.data()),o[o.length-1]._id=t.id})),o=t.vhAlgorithm.sortNumberbyASC(o,"month"),e(o)}),(function(t){console.error(t),n(t)}))}))},t.prototype.getPriceList_Detectors=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.clouds().getPriceList_Detectors().then((function(n){var o=new Array;n.size>0&&n.forEach((function(t){o.push(t.data()),o[o.length-1]._id=t.id})),o=t.vhAlgorithm.sortNumberbyASC(o,"month"),e(o)}),(function(t){console.error(t),n(t)}))}))},t.prototype.getPriceList_rLPRs=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.clouds().getPriceList_rLPRs().then((function(n){var o=new Array;n.size>0&&n.forEach((function(t){o.push(t.data()),o[o.length-1]._id=t.id})),o=t.vhAlgorithm.sortNumberbyASC(o,"month"),e(o)}),(function(t){console.error(t),n(t)}))}))},t.prototype.getPriceList_cLPRs=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.clouds().getPriceList_cLPRs().then((function(n){var o=new Array;n.size>0&&n.forEach((function(t){o.push(t.data()),o[o.length-1]._id=t.id})),o=t.vhAlgorithm.sortNumberbyASC(o,"month"),e(o)}),(function(t){console.error(t),n(t)}))}))},t.prototype.publishObservableEventCameras=function(){this.subjectcameras.next(this.cameras)},t.prototype.observableLocalCameras=function(){return this.subjectcameras},t.prototype.getObservableLocalCameras=function(){var t=this;return new c.Observable((function(e){t.observableLocalCameras().subscribe((function(t){e.next(t)})),t.publishObservableEventCameras()}))},t.prototype.getlocalCamera=function(t){for(var e=0;e<this.cameras.length;e++)if(this.cameras[e]._id===t)return this.cameras[e];return null},t.prototype.getlocalCameras=function(){return this.cameras},t.prototype.refreshLocalCameras=function(){var t=this;return new Promise((function(e){t.getCameras().then((function(){e(null)}))}))},t.prototype.createLicenseCam=function(){return new Promise((function(t,e){}))},t.prototype.addCamera=function(t){return new Promise((function(t,e){}))},t.prototype.updateCamera=function(t,e){var n=this;return new Promise((function(e,o){n.vhmongo_firebase.database().getDoc("cameras",t).then((function(t){}),(function(t){o(t)}))}))},t.prototype.deleteCamera=function(t){return new Promise((function(t,e){}))},t.prototype.getCamera=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("cameras",t).then((function(t){n(t)}))}))},t.prototype.getCameras=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("cameras").then((function(n){t.cameras=new Array,t.cameras=n,e(n)}),(function(t){n(t)}))}))},t.prototype.getFee_detailsByFields=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.database().getDocsByFields_onRootCollectionsFirebase("fee_details",t,{},n,o).then((function(t){e(t)}),(function(t){a(t)}))}))},t.prototype.getFeesByFields=function(t,e,n,o){var i=this;return new Promise((function(e,a){t.database={database:{$eq:i.vhmongo_firebase.auth().getDatabase()}},i.vhmongo_firebase.database().getDocsByFields_onRootCollectionsFirebase("fees",t,{},n,o).then((function(t){e(t)}),(function(t){a(t)}))}))},t.prototype.getFee=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc_onRootCollectionsFirebase("fees",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getFee_Details=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields_onRootCollectionsFirebase("fee_details",{id_fee:{$eq:t}},{},{},0).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.importUtoken=function(t){this.vhmongo_firebase.f3rdclouds().importUtoken(t)},t.prototype.getLocalEUtoken=function(){return this.vhmongo_firebase.f3rdclouds().getLocalEUtoken()},t.prototype.getEUtokenfromDatabase=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.f3rdclouds().getEUtokenfromDatabase().then((function(){e(null)}))}))},t.prototype.checkExpiredUtoken=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.f3rdclouds().checkExpiredUtoken().then((function(t){0===t.vcode?e(!0):(console.log(t.message),e(!1))}))}))},t.prototype.getlocalCloudCam=function(t){for(var e=0;e<this.cloudcams.length;e++)if(this.cloudcams[e].licensecam===t)return this.cloudcams[e];return null},t.prototype.getlocalCloudCams=function(){return this.cloudcams},t.prototype.refreshLocalCloudCams=function(){var t=this;return new Promise((function(e){t.getCloudCamsByEndUser().then((function(){e(null)}))}))},t.prototype.changeCloudCamEnableCLPRbyEndUser=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().changeCloudCamEnableCLPRbyEndUser(t,e).then((function(t){0===t.vcode?o(!0):(console.log(t.message),o(!1))}))}))},t.prototype.changeCloudCamEnableRLPRbyEndUser=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().changeCloudCamEnableRLPRbyEndUser(t,e).then((function(t){0===t.vcode?o(!0):(console.log(t.message),o(!1))}))}))},t.prototype.changeCloudCamEnableDetectorByEndUser=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().changeCloudCamEnableDetectorByEndUser(t,e).then((function(t){0===t.vcode?o(!0):(console.log(t.message),o(!1))}))}))},t.prototype.changeCloudCamEnableRecordByEndUser=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().changeCloudCamEnableRecordByEndUser(t,e).then((function(t){0===t.vcode?o(!0):(console.log(t.message),o(!1))}))}))},t.prototype.changeCloudCamEnableActiveByEndUser=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().changeCloudCamEnableActiveByEndUser(t,e).then((function(t){0===t.vcode?o(!0):(console.log(t.message),o(!1))}))}))},t.prototype.changeCloudCamURLbyEndUser=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().changeCloudCamURLbyEndUser(t,e).then((function(t){0===t.vcode?o(!0):(console.log(t.message),o(!1))}))}))},t.prototype.addCloudCamByEndUser=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().addCloudCamByEndUser(t,e).then((function(t){0===t.vcode?o(t.data):(console.log(t.message),o(null))}))}))},t.prototype.addCloudCamBoxByEndUser=function(t,e,n){var o=this;return new Promise((function(i){o.vhmongo_firebase.f3rdclouds().addCloudCamBoxByEndUser(t,e,n).then((function(t){0===t.vcode?i(t.data):(console.log(t.message),i(null))}))}))},t.prototype.updateCloudCamDataByEndUser=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().updateCloudCamDataByEndUser(t,e).then((function(t){0===t.vcode?o(!0):(console.log(t.message),o(!1))}))}))},t.prototype.deleteCloudCamByEndUser=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.f3rdclouds().deleteCloudCamByEndUser(t).then((function(t){0===t.vcode?n(!0):(console.log(t.message),n(!1))}))}))},t.prototype.getCloudCamByEndUser=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.f3rdclouds().getCloudCamByEndUser(t).then((function(t){0===t.vcode?n(t.data):(console.log(t.message),n(null))}))}))},t.prototype.getCloudCamsByEndUser=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.f3rdclouds().getCloudCamsByEndUser().then((function(n){0===n.vcode?t.cloudcams=n.data:(console.log(n.message),t.cloudcams=new Array),e(t.cloudcams)}),(function(t){n(t)}))}))},t.prototype.getPlaybackListCamByEndUser=function(t,e,n,o){var i=this;return new Promise((function(a,s){i.vhmongo_firebase.f3rdclouds().getPlaybackListCambyEndUser(t,e,n,o).then((function(t){0===t.vcode?a(t.data):(console.log(t),a([]))}),(function(t){s(t)}))}))},t.prototype.publishObservableEventRooms=function(){this.subjectrooms.next(this.rooms)},t.prototype.observableLocalRooms=function(){return this.subjectrooms},t.prototype.getObservableLocalRooms=function(){var t=this;return new c.Observable((function(e){t.observableLocalRooms().subscribe((function(t){e.next(t)})),t.publishObservableEventRooms()}))},t.prototype.getlocalRoom=function(t){for(var e=0;e<this.rooms.length;e++)if(this.rooms[e]._id===t)return this.rooms[e];return null},t.prototype.getlocalRooms=function(){return this.rooms},t.prototype.refreshLocalRooms=function(){var t=this;return new Promise((function(e){t.getRooms().then((function(){e(null)}))}))},t.prototype.addRoom=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("rooms",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateRoom=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("rooms",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteRoom=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("rooms",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getRoom=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("rooms",t).then((function(t){n(t)}))}))},t.prototype.getRooms=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("rooms").then((function(n){t.rooms=new Array,t.rooms=n,e(n)}),(function(t){n(t)}))}))},t.prototype.getlocalLog=function(t){for(var e=0;e<this.logs.length;e++)if(this.logs[e]._id===t)return this.logs[e];return null},t.prototype.getlocalLogs=function(){return this.logs},t.prototype.refreshLocalLogs=function(){var t=this;return new Promise((function(e){t.getLogs().then((function(){e(null)}))}))},t.prototype.addLog=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("logs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateLog=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("logs",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteLog=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("logs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getLog=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("logs",t).then((function(t){n(t)}))}))},t.prototype.getLogs=function(){var t=this;return new Promise((function(e,n){t.logs=new Array,t.vhmongo_firebase.database().getDocs("logs").then((function(n){t.logs=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventMainboards=function(){this.subjectmainboards.next(this.mainboards)},t.prototype.observableLocalMainboards=function(){return this.subjectmainboards},t.prototype.getObservableLocalMainboards=function(){var t=this;return new c.Observable((function(e){t.observableLocalMainboards().subscribe((function(t){e.next(t)})),t.publishObservableEventMainboards()}))},t.prototype.getlocalMainboard=function(t){for(var e=0;e<this.mainboards.length;e++)if(this.mainboards[e]._id===t)return this.mainboards[e];return null},t.prototype.getlocalMainboards=function(){return this.mainboards},t.prototype.refreshLocalMainboards=function(){var t=this;return new Promise((function(e){t.getMainboards().then((function(){e(null)}))}))},t.prototype.addMainboard=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("mainboards",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateMainboard=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("mainboards",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteMainboard=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("mainboards",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getMainboard=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("mainboards",t).then((function(t){n(t)}))}))},t.prototype.getMainboards=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("mainboards").then((function(n){t.mainboards=new Array,t.mainboards=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventFunctions=function(){this.subjectfunctions.next(this.functions)},t.prototype.observableLocalFunctions=function(){return this.subjectfunctions},t.prototype.getObservableLocalFunctions=function(){var t=this;return new c.Observable((function(e){t.observableLocalFunctions().subscribe((function(t){e.next(t)})),t.publishObservableEventFunctions()}))},t.prototype.getlocalFunction=function(t){for(var e=0;e<this.functions.length;e++)if(this.functions[e]._id===t)return this.functions[e];return null},t.prototype.getlocalFunctions=function(){return this.functions},t.prototype.refreshLocalFunctions=function(){var t=this;return new Promise((function(e){t.getFunctions().then((function(){e(null)}))}))},t.prototype.addFunction=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("functions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateFunction=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("functions",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteFunction=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("functions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getFunction=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("functions",t).then((function(t){n(t)}))}))},t.prototype.getFunctions=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("functions").then((function(n){t.functions=new Array,t.functions=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventComponents=function(){this.subjectcomponents.next(this.components)},t.prototype.observableLocalComponents=function(){return this.subjectcomponents},t.prototype.getObservableLocalComponents=function(){var t=this;return new c.Observable((function(e){t.observableLocalComponents().subscribe((function(t){e.next(t)})),t.publishObservableEventComponents()}))},t.prototype.getlocalComponent=function(t){for(var e=0;e<this.components.length;e++)if(this.components[e]._id===t)return this.components[e];return null},t.prototype.getlocalComponents=function(){return this.components},t.prototype.refreshLocalComponents=function(){var t=this;return new Promise((function(e){t.getComponents().then((function(){e(null)}))}))},t.prototype.addComponent=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("components",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateComponent=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("components",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteComponent=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("components",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getComponent=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("components",t).then((function(t){n(t)}))}))},t.prototype.getComponents=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("components").then((function(n){t.components=new Array,t.components=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventIcons=function(){this.subjecticons.next(this.icons)},t.prototype.observableLocalIcons=function(){return this.subjecticons},t.prototype.getObservableLocalIcons=function(){var t=this;return new c.Observable((function(e){t.observableLocalIcons().subscribe((function(t){e.next(t)})),t.publishObservableEventIcons()}))},t.prototype.getlocalIcon=function(t){for(var e=0;e<this.icons.length;e++)if(this.icons[e]._id===t)return this.icons[e];return null},t.prototype.getlocalIcons=function(){return this.icons},t.prototype.refreshLocalIcons=function(){var t=this;return new Promise((function(e){t.getIcons().then((function(){e(null)}))}))},t.prototype.addIcon=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("icons",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateIcon=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("icons",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteIcon=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("icons",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getIcon=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("icons",t).then((function(t){n(t)}))}))},t.prototype.getIcons=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("icons").then((function(n){t.icons=new Array,t.icons=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventAppSettingNameStations=function(){this.subjectappsettingstations.next()},t.prototype.observableLocalAppSettingNameStations=function(){return this.subjectappsettingstations},t.prototype.getObservableLocalAppSettingNameStations=function(){var t=this;return new c.Observable((function(e){t.observableLocalAppSettingNameStations().subscribe((function(){for(var n=new Array,o=0;o<t.appsettingstations.length;o++)n.push(t.appsettingstations[o].appsetting_name);e.next(n)})),t.publishObservableEventAppSettingNameStations()}))},t.prototype.getLocalAppSettingNameStations=function(){for(var t=new Array,e=0;e<this.appsettingstations.length;e++)t.push(this.appsettingstations[e].appsetting_name);return t},t.prototype.getLocalAppSettingNameStation=function(t){for(var e={},n=0;n<this.appsettingstations.length;n++)if(this.appsettingstations[n].appsetting_name===t){delete(e=Object.assign({},this.appsettingstations[n]))._id,delete e.appsetting_name;break}return e},t.prototype.getLocalAppSettingStation=function(t){for(var e=0;e<this.appsettingstations.length;e++)if(this.appsettingstations[e]._id===t)return this.appsettingstations[e];return null},t.prototype.refreshLocalAppSettingNameStations=function(){return new Promise((function(t,e){t(null)}))},t.prototype.getAppSettingStations=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocsByFields("appsettingstations",{uuid:{$eq:t.hwinfo.uuid}},{},{},0).then((function(n){n.length>0&&(t.appsettingstations=n),e(null)}),(function(t){n(t)}))}))},t.prototype.updateAppSettingNameStation=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().getDocsByFields("appsettingstations",{appsetting_name:{$eq:t},uuid:{$eq:n.hwinfo.uuid}},{},{},0).then((function(a){if(a.length>0)n.vhmongo_firebase.database().updateDoc("appsettingstations",a[0]._id,e).then((function(t){o(t)}),(function(t){i(t)}));else{var s=Object.assign({},e);s.appsetting_name=t,s.uuid=n.hwinfo.uuid,n.vhmongo_firebase.database().addDoc("appsettingstations",s).then((function(){o(!0)}),(function(t){i(t)}))}}))}))},t.prototype.deleteAppSettingNameStation=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("appsettingstations",{appsetting_name:{$eq:t},uuid:{$eq:e.hwinfo.uuid}},{},{},0).then((function(t){t.length>0?e.vhmongo_firebase.database().deleteDoc("appsettingstations",t[0]._id).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}))}))},t.prototype.getlocalScript=function(t){for(var e=0;e<this.scripts.length;e++)if(this.scripts[e]._id===t)return this.scripts[e];return null},t.prototype.getlocalScripts=function(){return this.scripts},t.prototype.refreshLocalScripts=function(){var t=this;return new Promise((function(e){t.getScripts().then((function(){e(null)}))}))},t.prototype.addScript=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("scripts",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateScript=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("scripts",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteScript=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("scripts",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getScript=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("scripts",t).then((function(t){n(t)}))}))},t.prototype.getScripts=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("scripts").then((function(n){t.scripts=new Array,t.scripts=n,e(n)}),(function(t){n(t)}))}))},t.prototype.getlocalScript_detail=function(t){for(var e=0;e<this.script_details.length;e++)if(this.script_details[e]._id===t)return this.script_details[e];return null},t.prototype.getlocalScript_details=function(){return this.script_details},t.prototype.refreshLocalScript_details=function(){var t=this;return new Promise((function(e){t.getScript_details().then((function(){e(null)}))}))},t.prototype.addScript_detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("script_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateScript_detail=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("script_details",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteScript_detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("script_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getScript_detail=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("script_details",t).then((function(t){n(t)}))}))},t.prototype.getScript_details=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("script_details").then((function(n){t.script_details=new Array,t.script_details=n,e(n)}),(function(t){n(t)}))}))},t}();J.decorators=[{type:e.Injectable}],J.ctorParameters=function(){return[{type:o.Vhmongo_firebase},{type:V},{type:F},{type:L}]};var H=function(){function t(t,e,n,o){var i=this;this.vhmongo_firebase=t,this.vhQuery=e,this.vhAuth=n,this.vhAlgorithm=o,this.designs=new Array,this.cameras=new Array,this.cloudcams=new Array,this.rooms=new Array,this.mainboards=new Array,this.functions=new Array,this.components=new Array,this.icons=new Array,this.appsettingstations=new Array,this.scripts=new Array,this.script_details=new Array,this.logs=new Array,this.hwinfo={},this.subjectcameras=new c.Subject,this.subjectappsettingstations=new c.Subject,this.subjectrooms=new c.Subject,this.subjectmainboards=new c.Subject,this.subjectfunctions=new c.Subject,this.subjecticons=new c.Subject,this.subjectcomponents=new c.Subject,r.Device.getId().then((function(t){var e=i.vhAuth.localStorageGET("hwinfo");null!=e&&null!=e?i.hwinfo=e:(i.hwinfo=Object.assign({},t),i.vhAuth.localStorageSET("hwinfo",i.hwinfo))}))}return t.prototype.syncCollections=function(){var t=this;return new Promise((function(e,n){t.initSyncCollections(),t.callbackCollectionInsert().subscribe(),t.callbackCollectionUpdate().subscribe(),t.callbackCollectionDelete().subscribe(),t.getUtokenByUser(),setTimeout((function(){e(!0)}),3e3)}))},t.prototype.initSyncCollections=function(){var t=new Array;return t[0]="rooms",t[1]="mainboards",t[2]="components",t[3]="icons",t[4]="functions",t[5]="vhemployees",t[6]="appsettingstations",this.vhmongo_firebase.socketMongoDB().initSyncCollections(t)},t.prototype.closeSyncCollections=function(){this.vhmongo_firebase.socketMongoDB().closeSyncCollections()},t.prototype.callbackCollectionInsert=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackCollectionInsert().subscribe((function(n){if("vhemployees"===n.colname?n.colname="employees":"appsettingstations"===n.colname&&(n.colname="appsettingstations"),"cameras"===n.colname)t.getlocalCamera(n._id)||((o=Object.assign({},n.data))._id=n._id,t.cameras.push(o),t.publishObservableEventCameras(),e.next(n.colname));else if("rooms"===n.colname){if(!t.getlocalRoom(n._id))(o=Object.assign({},n.data))._id=n._id,t.rooms.push(o),t.publishObservableEventRooms(),e.next(n.colname)}else if("mainboards"===n.colname){if(!t.getlocalMainboard(n._id))(o=Object.assign({},n.data))._id=n._id,t.mainboards.push(o),t.publishObservableEventMainboards(),e.next(n.colname)}else if("components"===n.colname){if(!t.getlocalComponent(n._id))(o=Object.assign({},n.data))._id=n._id,t.components.push(o),t.publishObservableEventComponents(),e.next(n.colname)}else if("icons"===n.colname){if(!t.getlocalIcon(n._id))(o=Object.assign({},n.data))._id=n._id,t.icons.push(o),t.publishObservableEventIcons(),e.next(n.colname)}else if("functions"===n.colname){if(!t.getlocalFunction(n._id))(o=Object.assign({},n.data))._id=n._id,t.functions.push(o),t.publishObservableEventFunctions(),e.next(n.colname)}else if("employees"===n.colname){(o=Object.assign({},n.data))._id=n._id,t.vhAuth.insertlocalEmployeeFromSyncCollection(o),t.vhAuth.publishObservableEventEmployees(),e.next(n.colname)}else if("appsettingstations"===n.colname){var o;if(!t.getLocalAppSettingStation(n._id))if(n.data.uuid===t.hwinfo.uuid)(o=Object.assign({},n.data))._id=n._id,delete o.uuid,t.appsettingstations.push(o),t.publishObservableEventAppSettingNameStations(),e.next(n.colname)}console.log("inserted",n.colname)}))}))},t.prototype.callbackCollectionUpdate=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackCollectionUpdate().subscribe((function(n){if("vhemployees"===n.colname?n.colname="employees":"appsettingstations"===n.colname&&(n.colname="appsettingstations"),"cameras"===n.colname){for(var o=0;o<t.cameras.length;o++)if(t.cameras[o]._id===n._id){t.cameras[o]=Object.assign(Object.assign({},t.cameras[o]),n.data),t.publishObservableEventCameras(),e.next(n.colname);break}}else if("rooms"===n.colname){for(o=0;o<t.rooms.length;o++)if(t.rooms[o]._id===n._id){t.rooms[o]=Object.assign(Object.assign({},t.rooms[o]),n.data),t.publishObservableEventRooms(),e.next(n.colname);break}}else if("mainboards"===n.colname){for(o=0;o<t.mainboards.length;o++)if(t.mainboards[o]._id===n._id){t.mainboards[o]=Object.assign(Object.assign({},t.mainboards[o]),n.data),t.publishObservableEventMainboards(),e.next(n.colname);break}}else if("components"===n.colname){for(o=0;o<t.components.length;o++)if(t.rooms[o]._id===n._id){t.rooms[o]=Object.assign(Object.assign({},t.components[o]),n.data),t.publishObservableEventComponents(),e.next(n.colname);break}}else if("icons"===n.colname){for(o=0;o<t.icons.length;o++)if(t.icons[o]._id===n._id){t.icons[o]=Object.assign(Object.assign({},t.icons[o]),n.data),t.publishObservableEventIcons(),e.next(n.colname);break}}else if("functions"===n.colname){for(o=0;o<t.icons.functions;o++)if(t.functions[o]._id===n._id){t.functions[o]=Object.assign(Object.assign({},t.functions[o]),n.data),t.publishObservableEventFunctions(),e.next(n.colname);break}}else if("employees"===n.colname)t.vhAuth.updateLocalEmployeeFromSyncCollection(n._id,n.data),t.vhAuth.publishObservableEventEmployees(),e.next(n.colname);else if("appsettingstations"===n.colname)for(o=0;o<t.appsettingstations.length;o++)if(t.appsettingstations[o]._id===n._id){t.appsettingstations[o]=Object.assign(Object.assign({},t.appsettingstations[o]),n.data),t.publishObservableEventAppSettingNameStations(),e.next(n.colname);break}console.log("updated",n.colname)}))}))},t.prototype.callbackCollectionDelete=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackCollectionDelete().subscribe((function(n){if("vhemployees"===n.colname?n.colname="employees":"appsettingstations"===n.colname&&(n.colname="appsettingstations"),"cameras"===n.colname){for(var o=0;o<t.cameras.length;o++)if(t.cameras[o]._id===n._id){t.cameras.splice(o,1),t.publishObservableEventCameras(),e.next(n.colname);break}}else if("rooms"===n.colname){for(o=0;o<t.rooms.length;o++)if(t.rooms[o]._id===n._id){t.rooms.splice(o,1),t.publishObservableEventRooms(),e.next(n.colname);break}}else if("mainboards"===n.colname){for(o=0;o<t.mainboards.length;o++)if(t.mainboards[o]._id===n._id){t.mainboards.splice(o,1),t.publishObservableEventMainboards(),e.next(n.colname);break}}else if("components"===n.colname){for(o=0;o<t.components.length;o++)if(t.components[o]._id===n._id){t.components.splice(o,1),t.publishObservableEventComponents(),e.next(n.colname);break}}else if("icons"===n.colname){for(o=0;o<t.icons.length;o++)if(t.icons[o]._id===n._id){t.icons.splice(o,1),t.publishObservableEventIcons(),e.next(n.colname);break}}else if("functions"===n.colname){for(o=0;o<t.functions.length;o++)if(t.functions[o]._id===n._id){t.functions.splice(o,1),t.publishObservableEventFunctions(),e.next(n.colname);break}}else if("employees"===n.colname)t.vhAuth.deleteLocalEmployeeFromSyncCollection(n._id),t.vhAuth.publishObservableEventEmployees(),e.next(n.colname);else if("appsettingstations"===n.colname)for(o=0;o<t.appsettingstations.length;o++)if(t.appsettingstations[o]._id===n._id){t.appsettingstations.splice(o,1),t.publishObservableEventAppSettingNameStations(),e.next(n.colname);break}console.log("deleted",n.colname)}))}))},t.prototype.startLocalStorage=function(){var t=this;return new Promise((function(e){var n=new Array;n[0]=t.vhAuth.refreshLocalMyPermission(),n[1]=t.refreshLocalCloudCams(),t.vhQuery.asyncPromiseAll(n).then((function(){e(null)}))}))},t.prototype.createPaymentVnpay=function(t,e,n,o,i,a){var s={projectName:this.vhmongo_firebase.auth().getProjectName(),sid:this.vhmongo_firebase.auth().getDatabase(),data:n};this.vhmongo_firebase.clouds().createPaymentVnpay(t,e,"billpayment","thanh toan","vn",s,o,i,a).then((function(t){window.location=t.data}),(function(t){console.log("error",t)}))},t.prototype.getDiscountFromCode=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.clouds().getDiscountFromCode(t).then((function(t){t.size>0?n(t.docs[0].data().discount):n(0)}),(function(t){console.error(t),o(t)}))}))},t.prototype.getPriceList_Records=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.clouds().getPriceList_Records().then((function(n){var o=new Array;n.size>0&&n.forEach((function(t){o.push(t.data()),o[o.length-1]._id=t.id})),o=t.vhAlgorithm.sortNumberbyASC(o,"month"),e(o)}),(function(t){console.error(t),n(t)}))}))},t.prototype.getPriceList_Detectors=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.clouds().getPriceList_Detectors().then((function(n){var o=new Array;n.size>0&&n.forEach((function(t){o.push(t.data()),o[o.length-1]._id=t.id})),o=t.vhAlgorithm.sortNumberbyASC(o,"month"),e(o)}),(function(t){console.error(t),n(t)}))}))},t.prototype.getPriceList_rLPRs=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.clouds().getPriceList_rLPRs().then((function(n){var o=new Array;n.size>0&&n.forEach((function(t){o.push(t.data()),o[o.length-1]._id=t.id})),o=t.vhAlgorithm.sortNumberbyASC(o,"month"),e(o)}),(function(t){console.error(t),n(t)}))}))},t.prototype.getPriceList_cLPRs=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.clouds().getPriceList_cLPRs().then((function(n){var o=new Array;n.size>0&&n.forEach((function(t){o.push(t.data()),o[o.length-1]._id=t.id})),o=t.vhAlgorithm.sortNumberbyASC(o,"month"),e(o)}),(function(t){console.error(t),n(t)}))}))},t.prototype.publishObservableEventCameras=function(){this.subjectcameras.next(this.cameras)},t.prototype.observableLocalCameras=function(){return this.subjectcameras},t.prototype.getObservableLocalCameras=function(){var t=this;return new c.Observable((function(e){t.observableLocalCameras().subscribe((function(t){e.next(t)})),t.publishObservableEventCameras()}))},t.prototype.getlocalCamera=function(t){for(var e=0;e<this.cameras.length;e++)if(this.cameras[e]._id===t)return this.cameras[e];return null},t.prototype.getlocalCameras=function(){return this.cameras},t.prototype.refreshLocalCameras=function(){var t=this;return new Promise((function(e){t.getCameras().then((function(){e(null)}))}))},t.prototype.createLicenseCam=function(){return new Promise((function(t,e){}))},t.prototype.addCamera=function(t){return new Promise((function(t,e){}))},t.prototype.updateCamera=function(t,e){return new Promise((function(t,e){}))},t.prototype.deleteCamera=function(t){return new Promise((function(t,e){}))},t.prototype.getCamera=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("cameras",t).then((function(t){n(t)}))}))},t.prototype.getCameras=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("cameras").then((function(n){t.cameras=new Array,t.cameras=n,e(n)}),(function(t){n(t)}))}))},t.prototype.getlocalCloudCam=function(t){for(var e=0;e<this.cloudcams.length;e++)if(this.cloudcams[e].licensecam===t)return this.cloudcams[e];return null},t.prototype.getlocalCloudCams=function(){return this.cloudcams},t.prototype.refreshLocalCloudCams=function(){var t=this;return new Promise((function(e){t.getCloudCamsbyUser().then((function(){e(null)}))}))},t.prototype.changeCloudCamEnableCLPRbyUser=function(t,e,n){var o=this;return new Promise((function(i){o.vhmongo_firebase.clouds().changeCloudCamEnableCLPRbyUser(t,e,n).then((function(t){0===t.vcode?i(!0):(console.log(t.message),i(!1))}))}))},t.prototype.changeCloudCamEnableRLPRbyUser=function(t,e,n){var o=this;return new Promise((function(i){o.vhmongo_firebase.clouds().changeCloudCamEnableRLPRbyUser(t,e,n).then((function(t){0===t.vcode?i(!0):(console.log(t.message),i(!1))}))}))},t.prototype.changeCloudCamEnableDetectorByUser=function(t,e,n){var o=this;return new Promise((function(i){o.vhmongo_firebase.clouds().changeCloudCamEnableDetectorByUser(t,e,n).then((function(t){0===t.vcode?i(!0):(console.log(t.message),i(!1))}))}))},t.prototype.changeCloudCamEnableRecordByUser=function(t,e,n){var o=this;return new Promise((function(i){o.vhmongo_firebase.clouds().changeCloudCamEnableRecordByUser(t,e,n).then((function(t){0===t.vcode?i(!0):(console.log(t.message),i(!1))}))}))},t.prototype.changeCloudCamEnableActiveByUser=function(t,e,n){var o=this;return new Promise((function(i){o.vhmongo_firebase.clouds().changeCloudCamEnableActiveByUser(t,e,n).then((function(t){0===t.vcode?i(!0):(console.log(t.message),i(!1))}))}))},t.prototype.changeCloudCamURLbyUser=function(t,e,n){var o=this;return new Promise((function(i){o.vhmongo_firebase.clouds().changeCloudCamURLbyUser(t,e,n).then((function(t){0===t.vcode?i(!0):(console.log(t.message),i(!1))}))}))},t.prototype.addCloudCamByUser=function(t,e,n){var o=this;return new Promise((function(i){o.vhmongo_firebase.clouds().addCloudCamByUser(t,e,n).then((function(t){0===t.vcode?i(t.data):(console.log(t.message),i(null))}))}))},t.prototype.updateCloudCamDataByUser=function(t,e,n){var o=this;return new Promise((function(i){o.vhmongo_firebase.clouds().updateCloudCamDataByUser(t,e,n).then((function(t){0===t.vcode?i(!0):(console.log(t.message),i(!1))}))}))},t.prototype.createEUtokenByUser=function(){var t=this;return new Promise((function(e){t.vhmongo_firebase.clouds().createEUtokenByUser().then((function(t){0===t.vcode?e(t.eutoken):(console.log(t.message),e(!1))}))}))},t.prototype.getUtokenByUser=function(){var t=this;return new Promise((function(e){t.vhmongo_firebase.clouds().getUtokenByUser().then((function(t){0===t.vcode?e(t.utoken):(console.log(t.message),e(!1))}))}))},t.prototype.deleteCloudCamByUser=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.clouds().deleteCloudCamByUser(t).then((function(t){0===t.vcode?n(!0):(console.log(t.message),n(!1))}))}))},t.prototype.getCloudCamByUser=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.clouds().getCloudCamByUser(t).then((function(t){0===t.vcode?n(t.data):(console.log(t.message),n(null))}))}))},t.prototype.getCloudCamsbyUser=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.clouds().getCloudCamsByUser().then((function(n){0===n.vcode?t.cloudcams=n.data:(console.log(n.message),t.cloudcams=new Array),e(t.cloudcams)}),(function(t){n(t)}))}))},t.prototype.getPlaybackListCamByUser=function(t,e,n,o,i){var a=this;return new Promise((function(s,r){a.vhmongo_firebase.clouds().getPlaybackListCamByUser(t,e,n,o,i).then((function(t){0===t.vcode?s(t.data):(console.log(t.message),s([]))}),(function(t){r(t)}))}))},t.prototype.publishObservableEventRooms=function(){this.subjectrooms.next(this.rooms)},t.prototype.observableLocalRooms=function(){return this.subjectrooms},t.prototype.getObservableLocalRooms=function(){var t=this;return new c.Observable((function(e){t.observableLocalRooms().subscribe((function(t){e.next(t)})),t.publishObservableEventRooms()}))},t.prototype.getlocalRoom=function(t){for(var e=0;e<this.rooms.length;e++)if(this.rooms[e]._id===t)return this.rooms[e];return null},t.prototype.getlocalRooms=function(){return this.rooms},t.prototype.refreshLocalRooms=function(){var t=this;return new Promise((function(e){t.getRooms().then((function(){e(null)}))}))},t.prototype.addRoom=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("rooms",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateRoom=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("rooms",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteRoom=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("rooms",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getRoom=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("rooms",t).then((function(t){n(t)}))}))},t.prototype.getRooms=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("rooms").then((function(n){t.rooms=new Array,t.rooms=n,e(n)}),(function(t){n(t)}))}))},t.prototype.getlocalLog=function(t){for(var e=0;e<this.logs.length;e++)if(this.logs[e]._id===t)return this.logs[e];return null},t.prototype.getlocalLogs=function(){return this.logs},t.prototype.refreshLocalLogs=function(){var t=this;return new Promise((function(e){t.getLogs().then((function(){e(null)}))}))},t.prototype.addLog=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("logs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateLog=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("logs",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteLog=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("logs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getLog=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("logs",t).then((function(t){n(t)}))}))},t.prototype.getLogs=function(){var t=this;return new Promise((function(e,n){t.logs=new Array,t.vhmongo_firebase.database().getDocs("logs").then((function(n){t.logs=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventMainboards=function(){this.subjectmainboards.next(this.mainboards)},t.prototype.observableLocalMainboards=function(){return this.subjectmainboards},t.prototype.getObservableLocalMainboards=function(){var t=this;return new c.Observable((function(e){t.observableLocalMainboards().subscribe((function(t){e.next(t)})),t.publishObservableEventMainboards()}))},t.prototype.getlocalMainboard=function(t){for(var e=0;e<this.mainboards.length;e++)if(this.mainboards[e]._id===t)return this.mainboards[e];return null},t.prototype.getlocalMainboards=function(){return this.mainboards},t.prototype.refreshLocalMainboards=function(){var t=this;return new Promise((function(e){t.getMainboards().then((function(){e(null)}))}))},t.prototype.addMainboard=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("mainboards",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateMainboard=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("mainboards",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteMainboard=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("mainboards",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getMainboard=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("mainboards",t).then((function(t){n(t)}))}))},t.prototype.getMainboards=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("mainboards").then((function(n){t.mainboards=new Array,t.mainboards=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventFunctions=function(){this.subjectfunctions.next(this.functions)},t.prototype.observableLocalFunctions=function(){return this.subjectfunctions},t.prototype.getObservableLocalFunctions=function(){var t=this;return new c.Observable((function(e){t.observableLocalFunctions().subscribe((function(t){e.next(t)})),t.publishObservableEventFunctions()}))},t.prototype.getlocalFunction=function(t){for(var e=0;e<this.functions.length;e++)if(this.functions[e]._id===t)return this.functions[e];return null},t.prototype.getlocalFunctions=function(){return this.functions},t.prototype.refreshLocalFunctions=function(){var t=this;return new Promise((function(e){t.getFunctions().then((function(){e(null)}))}))},t.prototype.addFunction=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("functions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateFunction=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("functions",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteFunction=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("functions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getFunction=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("functions",t).then((function(t){n(t)}))}))},t.prototype.getFunctions=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("functions").then((function(n){t.functions=new Array,t.functions=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventComponents=function(){this.subjectcomponents.next(this.components)},t.prototype.observableLocalComponents=function(){return this.subjectcomponents},t.prototype.getObservableLocalComponents=function(){var t=this;return new c.Observable((function(e){t.observableLocalComponents().subscribe((function(t){e.next(t)})),t.publishObservableEventComponents()}))},t.prototype.getlocalComponent=function(t){for(var e=0;e<this.components.length;e++)if(this.components[e]._id===t)return this.components[e];return null},t.prototype.getlocalComponents=function(){return this.components},t.prototype.refreshLocalComponents=function(){var t=this;return new Promise((function(e){t.getComponents().then((function(){e(null)}))}))},t.prototype.addComponent=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("components",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateComponent=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("components",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteComponent=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("components",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getComponent=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("components",t).then((function(t){n(t)}))}))},t.prototype.getComponents=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("components").then((function(n){t.components=new Array,t.components=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventIcons=function(){this.subjecticons.next(this.icons)},t.prototype.observableLocalIcons=function(){return this.subjecticons},t.prototype.getObservableLocalIcons=function(){var t=this;return new c.Observable((function(e){t.observableLocalIcons().subscribe((function(t){e.next(t)})),t.publishObservableEventIcons()}))},t.prototype.getlocalIcon=function(t){for(var e=0;e<this.icons.length;e++)if(this.icons[e]._id===t)return this.icons[e];return null},t.prototype.getlocalIcons=function(){return this.icons},t.prototype.refreshLocalIcons=function(){var t=this;return new Promise((function(e){t.getIcons().then((function(){e(null)}))}))},t.prototype.addIcon=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("icons",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateIcon=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("icons",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteIcon=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("icons",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getIcon=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("icons",t).then((function(t){n(t)}))}))},t.prototype.getIcons=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("icons").then((function(n){t.icons=new Array,t.icons=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventAppSettingNameStations=function(){this.subjectappsettingstations.next()},t.prototype.observableLocalAppSettingNameStations=function(){return this.subjectappsettingstations},t.prototype.getObservableLocalAppSettingNameStations=function(){var t=this;return new c.Observable((function(e){t.observableLocalAppSettingNameStations().subscribe((function(){for(var n=new Array,o=0;o<t.appsettingstations.length;o++)n.push(t.appsettingstations[o].appsetting_name);e.next(n)})),t.publishObservableEventAppSettingNameStations()}))},t.prototype.getLocalAppSettingNameStations=function(){for(var t=new Array,e=0;e<this.appsettingstations.length;e++)t.push(this.appsettingstations[e].appsetting_name);return t},t.prototype.getLocalAppSettingNameStation=function(t){for(var e={},n=0;n<this.appsettingstations.length;n++)if(this.appsettingstations[n].appsetting_name===t){delete(e=Object.assign({},this.appsettingstations[n]))._id,delete e.appsetting_name;break}return e},t.prototype.getLocalAppSettingStation=function(t){for(var e=0;e<this.appsettingstations.length;e++)if(this.appsettingstations[e]._id===t)return this.appsettingstations[e];return null},t.prototype.refreshLocalAppSettingNameStations=function(){return new Promise((function(t,e){t(null)}))},t.prototype.getAppSettingStations=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocsByFields("appsettingstations",{uuid:{$eq:t.hwinfo.uuid}},{},{},0).then((function(n){n.length>0&&(t.appsettingstations=n),e(null)}),(function(t){n(t)}))}))},t.prototype.updateAppSettingNameStation=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().getDocsByFields("appsettingstations",{appsetting_name:{$eq:t},uuid:{$eq:n.hwinfo.uuid}},{},{},0).then((function(a){if(a.length>0)n.vhmongo_firebase.database().updateDoc("appsettingstations",a[0]._id,e).then((function(t){o(t)}),(function(t){i(t)}));else{var s=Object.assign({},e);s.appsetting_name=t,s.uuid=n.hwinfo.uuid,n.vhmongo_firebase.database().addDoc("appsettingstations",s).then((function(){o(!0)}),(function(t){i(t)}))}}))}))},t.prototype.deleteAppSettingNameStation=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("appsettingstations",{appsetting_name:{$eq:t},uuid:{$eq:e.hwinfo.uuid}},{},{},0).then((function(t){t.length>0?e.vhmongo_firebase.database().deleteDoc("appsettingstations",t[0]._id).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}))}))},t.prototype.getlocalScript=function(t){for(var e=0;e<this.scripts.length;e++)if(this.scripts[e]._id===t)return this.scripts[e];return null},t.prototype.getlocalScripts=function(){return this.scripts},t.prototype.refreshLocalScripts=function(){var t=this;return new Promise((function(e){t.getScripts().then((function(){e(null)}))}))},t.prototype.addScript=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("scripts",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateScript=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("scripts",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteScript=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("scripts",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getScript=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("scripts",t).then((function(t){n(t)}))}))},t.prototype.getScripts=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("scripts").then((function(n){t.scripts=new Array,t.scripts=n,e(n)}),(function(t){n(t)}))}))},t.prototype.getlocalScript_detail=function(t){for(var e=0;e<this.script_details.length;e++)if(this.script_details[e]._id===t)return this.script_details[e];return null},t.prototype.getlocalScript_details=function(){return this.script_details},t.prototype.refreshLocalScript_details=function(){var t=this;return new Promise((function(e){t.getScript_details().then((function(){e(null)}))}))},t.prototype.addScript_detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("script_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateScript_detail=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("script_details",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteScript_detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("script_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getScript_detail=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("script_details",t).then((function(t){n(t)}))}))},t.prototype.getScript_details=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("script_details").then((function(n){t.script_details=new Array,t.script_details=n,e(n)}),(function(t){n(t)}))}))},t}();H.decorators=[{type:e.Injectable}],H.ctorParameters=function(){return[{type:o.Vhmongo_firebase},{type:V},{type:F},{type:L}]};var G=function(){function t(t){this.vhmongo_firebase=t,this.productlistshopees=new Array,this.shoplistshopee=new Array,this.lazadapricecomparinglist=new Array,this.tikipricecomparinglist=new Array,this.sendopricecomparinglist=new Array,this.shopeepricecomparinglist=new Array}return t.prototype.getShippingDocumentShopee=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.shopee().getShippingDocumentShopee(t,e,Number(n)).then((function(t){i(t)}),(function(t){a(t)}))}))},t.prototype.getShippingParameterShopee=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.shopee().getShippingParameterShopee(t,e,Number(n)).then((function(t){i(t)}),(function(t){a(t)}))}))},t.prototype.confirmShippingByJSONShopee=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.shopee().confirmShippingByJSONShopee(t,e,Number(n)).then((function(t){i(t)}),(function(t){a(t)}))}))},t.prototype.observableLazadaPriceComparing=function(t){var e=this;return new c.Observable((function(n){e.callbacklazadapricecomparing=e.vhmongo_firebase.socketMongoDB().initSyncLazadaPriceComparing(t).subscribe((function(t){if("added"===t.type){var o=Object.assign({_id:t.doc.id},e.vhmongo_firebase.database().cvtDataFB2MG(t.doc.data()));e.lazadapricecomparinglist.push(o)}else if("modified"===t.type){o=Object.assign({_id:t.doc.id},e.vhmongo_firebase.database().cvtDataFB2MG(t.doc.data()));for(var i=0;i<e.lazadapricecomparinglist.length;i++)if(e.lazadapricecomparinglist[i]._id===o._id){e.lazadapricecomparinglist[i]=Object.assign(Object.assign({},e.lazadapricecomparinglist[i]),o);break}}else if("removed"===t.type)for(o={_id:t.doc.id},i=0;i<e.lazadapricecomparinglist.length;i++)if(e.lazadapricecomparinglist[i]._id===o._id){e.lazadapricecomparinglist.splice(i,1);break}n.next(!0)}))}))},t.prototype.closeLazadaPriceComparing=function(){this.callbacklazadapricecomparing.unsubscribe(),this.vhmongo_firebase.socketMongoDB().closeLazadaPriceComparing()},t.prototype.getLocalLazadaPriceComparing=function(){return JSON.parse(JSON.stringify(this.lazadapricecomparinglist))},t.prototype.restartEcommercePriceComparingMACHINE=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().restartEcommercePriceComparingMACHINE().then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.getAllShops=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("ecommerces",{id_branch:{$eq:t}},{},{},0).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateShop=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().getDoc("ecommerces",t).then((function(a){if(a){var s={};s=null!=a.data?Object.assign(Object.assign({},a.data),e):Object.assign({},e),n.vhmongo_firebase.database().updateDoc("ecommerces",t,{data:s}).then((function(e){for(var i=0;i<n.shoplistshopee.length;i++)if(n.shoplistshopee[i]._id===t){n.shoplistshopee[i].data=s;break}o(e)}),(function(t){i(t)}))}else o(!1)}))}))},t.prototype.signInShopee=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.shopee().signIn(t,e).then((function(t){window.location=t.data,o(!0)}),(function(t){i(t)}))}))},t.prototype.signOutShopee=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.shopee().signOut(t).then((function(i){if(0===i.vcode){for(var a=0;a<e.shoplistshopee.length;a++)if(e.shoplistshopee[a]._id===t){e.shoplistshopee.splice(a,1);break}for(a=0;a<e.productlistshopees.length;a++)if(e.productlistshopees[a]._id===t){e.productlistshopees.splice(a,1);break}n(!0)}else console.log(i.message),o(!1)}),(function(t){o(t)}))}))},t.prototype.refreshLocalProductListShopee=function(t,e){var n=this;return new Promise((function(o,i){""!=e&&null!=e?n.getProductListShopee(t,e).then((function(){o(null)})):n.getProductListShopees(t).then((function(){o(null)}))}))},t.prototype.getlocalShopListShopee=function(){return this.shoplistshopee},t.prototype.getProductListShopee=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.shopee().getShop(t,e).then((function(t){if(console.log("shopshopee",t),0===t.vcode){n.shoplistshopee=E(t.data),n.productlistshopees=E(t.data);for(var e=new Array,a=function(t){e[t]=new Promise((function(e,o){n.vhmongo_firebase.shopee().getProductList(n.productlistshopees[t].access_token,Number(n.productlistshopees[t]._id)).then((function(o){n.productlistshopees[t].productlist=o,e(null)}),(function(t){console.log(t),o(t)}))}))},s=0;s<n.productlistshopees.length;s++)a(s);Promise.all(e).then((function(){console.log("productlistshopees",n.productlistshopees),o(null)}))}else console.log(t.message),i(t.message)}),(function(t){i(t)}))}))},t.prototype.getProductListShopees=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.shopee().getShopList(t).then((function(t){if(0===t.vcode){e.shoplistshopee=E(t.data),e.productlistshopees=E(t.data);for(var i=new Array,a=function(t){i[t]=new Promise((function(n,o){e.vhmongo_firebase.shopee().getProductList(e.productlistshopees[t].access_token,Number(e.productlistshopees[t]._id)).then((function(o){e.productlistshopees[t].productlist=o,n(null)}),(function(t){console.log(t),o(t)}))}))},s=0;s<e.productlistshopees.length;s++)a(s);Promise.all(i).then((function(){console.log("productlistshopees",e.productlistshopees),n(null)}))}else console.log(t.message),o(t.message)}),(function(t){o(t)}))}))},t.prototype.getlocalProductListShopee=function(t){for(var e=0;e<this.productlistshopees.length;e++)if(this.productlistshopees[e]._id===t)return JSON.parse(JSON.stringify(this.productlistshopees[e].productlist));return[]},t.prototype.getProductByItem_idShopee=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.shopee().getProductByItem_id(t,e,Number(n)).then((function(t){if(0===t.vcode){for(var a=0;a<o.productlistshopees.length;a++)if(o.productlistshopees[a]._id===n)for(var s=0;s<o.productlistshopees[a].productlist.length;s++)if(o.productlistshopees[a].productlist[s].item_id===e){o.productlistshopees[a].productlist[s]=Object.assign(Object.assign({},o.productlistshopees[a].productlist[s]),t.data);break}i(t.data)}else console.log(t.message),i(null)}),(function(t){a(t)}))}))},t.prototype.getSalesOrderListShopee=function(t,e,n,o){var i=this;return t=new Date(t),e=new Date(e),new Promise((function(a,s){var r=new Promise((function(a,s){i.vhmongo_firebase.shopee().getOrderList(t.getTime()/1e3,e.getTime()/1e3,n,Number(o)).then((function(t){i.productlistshopees.forEach((function(e){e._id===o&&(e.salesorderdetaillist=t)})),a(t)}),(function(t){s(t)}))})),l=new Promise((function(n,a){var s={create_time:{$gte:new Date(t),$lte:new Date(e)}};i.vhmongo_firebase.database().getDocsByFields(o,s,{},{},0).then((function(t){n(t)}))}));Promise.all([r,l]).then((function(t){t[0].filter((function(e){var n=!0;return t[1].forEach((function(t){e.order_sn.toString()===t._id&&(n=!1)})),n})).forEach((function(t){i.vhmongo_firebase.database().addDocbyID(o.toString(),t.order_sn.toString(),{create_time:new Date(1e3*t.create_time)})}));for(var e=0;e<t[0].length;e++)for(var n=0;n<t[1].length;n++)if(t[0][e].order_sn===t[1][n]._id){var s=Object.assign({},t[1][n]);delete s._id,delete s.create_time,t[0][e]=Object.assign(Object.assign({},t[0][e]),s)}console.log("salesorderdetaillist",t[0]),a(t[0])}))}))},t.prototype.getSalesOrderDetailShopee=function(t,e,n){var o=this;return new Promise((function(i,a){var s=o.vhmongo_firebase.shopee().getOrders(t,e,n),r=o.vhmongo_firebase.database().getDoc(n,t);Promise.all([s,r]).then((function(t){t[0].length>0?(t[1]||o.vhmongo_firebase.database().addDocbyID(n,t[0].order_sn,{create_time:new Date(1e3*t[0].create_time)}),i(t[0][0])):i(null)}))}))},t.prototype.getTrackingNumberShopee=function(t,e,n){var o=this;return new Promise((function(i,a){var s=o.vhmongo_firebase.shopee().getTrackingNumber(t,e,n),r=o.vhmongo_firebase.database().getDoc(n,t);Promise.all([s,r]).then((function(e){e[1]&&o.vhmongo_firebase.database().updateDoc(n,t,{tracking_number:e[0].tracking_number}),i(e[0])}),(function(t){a(t)}))}))},t.prototype.addMergeShopeesProduct_model=function(t,e,n,o,i){var a=this;return new Promise((function(s,r){var l={item_id:e,id_shop:o,model:E(n)};null!=t[i]?void 0===t[i].shopees&&(t[i].shopees=new Array):(t[i]={},t[i].shopees=new Array);for(var c=!1,u=0;u<t[i].shopees.length;u++)if(t[i].shopees[u].item_id===e&&t[i].shopees[u].id_shop===o){var d;null!=t[i].shopees[u].model?t[i].shopees[u].model=E(t[i].shopees[u].model,n):t[i].shopees[u].model=E(n),(d={})[i]=t[i],a.vhmongo_firebase.database().updateDoc("products",t._id,Object.assign({},d)).then((function(){s(!0)}),(function(t){r(t)})),c=!0;break}c||(t[i].shopees.push(l),(d={})[i]=t[i],a.vhmongo_firebase.database().updateDoc("products",t._id,Object.assign({},d)).then((function(){s(!0)}),(function(t){r(t)})))}))},t.prototype.updateMergeShopeesProduct=function(t,e,n,o,i){var a=this;return new Promise((function(s,r){if(void 0===t[i])return s(!1);if(void 0===t[i].shopees)return s(!1);for(var l=!1,c=0;c<t[i].shopees.length;c++)if(t[i].shopees[c].item_id===e&&t[i].shopees[c].id_shop===o){t[i].shopees[c]=Object.assign(Object.assign({},t[i].shopees[c]),n);var u={};u[i]=t[i],a.vhmongo_firebase.database().updateDoc("products",t._id,Object.assign({},u)).then((function(t){s(t)}),(function(t){r(t)})),l=!0;break}l||s(!1)}))},t.prototype.updateMergeShopeesProduct_model=function(t,e,n,o,i,a){var s=this;return new Promise((function(r,l){if(void 0===t[a])return r(!1);if(void 0===t[a].shopees)return r(!1);for(var c=!1,u=0;u<t[a].shopees.length;u++)if(t[a].shopees[u].item_id===e&&t[a].shopees[u].id_shop===i&&null!=t[a].shopees[u].model)for(var d=0;d<t[a].shopees[u].model.length;d++)if(t[a].shopees[u].model[d].model_id===n){t[a].shopees[u].model[d]=Object.assign(Object.assign({},t[a].shopees[u].model[d]),o);var _={};_[a]=t[a],s.vhmongo_firebase.database().updateDoc("products",t._id,Object.assign({},_)).then((function(t){r(t)}),(function(t){l(t)})),c=!0;break}c||r(!1)}))},t.prototype.deleteMergeShopeeProduct_model=function(t,e,n,o,i){var a=this;return new Promise((function(s,r){if(void 0===t[i])return s(!1);if(void 0===t[i].shopees)return s(!1);for(var l=!1,c=0;c<t[i].shopees.length;c++)if(t[i].shopees[c].item_id===e&&t[i].shopees[c].id_shop===o&&null!=t[i].shopees[c].model){for(var u=0;u<t[i].shopees[c].model.length;u++)if(t[i].shopees[c].model[u].model_id===n){t[i].shopees[c].model.splice(u,1),(d={})[i]=t[i],a.vhmongo_firebase.database().updateDoc("products",t._id,Object.assign({},d)).then((function(t){s(t)}),(function(t){r(t)})),l=!0;break}var d;if(0===t[i].shopees[c].model.length)t[i].shopees.splice(c,1),(d={})[i]=t[i],a.vhmongo_firebase.database().updateDoc("products",t._id,Object.assign({},d)).then((function(t){s(t)}),(function(t){r(t)})),l=!0}l||s(!1)}))},t.prototype.updateProductInfoByJSONshopee=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.shopee().updateProductInfoByJSONshopee(t,e,Number(n)).then((function(t){0===t.vcode?i(t.data):(console.log(t.message),i(null))}),(function(t){a(t)}))}))},t.prototype.updateProductStockByJSONshopee=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.shopee().updateProductStockByJSONshopee(t,e,Number(n)).then((function(t){0===t.vcode?i(t.data):(console.log(t.message),i(null))}),(function(t){a(t)}))}))},t.prototype.updateProductPriceByJSONshopee=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.shopee().updateProductPriceByJSONshopee(t,e,Number(n)).then((function(t){0===t.vcode?i(t.data):(console.log(t.message),i(null))}),(function(t){a(t)}))}))},t.prototype.getSalesOrderShopee_fromViethas=function(t,e){var n=this;return new Promise((function(o,i){for(var a=new Array,s=0;s<t.length;s++)a[s]=n.vhmongo_firebase.database().getDoc(e,t[s]);Promise.all(a).then((function(t){o(t)}))}))},t.prototype.updateSalesOrderShopee=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.database().updateDoc(t,e,n).then((function(a){a&&o.productlistshopees.forEach((function(o){o._id===t&&o.salesorderdetaillist.forEach((function(t){t.order_sn===e&&(t=Object.assign(Object.assign({},t),n))}))})),i(a)}),(function(t){a(t)}))}))},t.prototype.updateSalesOrderShopee_byFile=function(t,e,n,o){var i=this;return new Promise((function(a,s){for(var r=new Array,l=function(a){r[a]=new Promise((function(s){i.vhmongo_firebase.shopee().getOrders(t[a],n,Number(o)).then((function(n){n?i.vhmongo_firebase.database().getDoc(o,t[a]).then((function(n){n?i.vhmongo_firebase.database().updateDoc(o,t[a],e).then((function(t){s(t)}),(function(){s(!1)})):i.vhmongo_firebase.database().addDocbyID(o,t[a],e).then((function(){s(!0)}))})):s(!1)}),(function(){s(!1)}))}))},c=0;c<t.length;c++)l(c);Promise.all(r).then((function(t){a(t)}))}))},t}();G.decorators=[{type:e.Injectable}],G.ctorParameters=function(){return[{type:o.Vhmongo_firebase}]};var Y=function(){function t(t,e,n,o,i,a){var s=this;this.vhmongo_firebase=t,this.vhQuery=e,this.vhAuth=n,this.vhAlgorithm=o,this.iap2=i,this.platform=a,this.restriction_main_package=null,this.restriction_ecommerce_package=null,this.restriction_facebook_package=null,this.restriction_warranty_package=null,this.productlistsendo=new Array,this.shoplistsendo=new Array,this.productlistlazada=new Array,this.shoplistlazada=new Array,this.productlisttikis=new Array,this.shoplisttiki=new Array,this.products=new Array,this.customers=new Array,this.suppliers=new Array,this.wallets=new Array,this.taxs=new Array,this.categorys=new Array,this.inventorytimes=new Array,this.warrantys=new Array,this.discount_bills=new Array,this.discount_saless=new Array,this.customer_classs=new Array,this.commissions=new Array,this.deliverys=new Array,this.addresss=new Array,this.incoming_groups=new Array,this.spending_groups=new Array,this.branchs=new Array,this.promotions=new Array,this.printers=new Array,this.hwinfo={},this.appsettingstations=new Array,this.appsettingbranchs=new Array,this.subjectwallets=new c.Subject,this.subjectappsettingstations=new c.Subject,this.subjectappsettingbranchs=new c.Subject,this.subjectbranchs=new c.Subject,this.subjectcategorys=new c.Subject,this.subjectcustomers=new c.Subject,this.subjectinventorytimes=new c.Subject,this.subjectprinters=new c.Subject,this.subjectproducts=new c.Subject,this.subjectpromotions=new c.Subject,this.subjectsuppliers=new c.Subject,this.subjecttaxs=new c.Subject,this.subjectwarrantys=new c.Subject,this.subjectdiscount_bills=new c.Subject,this.subjectcustomer_classs=new c.Subject,this.sync_code=Math.random().toString(36).substr(2,10).toUpperCase(),r.Device.getId().then((function(t){var e=s.vhAuth.localStorageGET("hwinfo");null!=e&&null!=e?s.hwinfo=e:(s.hwinfo=Object.assign({},t),s.vhAuth.localStorageSET("hwinfo",s.hwinfo))}))}return t.prototype.refreshLocalRestrictionMainPackage=function(){var t=this;return new Promise((function(e,n){var o=t.getDefaultBranch()._id,i=t.vhAuth.getStore()[o].main_package_expire.id_restriction;t.vhmongo_firebase.rootdatabase().getDoc("restrictions",i).then((function(n){n&&(t.restriction_main_package=Object.assign(Object.assign({},n),t.vhAuth.getStore()[o].main_package_expire),delete t.restriction_main_package.id_restriction,delete t.restriction_main_package._id,console.log("restriction_main_package",t.restriction_main_package)),e(null)}),(function(t){n(t)}))}))},t.prototype.getLocalRestrictionMainPackage=function(){return this.restriction_main_package},t.prototype.refreshLocalRestrictionEcommercePackage=function(){var t=this;return new Promise((function(e,n){var o=t.getDefaultBranch()._id,i=t.vhAuth.getStore()[o].ecommerce_package_expire.id_restriction;t.vhmongo_firebase.rootdatabase().getDoc("restrictions",i).then((function(n){n&&(t.restriction_ecommerce_package=Object.assign(Object.assign({},n),t.vhAuth.getStore()[o].ecommerce_package_expire),delete t.restriction_ecommerce_package.id_restriction,delete t.restriction_ecommerce_package._id,console.log("restriction_ecommerce_package",t.restriction_ecommerce_package)),e(null)}),(function(t){n(t)}))}))},t.prototype.getLocalRestrictionEcommercePackage=function(){return this.restriction_ecommerce_package},t.prototype.refreshLocalRestrictionFacebookPackage=function(){var t=this;return new Promise((function(e,n){var o=t.getDefaultBranch()._id,i=t.vhAuth.getStore()[o].facebook_package_expire.id_restriction;t.vhmongo_firebase.rootdatabase().getDoc("restrictions",i).then((function(n){n&&(t.restriction_facebook_package=Object.assign(Object.assign({},n),t.vhAuth.getStore()[o].facebook_package_expire),delete t.restriction_facebook_package.id_restriction,delete t.restriction_facebook_package._id,console.log("restriction_facebook_package",t.restriction_facebook_package)),e(null)}),(function(t){n(t)}))}))},t.prototype.getLocalRestrictionFacebookPackage=function(){return this.restriction_facebook_package},t.prototype.refreshLocalRestrictionWarrantyPackage=function(){var t=this;return new Promise((function(e,n){var o=t.getDefaultBranch()._id,i=t.vhAuth.getStore()[o].warranty_package_expire.id_restriction;t.vhmongo_firebase.rootdatabase().getDoc("restrictions",i).then((function(n){n&&(t.restriction_warranty_package=Object.assign(Object.assign({},n),t.vhAuth.getStore()[o].warranty_package_expire),delete t.restriction_warranty_package.id_restriction,delete t.restriction_warranty_package._id,console.log("restriction_warranty_package",t.restriction_warranty_package)),e(null)}),(function(t){n(t)}))}))},t.prototype.getLocalRestrictionWarrantyPackage=function(){return this.restriction_warranty_package},t.prototype.observableWebhookFeedFacebook=function(t){var e=this;return new c.Observable((function(n){e.vhmongo_firebase.socketFacebook().observableWebhookFeed(t).subscribe((function(t){n.next(t)}))}))},t.prototype.unsubscribeWebhookFeedFacebook=function(t){this.vhmongo_firebase.socketFacebook().unsubscribeWebhookFeed(t)},t.prototype.observableWebhookMessagesFacebook=function(t){var e=this;return new c.Observable((function(n){e.vhmongo_firebase.socketFacebook().observableWebhookMessages(t).subscribe((function(t){n.next(t)}))}))},t.prototype.unsubscribeWebhookMessagesFacebook=function(t){this.vhmongo_firebase.socketFacebook().unsubscribeWebhookMessages(t)},t.prototype.GetShippingStampForDropshipTiki=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.tiki().GetShippingStampForDropshipTiki(t,e,n).then((function(t){i(t)}),(function(t){a(t)}))}))},t.prototype.getSellerInventoriesForConfirmationTiki=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.tiki().getSellerInventoriesForConfirmationTiki(t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getExpectedPickupTimesTiki=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.tiki().getExpectedPickupTimesTiki(t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.ConfirmEnoughStockForDropShippingByJSONTiki=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.tiki().ConfirmEnoughStockForDropShippingByJSONTiki(t,e,n).then((function(t){i(t)}),(function(t){a(t)}))}))},t.prototype.getSalesOrderTiki_fromViethas=function(t,e){var n=this;return new Promise((function(o,i){for(var a=new Array,s=0;s<t.length;s++)a[s]=n.vhmongo_firebase.database().getDoc(e,t[s]);Promise.all(a).then((function(t){o(t)}))}))},t.prototype.updateSalesOrderTiki=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.database().updateDoc(t,e,n).then((function(a){a&&o.productlistlazada.forEach((function(o){o._id===t&&o.salesorderdetaillist.forEach((function(t){t.code===e&&(t=Object.assign(Object.assign({},t),n))}))})),i(a)}),(function(t){a(t)}))}))},t.prototype.updateSalesOrderTiki_byFile=function(t,e,n,o){var i=this;return new Promise((function(a,s){for(var r=new Array,l=function(a){r[a]=new Promise((function(s){i.vhmongo_firebase.tiki().getOrders(t[a],n).then((function(n){n?i.vhmongo_firebase.database().getDoc(o,t[a]).then((function(n){n?i.vhmongo_firebase.database().updateDoc(o,t[a],e).then((function(t){s(t)}),(function(){s(!1)})):i.vhmongo_firebase.database().addDocbyID(o,t[a],e).then((function(){s(!0)}))})):s(!1)}),(function(){s(!1)}))}))},c=0;c<t.length;c++)l(c);Promise.all(r).then((function(t){a(t)}))}))},t.prototype.updateProductByJSONTiki=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.tiki().updateProductByJSON(t,e).then((function(t){0===t.vcode?o(t.data):(console.log(t.message),o(null))}),(function(t){i(t)}))}))},t.prototype.updateProductsByJSONTiki=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.tiki().updateProductsByJSON(t,e).then((function(t){0===t.vcode?o(t.data):(console.log(t.message),o(null))}),(function(t){i(t)}))}))},t.prototype.getSalesOrderListTiki=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Promise((function(a,s){i.vhmongo_firebase.tiki().getOrderList(B(new Date(t),"YYYY-MM-dd HH:mm:ss"),B(new Date(e),"YYYY-MM-dd HH:mm:ss"),n).then((function(t){i.productlisttikis.forEach((function(e){e._id===o&&(e.salesorderdetaillist=t)})),a(t)}),(function(t){s(t)}))})),l=new Promise((function(n,a){var s={created_at:{$gte:new Date(t),$lte:new Date(e)}};i.vhmongo_firebase.database().getDocsByFields(o,s,{},{},0).then((function(t){n(t)}))}));Promise.all([r,l]).then((function(t){t[0].filter((function(e){var n=!0;return t[1].forEach((function(t){e.code.toString()===t._id&&(n=!1)})),n})).forEach((function(t){i.vhmongo_firebase.database().addDocbyID(o.toString(),t.code.toString(),{created_at:new Date(t.created_at)})}));for(var e=0;e<t[0].length;e++)for(var n=0;n<t[1].length;n++)if(t[0][e].code===t[1][n]._id){var s=Object.assign({},t[1][n]);delete s._id,delete s.created_at,t[0][e]=Object.assign(Object.assign({},t[0][e]),s)}a(t[0])}))}))},t.prototype.getSalesOrderDetailTiki=function(t,e,n){var o=this;return new Promise((function(i,a){var s=o.vhmongo_firebase.tiki().getOrders(t,e),r=o.vhmongo_firebase.database().getDoc(n,t);Promise.all([s,r]).then((function(t){t[0].length>0?(t[1]||o.vhmongo_firebase.database().addDocbyID(n,t[0].code,{created_at:new Date(t[0].created_at)}),i(t[0][0])):i(null)}))}))},t.prototype.getlocalProductListTiki=function(t){for(var e=0;e<this.productlisttikis.length;e++)if(this.productlisttikis[e]._id===t)return JSON.parse(JSON.stringify(this.productlisttikis[e].productlist));return[]},t.prototype.refreshLocalProductListTikis=function(t){var e=this;return new Promise((function(n,o){""!=t&&null!=t?e.getProductListTiki(t).then((function(){n(null)})):e.getProductListTikis().then((function(){n(null)}))}))},t.prototype.getProductListTiki=function(t){var e=this;return new Promise((function(n,o){var i=e.getDefaultBranch()._id;e.vhmongo_firebase.tiki().getShop(i,t).then((function(t){if(console.log("shoptiki",t),0===t.vcode){e.shoplisttiki=E(t.data),e.productlisttikis=E(t.data);for(var i=new Array,a=function(t){i[t]=new Promise((function(n,o){for(var i=new Array,a=function(n){i[n]=new Promise((function(o,i){var a=n+1;e.vhmongo_firebase.tiki().getProductPage(e.productlisttikis[t].access_token,a).then((function(t){0===t.vcode?o(t.data):(console.log(t.message),i(t.message))}),(function(t){i(t)}))}))},s=0;s<e.productlisttikis[t].product_page_total;s++)a(s);Promise.all(i).then((function(o){e.productlisttikis[t].productlist=o.flat(),n(null)}))}))},s=0;s<e.productlisttikis.length;s++)a(s);Promise.all(i).then((function(){console.log("productlisttikis",e.productlisttikis),n(null)}))}else console.log(t.message),o(t.message)}),(function(t){o(t)}))}))},t.prototype.getProductListTikis=function(){var t=this;return new Promise((function(e,n){var o=t.getDefaultBranch()._id;t.vhmongo_firebase.tiki().getShopList(o).then((function(o){if(0===o.vcode){t.shoplisttiki=E(o.data),t.productlisttikis=E(o.data);for(var i=new Array,a=function(e){i[e]=new Promise((function(n,o){for(var i=new Array,a=function(n){i[n]=new Promise((function(o,i){var a=n+1;t.vhmongo_firebase.tiki().getProductPage(t.productlisttikis[e].access_token,a).then((function(t){0===t.vcode?o(t.data):(console.log(t.message),i(t.message))}),(function(t){i(t)}))}))},s=0;s<t.productlisttikis[e].product_page_total;s++)a(s);Promise.all(i).then((function(o){t.productlisttikis[e].productlist=o.flat(),n(null)}))}))},s=0;s<t.productlisttikis.length;s++)a(s);Promise.all(i).then((function(){console.log("productlisttikis",t.productlisttikis),e(null)}))}else console.log(o.message),n(o.message)}),(function(t){n(t)}))}))},t.prototype.getProductByIdTiki=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.tiki().getProductByIdTiki(t,e).then((function(t){if(0===t.vcode){for(var a=0;a<o.productlisttikis.length;a++)if(o.productlisttikis[a]._id===n)for(var s=0;s<o.productlisttikis[a].productlist.length;s++)if(o.productlisttikis[a].productlist[s].product_id===e){o.productlisttikis[a].productlist[s]=Object.assign(Object.assign({},o.productlisttikis[a].productlist[s]),t.data);break}i(t.data)}else console.log(t.message),i(null)}),(function(t){a(t)}))}))},t.prototype.getHiddenProductListTiki=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.tiki().getHiddenProductList(t).then((function(t){0===t.vcode?n(t.data):(console.log(t.message),n([]))}),(function(t){o(t)}))}))},t.prototype.getlocalShopListTiki=function(){return this.shoplisttiki},t.prototype.getShopListTiki=function(){var t=this;return new Promise((function(e,n){var o=t.getDefaultBranch()._id;t.vhmongo_firebase.tiki().getShopList(o).then((function(o){0===o.vcode?(t.shoplisttiki=o.data,e(o.data)):(console.log(o.message),n(o.message))}),(function(t){n(t)}))}))},t.prototype.signInTiki=function(t){var e=this;return new Promise((function(n,o){var i=e.getDefaultBranch()._id;e.vhmongo_firebase.tiki().signIn(i,t).then((function(t){window.location=t.data,n(!0)}),(function(t){o(t)}))}))},t.prototype.signOutTiki=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.tiki().signOut(t).then((function(i){if(0===i.vcode){for(var a=0;a<e.shoplisttiki.length;a++)if(e.shoplisttiki[a]._id===t){e.shoplisttiki.splice(a,1);break}for(a=0;a<e.productlisttikis.length;a++)if(e.productlisttikis[a]._id===t){e.productlisttikis.splice(a,1);break}n(!0)}else console.log(i.message),o(!1)}),(function(t){o(t)}))}))},t.prototype.addMergeTikiProduct=function(t,e,n){var o=this;return new Promise((function(i,a){var s=o.getDefaultBranch()._id,r=o.getlocalProduct(t);null!=r[s]?void 0===r[s].tikis&&(r[s].tikis=new Array):(r[s]={},r[s].tikis=new Array);for(var l=new Array,c=0;c<e.length;c++){for(var u={product_id:e[c],id_shop:n},d=!1,_=0;_<r[s].tikis.length;_++)if(r[s].tikis[_].product_id===e[c]&&r[s].tikis[_].id_shop===n){d=!0;break}d||l.push(u)}if(l.length>0){r[s].tikis=E(r[s].tikis,l);var p={};p[s]=r[s],o.vhmongo_firebase.database().updateDoc("products",t,Object.assign({},p)).then((function(){i(!0)}),(function(t){a(t)}))}else i(!1)}))},t.prototype.updateMergeTikiProduct=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=i.getlocalProduct(t),l=i.getDefaultBranch()._id;if(void 0===r[l])return a(!1);if(void 0===r[l].tikis)return a(!1);for(var c=!1,u=0;u<r[l].tikis.length;u++)if(r[l].tikis[u].product_id===e&&r[l].tikis[u].id_shop===o){r[l].tikis[u]=Object.assign(Object.assign({},r[l].tikis[u]),n);var d={};d[l]=r[l],i.vhmongo_firebase.database().updateDoc("products",t,Object.assign({},d)).then((function(t){a(t)}),(function(t){s(t)})),c=!0;break}c||a(!1)}))},t.prototype.updateMergeTikiProduct_hidden=function(t,e,n){var o=this;return new Promise((function(i,a){for(var s=o.getDefaultBranch()._id,r=o.getlocalProducts(),l=null,c=0;c<r.length;c++)if(null!=r[c][s]&&null!=r[c][s].tikis)for(var u=0;u<r[c][s].tikis.length;u++)if(r[c][s].tikis[u].product_id===t&&r[c][s].tikis[u].id_shop===n){l=r[c];break}if(!l)return i(!1);if(void 0===l[s])return i(!1);if(void 0===l[s].tikis)return i(!1);var d=!1;for(c=0;c<l[s].tikis.length;c++)if(l[s].tikis[c].product_id===t&&l[s].tikis[c].id_shop===n){for(var _=0;_<o.productlisttikis.length;_++)if(o.productlisttikis[_]._id===n)for(var p=0;p<o.productlisttikis[_].productlist.length;p++)if(o.productlisttikis[_].productlist[p].product_id===t){o.productlisttikis[_].productlist[p].hidden=e;break}l[s].tikis[c].hidden=e;var b={};b[s]=l[s],o.vhmongo_firebase.database().updateDoc("products",l._id,Object.assign({},b)).then((function(t){i(t)}),(function(t){a(t)})),d=!0;break}d||i(!1)}))},t.prototype.deleteMergeTikiProduct=function(t,e,n){var o=this;return new Promise((function(i,a){var s=o.getlocalProduct(t),r=o.getDefaultBranch()._id;if(void 0===s[r])return i(!1);if(void 0===s[r].tikis)return i(!1);for(var l=!1,c=0;c<s[r].tikis.length;c++)if(s[r].tikis[c].product_id===e&&s[r].tikis[c].id_shop===n){s[r].tikis.splice(c,1);var u={};u[r]=s[r],o.vhmongo_firebase.database().updateDoc("products",s._id,Object.assign({},u)).then((function(t){i(t)}),(function(t){a(t)})),l=!0;break}l||i(!1)}))},t.prototype.updateProductByXMLLazada=function(t,e){var n=this;return new Promise((function(o,i){var a=t;n.vhmongo_firebase.lazada().updateProductByXMLLazada(a,e).then((function(t){0===t.vcode?o(t.data):(console.log(t.message),o(!1))}),(function(t){i(t)}))}))},t.prototype.setStatusPackedLazada=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.lazada().setStatusPackedLazada(t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.setStatusReadyToShipLazada=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.lazada().setStatusReadyToShipLazada(t,e,n).then((function(t){i(t)}),(function(t){a(t)}))}))},t.prototype.getlocalProductListLazada=function(t){for(var e=0;e<this.productlistlazada.length;e++)if(this.productlistlazada[e]._id===t)return JSON.parse(JSON.stringify(this.productlistlazada[e].productlist));return[]},t.prototype.refreshLocalProductListLazadas=function(t){var e=this;return new Promise((function(n,o){""!=t&&null!=t?e.getProductListLazada(t).then((function(){n(null)})):e.getProductListLazadas().then((function(){n(null)}))}))},t.prototype.getProductListLazada=function(t){var e=this;return new Promise((function(n,o){var i=e.getDefaultBranch()._id;e.vhmongo_firebase.lazada().getShop(i,t).then((function(t){if(console.log("shoplazada",t),0===t.vcode){e.shoplistlazada=E(t.data),e.productlistlazada=E(t.data);for(var i=new Array,a=function(t){i[t]=new Promise((function(n,o){e.vhmongo_firebase.lazada().getProducts(e.productlistlazada[t].access_token).then((function(o){e.productlistlazada[t].productlist=o,n(null)}),(function(t){o(t)}))}))},s=0;s<e.productlistlazada.length;s++)a(s);Promise.all(i).then((function(){console.log("productlistlazadas",e.productlistlazada),n(null)}))}else console.log(t.message),o(t.message)}),(function(t){o(t)}))}))},t.prototype.getProductListLazadas=function(){var t=this;return new Promise((function(e,n){var o=t.getDefaultBranch()._id;t.vhmongo_firebase.lazada().getShopList(o).then((function(o){if(0===o.vcode){t.shoplistlazada=E(o.data),t.productlistlazada=E(o.data);for(var i=new Array,a=function(e){i[e]=new Promise((function(n,o){t.vhmongo_firebase.lazada().getProducts(t.productlistlazada[e].access_token).then((function(o){t.productlistlazada[e].productlist=o,n(null)}),(function(t){o(t)}))}))},s=0;s<t.productlistlazada.length;s++)a(s);Promise.all(i).then((function(){console.log("productlistlazadas",t.productlistlazada),e(null)}))}else console.log(o.message),n(o.message)}),(function(t){n(t)}))}))},t.prototype.getProductDetailLazada=function(t,e,n){var o=this;return new Promise((function(i,a){for(var s=[],r=0;r<t.length;r++)s[r]=o.vhmongo_firebase.lazada().getProductItem(t[r],e);Promise.all(s).then((function(t){for(var e=0;e<o.productlistlazada.length;e++)if(o.productlistlazada[e]._id===n)for(var a=0;a<t.length;a++)for(var s=0;s<o.productlistlazada[e].productlist.length;s++)if(t[a].item_id===o.productlistlazada[e].productlist[s].item_id){o.productlistlazada[e].productlist[s]=Object.assign(Object.assign({},o.productlistlazada[e].productlist[s]),t[a]);break}i(t)}))}))},t.prototype.getlocalShopListLazada=function(){return this.shoplistlazada},t.prototype.getShopListLazada=function(){var t=this;return new Promise((function(e,n){var o=t.getDefaultBranch()._id;t.vhmongo_firebase.lazada().getShopList(o).then((function(o){0===o.vcode?(t.shoplistlazada=o.data,e(o.data)):(console.log(o.message),n(o.message))}),(function(t){n(t)}))}))},t.prototype.signInLazada=function(t){var e=this;return new Promise((function(n,o){var i=e.getDefaultBranch()._id;e.vhmongo_firebase.lazada().signIn(i,t).then((function(t){window.location=t.data,n(!0)}),(function(t){o(t)}))}))},t.prototype.signOutLazada=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.lazada().signOut(t).then((function(i){if(0===i.vcode){for(var a=0;a<e.shoplistlazada.length;a++)if(e.shoplistlazada[a]._id===t){e.shoplistlazada.splice(a,1);break}for(a=0;a<e.productlistlazada.length;a++)if(e.productlistlazada[a]._id===t){e.productlistlazada.splice(a,1);break}n(!0)}else console.log(i.message),o(!1)}),(function(t){o(t)}))}))},t.prototype.addMergeLazadasProduct_skus=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=i.getDefaultBranch()._id,l=i.getlocalProduct(t),c={item_id:e,id_shop:o,skus:E(n)};null!=l[r]?void 0===l[r].lazadas&&(l[r].lazadas=new Array):(l[r]={},l[r].lazadas=new Array);for(var u=!1,d=0;d<l[r].lazadas.length;d++)if(l[r].lazadas[d].item_id===e&&l[r].lazadas[d].id_shop===o){var _;null!=l[r].lazadas[d].skus?l[r].lazadas[d].skus=E(l[r].lazadas[d].skus,n):l[r].lazadas[d].skus=E(n),(_={})[r]=l[r],i.vhmongo_firebase.database().updateDoc("products",t,Object.assign({},_)).then((function(){a(!0)}),(function(t){s(t)})),u=!0;break}u||(l[r].lazadas.push(c),(_={})[r]=l[r],i.vhmongo_firebase.database().updateDoc("products",t,Object.assign({},_)).then((function(){a(!0)}),(function(t){s(t)})))}))},t.prototype.updateMergeLazadasProduct=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=i.getlocalProduct(t),l=i.getDefaultBranch()._id;if(void 0===r[l])return a(!1);if(void 0===r[l].lazadas)return a(!1);for(var c=!1,u=0;u<r[l].lazadas.length;u++)if(r[l].lazadas[u].item_id===e&&r[l].lazadas[u].id_shop===o){r[l].lazadas[u]=Object.assign(Object.assign({},r[l].lazadas[u]),n);var d={};d[l]=r[l],i.vhmongo_firebase.database().updateDoc("products",t,Object.assign({},d)).then((function(t){a(t)}),(function(t){s(t)})),c=!0;break}c||a(!1)}))},t.prototype.updateMergeLazadasProduct_hidden=function(t,e,n){var o=this;return new Promise((function(i,a){for(var s=o.getDefaultBranch()._id,r=o.getlocalProducts(),l=null,c=0;c<r.length;c++)if(null!=r[c][s]&&null!=r[c][s].lazadas)for(var u=0;u<r[c][s].lazadas.length;u++)if(r[c][s].lazadas[u].item_id===t&&r[c][s].lazadas[u].id_shop===n){l=r[c];break}if(!l)return i(!1);if(void 0===l[s])return i(!1);if(void 0===l[s].lazadas)return i(!1);var d=!1;for(c=0;c<l[s].lazadas.length;c++)if(l[s].lazadas[c].item_id===t&&l[s].lazadas[c].id_shop===n){for(var _=0;_<o.productlistlazada.length;_++)if(o.productlistlazada[_]._id===n)for(var p=0;p<o.productlistlazada[_].productlist.length;p++)if(o.productlistlazada[_].productlist[p].item_id===t){o.productlistlazada[_].productlist[p].hidden=e;break}l[s].lazadas[c].hidden=e;var b={};b[s]=l[s],o.vhmongo_firebase.database().updateDoc("products",l._id,Object.assign({},b)).then((function(t){i(t)}),(function(t){a(t)})),d=!0;break}d||i(!1)}))},t.prototype.updateMergeLazadasProduct_skus=function(t,e,n,o,i){var a=this;return new Promise((function(s,r){var l=a.getlocalProduct(t),c=a.getDefaultBranch()._id;if(void 0===l[c])return s(!1);if(void 0===l[c].lazadas)return s(!1);for(var u=!1,d=0;d<l[c].lazadas.length;d++)if(l[c].lazadas[d].item_id===e&&l[c].lazadas[d].id_shop===i&&null!=l[c].lazadas[d].skus)for(var _=0;_<l[c].lazadas[d].skus.length;_++)if(l[c].lazadas[d].skus[_].SkuId===n){l[c].lazadas[d].skus[_]=Object.assign(Object.assign({},l[c].lazadas[d].skus[_]),o);var p={};p[c]=l[c],a.vhmongo_firebase.database().updateDoc("products",t,Object.assign({},p)).then((function(t){s(t)}),(function(t){r(t)})),u=!0;break}u||s(!1)}))},t.prototype.deleteMergeLazadaProduct_skus=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=i.getlocalProduct(t),l=i.getDefaultBranch()._id;if(void 0===r[l])return a(!1);if(void 0===r[l].lazadas)return a(!1);for(var c=!1,u=0;u<r[l].lazadas.length;u++)if(r[l].lazadas[u].item_id===e&&r[l].lazadas[u].id_shop===o&&null!=r[l].lazadas[u].skus){for(var d=0;d<r[l].lazadas[u].skus.length;d++)if(r[l].lazadas[u].skus[d].SkuId===n){r[l].lazadas[u].skus.splice(d,1),(_={})[l]=r[l],i.vhmongo_firebase.database().updateDoc("products",r._id,Object.assign({},_)).then((function(t){a(t)}),(function(t){s(t)})),c=!0;break}var _;if(0===r[l].lazadas[u].skus.length)r[l].lazadas.splice(u,1),(_={})[l]=r[l],i.vhmongo_firebase.database().updateDoc("products",r._id,Object.assign({},_)).then((function(t){a(t)}),(function(t){s(t)})),c=!0}c||a(!1)}))},t.prototype.getSalesOrderListLazada=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Promise((function(a,s){i.vhmongo_firebase.lazada().getOrders(t,e,n).then((function(t){i.productlistlazada.forEach((function(e){e._id===o&&(e.salesorderdetaillist=t)})),a(t)}),(function(t){s(t)}))})),l=new Promise((function(n,a){var s={created_at:{$gte:new Date(t),$lte:new Date(e)}};i.vhmongo_firebase.database().getDocsByFields(o,s,{},{},0).then((function(t){n(t)}))}));Promise.all([r,l]).then((function(t){t[0].filter((function(e){var n=!0;return t[1].forEach((function(t){e.order_id.toString()===t._id&&(n=!1)})),n})).forEach((function(t){i.vhmongo_firebase.database().addDocbyID(o.toString(),t.order_id.toString(),{created_at:new Date(t.created_at)})}));for(var e=0;e<t[0].length;e++)for(var n=0;n<t[1].length;n++)if(t[0][e].order_id===t[1][n]._id){var s=Object.assign({},t[1][n]);delete s._id,t[0][e]=Object.assign(Object.assign({},t[0][e]),s)}console.log("salesorderdetaillist",t[0]),a(t[0])}))}))},t.prototype.getSalesOrderDetailListLazada=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Promise((function(a,s){i.vhmongo_firebase.lazada().getOrdersDetail(t,e,n).then((function(t){i.productlistlazada.forEach((function(e){e._id===o&&(e.salesorderdetaillist=t)})),a(t)}),(function(t){s(t)}))})),l=new Promise((function(n,a){var s={created_at:{$gte:new Date(t),$lte:new Date(e)}};i.vhmongo_firebase.database().getDocsByFields(o,s,{},{},0).then((function(t){n(t)}))}));Promise.all([r,l]).then((function(t){t[0].filter((function(e){var n=!0;return t[1].forEach((function(t){e.order_id.toString()===t._id&&(n=!1)})),n})).forEach((function(t){i.vhmongo_firebase.database().addDocbyID(o.toString(),t.order_id.toString(),{created_at:new Date(t.order_items[0].created_at)})}));for(var e=0;e<t[0].length;e++){delete t[0][e].order_number;for(var n=0;n<t[1].length;n++)if(String(t[0][e].order_id)===t[1][n]._id){var s=Object.assign({},t[1][n]);delete s._id,delete s.created_at,t[0][e]=Object.assign(Object.assign({},t[0][e]),s);break}}console.log("salesorderdetaillist",t[0]),a(t[0])}))}))},t.prototype.getSalesOrderDetailLazada=function(t,e,n){var o=this;return new Promise((function(i,a){var s=o.vhmongo_firebase.lazada().getOrderDetail(t,e),r=o.vhmongo_firebase.database().getDoc(n,t);Promise.all([s,r]).then((function(t){t[0]&&(t[1]||o.vhmongo_firebase.database().addDocbyID(n,t[0].order_id,{created_at:new Date(t[0].sales_order.created_at)})),i(t[0])}))}))},t.prototype.getSalesOrderLazada_fromViethas=function(t,e){var n=this;return new Promise((function(o,i){for(var a=new Array,s=0;s<t.length;s++)a[s]=n.vhmongo_firebase.database().getDoc(e,t[s]);Promise.all(a).then((function(t){o(t)}))}))},t.prototype.getSalesOrderDetailListLazada_fromViethas=function(t,e,n){var o=this;return new Promise((function(i,a){var s={order_date_time_stamp:{$gte:new Date(t),$lte:new Date(e)}};o.vhmongo_firebase.database().getDocsByFields(n,s,{},{order_date_time_stamp:1},0).then((function(t){i(t)}))}))},t.prototype.updateSalesOrderLazada=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.database().updateDoc(t,e,n).then((function(a){a&&o.productlistlazada.forEach((function(o){o._id===t&&o.salesorderdetaillist.forEach((function(t){t.order_id===e&&(t=Object.assign(Object.assign({},t),n))}))})),i(a)}),(function(t){a(t)}))}))},t.prototype.updateSalesOrderLazada_byFile=function(t,e,n,o){var i=this;return new Promise((function(a,s){for(var r=new Array,l=function(a){r[a]=new Promise((function(s){i.vhmongo_firebase.lazada().getOrderDetail(t[a],n).then((function(n){n?i.vhmongo_firebase.database().getDoc(o,t[a]).then((function(n){n?i.vhmongo_firebase.database().updateDoc(o,t[a],e).then((function(t){s(t)}),(function(){s(!1)})):i.vhmongo_firebase.database().addDocbyID(o,t[a],e).then((function(){s(!0)}))})):s(!1)}),(function(){s(!1)}))}))},c=0;c<t.length;c++)l(c);Promise.all(r).then((function(t){a(t)}))}))},t.prototype.getShopPartner=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("bills",{id_shop:{$eq:t}},{},{},1).then((function(t){0===t.length?n(null):n(e.getlocalCustomer(t[0].id_customer))}),(function(t){o(t)}))}))},t.prototype.updateShop=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().getDoc("ecommerces",t).then((function(a){if(a){var s={};s=null!=a.data?Object.assign(Object.assign({},a.data),e):Object.assign({},e),n.vhmongo_firebase.database().updateDoc("ecommerces",t,{data:s}).then((function(e){for(var i=0;i<n.shoplistlazada.length;i++)if(n.shoplistlazada[i]._id===t){n.shoplistlazada[i].data=s;break}for(i=0;i<n.shoplistsendo.length;i++)if(n.shoplistsendo[i]._id===t){n.shoplistsendo[i].data=s;break}for(i=0;i<n.shoplisttiki.length;i++)if(n.shoplisttiki[i]._id===t){n.shoplisttiki[i].data=s;break}o(e)}),(function(t){i(t)}))}else o(!1)}))}))},t.prototype.updateByJSONSendo=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.sendo().updateByJSONSendo(t,e).then((function(t){0===t.vcode?o(t.data):(console.log(t.message),o(null))}),(function(t){i(t)}))}))},t.prototype.updateOrderStatusSendo=function(t,e,n,o){var i=this;return new Promise((function(a,s){i.vhmongo_firebase.sendo().updateOrderStatusSendo(t,e,n,o).then((function(t){a(t)}),(function(t){s(t)}))}))},t.prototype.getSalesOrderDetailListSendo=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Promise((function(a,s){i.vhmongo_firebase.sendo().getSalesOrderPageTokensSendo(t,e,n).then((function(r){var l=r;i.vhmongo_firebase.sendo().getSalesOrderDetailPages(t,e,l,n).then((function(t){i.productlistsendo.forEach((function(e){e._id===o&&(e.salesorderdetaillist=t)})),a(t)}),(function(t){s(t)}))}),(function(t){s(t)}))})),l=new Promise((function(n,a){var s={order_date_time_stamp:{$gte:new Date(t),$lte:new Date(e)}};i.vhmongo_firebase.database().getDocsByFields(o,s).then((function(t){n(t)}))}));Promise.all([r,l]).then((function(t){var e=t[0].filter((function(e){var n=!0;return t[1].forEach((function(t){e.sales_order.order_number===t._id&&(n=!1)})),n})),n=(new Date).getTimezoneOffset();e.forEach((function(t){i.vhmongo_firebase.database().addDocbyID(o,t.sales_order.order_number,{order_date_time_stamp:new Date(1e3*(t.sales_order.order_date_time_stamp+60*n))})}));for(var s=0;s<t[0].length;s++)for(var r=0;r<t[1].length;r++)if(t[0][s].sales_order.order_number===t[1][r]._id){var l=Object.assign({},t[1][r]);delete l._id,delete l.order_date_time_stamp,t[0][s].sales_order=Object.assign(Object.assign({},t[0][s].sales_order),l)}a(t[0])}))}))},t.prototype.getSalesOrderDetailSendo=function(t,e,n){var o=this;return new Promise((function(i,a){var s=o.vhmongo_firebase.sendo().getSalesOrderDetail(t,e),r=o.vhmongo_firebase.database().getDoc(n,t);Promise.all([s,r]).then((function(t){if(t[0]){var e=(new Date).getTimezoneOffset();t[1]||o.vhmongo_firebase.database().addDocbyID(n,t[0].sales_order.order_number,{order_date_time_stamp:new Date(1e3*(t[0].sales_order.order_date_time_stamp+60*e))})}i(t[0])}))}))},t.prototype.getSalesOrderSendo_fromViethas=function(t,e){var n=this;return new Promise((function(o,i){for(var a=new Array,s=0;s<t.length;s++)a[s]=n.vhmongo_firebase.database().getDoc(e,t[s]);Promise.all(a).then((function(t){o(t)}))}))},t.prototype.getSalesOrderDetailListSendo_fromViethas=function(t,e,n){var o=this;return new Promise((function(i,a){var s={order_date_time_stamp:{$gte:new Date(t),$lte:new Date(e)}};o.vhmongo_firebase.database().getDocsByFields(n,s,{},{order_date_time_stamp:1},0).then((function(t){i(t)}))}))},t.prototype.updateSalesOrderSendo=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.database().updateDoc(t,e,n).then((function(a){a&&o.productlistsendo.forEach((function(o){o._id===t&&o.salesorderdetaillist.forEach((function(t){t.sales_order.order_number===e&&(t.sales_order=Object.assign(Object.assign({},t.sales_order),n))}))})),i(a)}),(function(t){a(t)}))}))},t.prototype.updateSalesOrderSendo_byFile=function(t,e,n,o){var i=this;return new Promise((function(a,s){for(var r=new Array,l=function(a){r[a]=new Promise((function(s){i.vhmongo_firebase.sendo().getSalesOrderDetail(t[a],n).then((function(n){n?i.vhmongo_firebase.database().getDoc(o,t[a]).then((function(n){n?i.vhmongo_firebase.database().updateDoc(o,t[a],e).then((function(t){s(t)}),(function(){s(!1)})):i.vhmongo_firebase.database().addDocbyID(o,t[a],e).then((function(){s(!0)}))})):s(!1)}),(function(){s(!1)}))}))},c=0;c<t.length;c++)l(c);Promise.all(r).then((function(t){a(t)}))}))},t.prototype.getlocalShopListSendo=function(){return this.shoplistsendo},t.prototype.getlocalProductListSendo=function(t){for(var e=0;e<this.productlistsendo.length;e++)if(this.productlistsendo[e]._id===t)return JSON.parse(JSON.stringify(this.productlistsendo[e].productlist));return[]},t.prototype.refreshLocalProductListSendo=function(t){var e=this;return new Promise((function(n,o){""!=t&&null!=t?e.getProductListSendo(t).then((function(){n(null)})):e.getProductListSendos().then((function(){n(null)}))}))},t.prototype.getProductListSendo=function(t){var e=this;return new Promise((function(n,o){var i=e.getDefaultBranch()._id;e.vhmongo_firebase.sendo().getShop(i,t).then((function(t){if(console.log("shopsendo",t),0===t.vcode){e.shoplistsendo=E(t.data),e.productlistsendo=E(t.data);for(var i=new Array,a=function(t){i[t]=new Promise((function(n,o){e.vhmongo_firebase.sendo().getProductListSendo(e.productlistsendo[t].token).then((function(o){e.productlistsendo[t].productlist=o,n(o)}))}))},s=0;s<e.productlistsendo.length;s++)a(s);Promise.all(i).then((function(){console.log("productlistsendo",e.productlistsendo),n(null)}))}else console.log("lỗi:",t.message),o(t.message)}),(function(t){o(t)}))}))},t.prototype.getProductListSendos=function(){var t=this;return new Promise((function(e,n){var o=t.getDefaultBranch()._id;t.vhmongo_firebase.sendo().getShopList(o).then((function(o){if(console.log("shoplist",o),0===o.vcode){t.shoplistsendo=E(o.data),t.productlistsendo=E(o.data);for(var i=new Array,a=function(e){i[e]=new Promise((function(n,o){t.vhmongo_firebase.sendo().getProductListSendo(t.productlistsendo[e].token).then((function(o){t.productlistsendo[e].productlist=o,n(o)}))}))},s=0;s<t.productlistsendo.length;s++)a(s);Promise.all(i).then((function(){console.log("productlistsendo",t.productlistsendo),e(null)}))}else console.log("lỗi:",o.message),n(o.message)}),(function(t){n(t)}))}))},t.prototype.getProductDetailSendo=function(t,e,n){var o=this;return new Promise((function(i,a){for(var s=[],r=0;r<t.length;r++)s[r]=o.vhmongo_firebase.sendo().getProductDetail(t[r],e);Promise.all(s).then((function(t){for(var e=0;e<o.productlistsendo.length;e++)if(o.productlistsendo[e]._id===n)for(var a=0;a<t.length;a++)for(var s=0;s<o.productlistsendo[e].productlist.length;s++)if(t[a].id===o.productlistsendo[e].productlist[s].id){o.productlistsendo[e].productlist[s]=Object.assign(Object.assign({},o.productlistsendo[e].productlist[s]),t[a]);break}i(t)}))}))},t.prototype.signInSendo=function(t,e,n){var o=this;return new Promise((function(i,a){var s=o.getDefaultBranch()._id;o.vhmongo_firebase.sendo().signIn(t,e,n,s).then((function(t){0===t.vcode?(o.shoplistsendo.push(t.data),i(t.data)):(console.log(t.message),i(null))}),(function(t){a(t)}))}))},t.prototype.signOutSendo=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.sendo().signOut(t).then((function(i){if(0===i.vcode){for(var a=0;a<e.shoplistsendo.length;a++)if(e.shoplistsendo[a]._id===t){e.shoplistsendo.splice(a,1);break}for(a=0;a<e.productlistsendo.length;a++)if(e.productlistsendo[a]._id===t){e.productlistsendo.splice(a,1);break}n(!0)}else console.log(i.message),o(!1)}),(function(t){o(t)}))}))},t.prototype.getShopListSendo=function(){var t=this;return new Promise((function(e,n){var o=t.getDefaultBranch()._id;t.vhmongo_firebase.sendo().getShopList(o).then((function(o){0===o.vcode?(t.shoplistsendo.push(o.data),e(o.data)):(console.log(o.message),n(o.message))}),(function(t){n(t)}))}))},t.prototype.addMergeSendoProduct_variants=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=i.getDefaultBranch()._id,l=i.getlocalProduct(t),c={id:e,id_shop:o,variants:E(n)};null!=l[r]?void 0===l[r].sendos&&(l[r].sendos=new Array):(l[r]={},l[r].sendos=new Array);for(var u=!1,d=0;d<l[r].sendos.length;d++)if(l[r].sendos[d].id===e&&l[r].sendos[d].id_shop===o){var _;null!=l[r].sendos[d].variants?l[r].sendos[d].variants=E(l[r].sendos[d].variants,n):l[r].sendos[d].variants=E(n),(_={})[r]=l[r],i.vhmongo_firebase.database().updateDoc("products",t,Object.assign({},_)).then((function(){a(!0)}),(function(t){s(t)})),u=!0;break}u||(l[r].sendos.push(c),(_={})[r]=l[r],i.vhmongo_firebase.database().updateDoc("products",t,Object.assign({},_)).then((function(){a(!0)}),(function(t){s(t)})))}))},t.prototype.updateMergeSendoProduct=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=i.getlocalProduct(t),l=i.getDefaultBranch()._id;if(void 0===r[l])return a(!1);if(void 0===r[l].sendos)return a(!1);for(var c=!1,u=0;u<r[l].sendos.length;u++)if(r[l].sendos[u].id===e&&r[l].sendos[u].id_shop===o){r[l].sendos[u]=Object.assign(Object.assign({},r[l].sendos[u]),n);var d={};d[l]=r[l],i.vhmongo_firebase.database().updateDoc("products",t,Object.assign({},d)).then((function(t){a(t)}),(function(t){s(t)})),c=!0;break}c||a(!1)}))},t.prototype.updateMergeSendoProduct_hidden=function(t,e,n){var o=this;return new Promise((function(i,a){for(var s=o.getDefaultBranch()._id,r=o.getlocalProducts(),l=null,c=0;c<r.length;c++)if(null!=r[c][s]&&null!=r[c][s].sendos)for(var u=0;u<r[c][s].sendos.length;u++)if(r[c][s].sendos[u].id===t&&r[c][s].sendos[u].id_shop===n){l=r[c];break}if(!l)return i(!1);if(void 0===l[s])return i(!1);if(void 0===l[s].sendos)return i(!1);var d=!1;for(c=0;c<l[s].sendos.length;c++)if(l[s].sendos[c].id===t&&l[s].sendos[c].id_shop===n){for(var _=0;_<o.productlistlazada.length;_++)if(o.productlistlazada[_]._id===n)for(var p=0;p<o.productlistlazada[_].productlist.length;p++)if(o.productlistlazada[_].productlist[p].id===t){o.productlistlazada[_].productlist[p].hidden=e;break}l[s].sendos[c].hidden=e;var b={};b[s]=l[s],o.vhmongo_firebase.database().updateDoc("products",l._id,Object.assign({},b)).then((function(t){i(t)}),(function(t){a(t)})),d=!0;break}d||i(!1)}))},t.prototype.updateMergeSendoProduct_variants=function(t,e,n,o,i){var a=this;return new Promise((function(s,r){var l=a.getlocalProduct(t),c=a.getDefaultBranch()._id;if(void 0===l[c])return s(!1);if(void 0===l[c].sendos)return s(!1);for(var u=!1,d=0;d<l[c].sendos.length;d++)if(l[c].sendos[d].id===e&&l[c].sendos[d].id_shop===i&&null!=l[c].sendos[d].variants)for(var _=0;_<l[c].sendos[d].variants.length;_++)if(l[c].sendos[d].variants[_].variant_attribute_hash===n){l[c].sendos[d].variants[_]=Object.assign(Object.assign({},l[c].sendos[d].variants[_]),o);var p={};p[c]=l[c],a.vhmongo_firebase.database().updateDoc("products",t,Object.assign({},p)).then((function(t){s(t)}),(function(t){r(t)})),u=!0;break}u||s(!1)}))},t.prototype.deleteMergeSendoProduct_variants=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=i.getlocalProduct(t),l=i.getDefaultBranch()._id;if(void 0===r[l])return a(!1);if(void 0===r[l].sendos)return a(!1);for(var c=!1,u=0;u<r[l].sendos.length;u++)if(r[l].sendos[u].id===e&&r[l].sendos[u].id_shop===o&&null!=r[l].sendos[u].variants){for(var d=0;d<r[l].sendos[u].variants.length;d++)if(r[l].sendos[u].variants[d].variant_attribute_hash===n){r[l].sendos[u].variants.splice(d,1),(_={})[l]=r[l],i.vhmongo_firebase.database().updateDoc("products",r._id,Object.assign({},_)).then((function(t){a(t)}),(function(t){s(t)})),c=!0;break}var _;if(0===r[l].sendos[u].variants.length)r[l].sendos.splice(u,1),(_={})[l]=r[l],i.vhmongo_firebase.database().updateDoc("products",r._id,Object.assign({},_)).then((function(t){a(t)}),(function(t){s(t)})),c=!0}c||a(!1)}))},t.prototype.getReportSales_Sendo=function(t,e,n,o,i){},t.prototype.fixOldVersion=function(t){var e=this;return 1===t?new Promise((function(t,n){var o=e.getDefaultBranch();e.vhmongo_firebase.database().getDocs("vhbill_details").then((function(n){var i=new Array;if(n.length>0){for(var a=0;a<n.length;a++)void 0===n[a].id_branch&&(i[i.length]=e.vhmongo_firebase.database().updateDoc("vhbill_details",n[a]._id,{id_branch:o._id}));Promise.all(i).then((function(e){console.log("array_promise.length",e.length),t(!0)}))}else t(!1)})).catch((function(t){n(t)}))})):2===t?new Promise((function(t,n){var o=e.getDefaultBranch();e.vhmongo_firebase.database().getDocs("wallets").then((function(n){var i=new Array;if(n.length>0){for(var a=0;a<n.length;a++)"id_cash"!=n[a]._id&&void 0===n[a].id_branch&&(i[i.length]=e.vhmongo_firebase.database().updateDoc("wallets",n[a]._id,{id_branch:o._id}));Promise.all(i).then((function(e){console.log("array_promise.length",e.length),t(!0)}))}else t(!1)})).catch((function(t){n(t)}))})):3===t?new Promise((function(t,n){e.vhmongo_firebase.database().getDocs("vhbill_details").then((function(n){var o=new Array;if(n.length>0){for(var i=0;i<n.length;i++)if(void 0===n[i].id_category&&null!=n[i].id_product){var a=e.getlocalProduct(n[i].id_product).id_category;o[o.length]=e.vhmongo_firebase.database().updateDoc("vhbill_details",n[i]._id,{id_category:a})}Promise.all(o).then((function(e){console.log("array_promise",e),t(!0)}))}else t(!1)})).catch((function(t){n(t)}))})):void 0},t.prototype.syncCollections_Mobile=function(){var t=this;return new Promise((function(e,n){t.initSyncCollections(),t.callbackCollectionInsert().subscribe(),t.callbackCollectionUpdate().subscribe(),t.callbackCollectionDelete().subscribe(),setTimeout((function(){t.checkExpireBranch_Sales(),e(!0)}),3e3)}))},t.prototype.syncCollections_Desktop=function(){var t=this;return new Promise((function(e,n){t.initSyncCollections(),t.callbackCollectionInsert().subscribe(),t.callbackCollectionUpdate().subscribe(),t.callbackCollectionDelete().subscribe(),setTimeout((function(){t.syncCashBookEveryDay_Stock1stDayOfMonth().then((function(){t.syncInventoryEveryDay_Stock1stDayOfMonth().then((function(){e(!0)})),t.checkExpireBranch_Sales()}))}),3e3)}))},t.prototype.checkExpireBranch_Sales=function(){if(this.getDefaultBranch()){var t=this.getDefaultBranch()._id;this.vhmongo_firebase.auth().checkExpireBranch_Sales(t).then((function(){console.log("success checkExpireBranch_Sales")}),(function(t){console.log("no success checkExpireBranch_Sales")}))}},t.prototype.fixBill=function(){var t=this;return new Promise((function(e,n){var o={date:{$gte:new Date("2021-12-09T05:24:00"),$lte:new Date("2021-12-09T05:24:00")}};t.vhmongo_firebase.database().getDocsByFields("bills",o,{},{date:1},0).then((function(n){if(n.length>0)for(var o=0;o<n.length;o++)t.vhmongo_firebase.database().getDocsByFields("vhbill_details",{id_bill:{$eq:n[o]._id}},{},{},0).then((function(e){for(var n=0;n<e.length;n++)if(void 0===e[n].ptype&&null!=e[n].id_product){var o=t.getlocalProduct(e[n].id_product);null!=o&&(console.log("product.type",o.type),t.vhmongo_firebase.database().updateDoc("vhbill_details",e[n]._id,{ptype:o.type}))}}));e(null)}))}))},t.prototype.initSyncCollections=function(){this.categorys=new Array,this.products=new Array,this.suppliers=new Array,this.customers=new Array,this.wallets=new Array,this.branchs=new Array,this.taxs=new Array,this.promotions=new Array,this.inventorytimes=new Array,this.appsettingbranchs=new Array,this.appsettingstations=new Array,this.printers=new Array,this.warrantys=new Array,this.vhAuth.clearLocalEmployeeFromSyncCollection();var t=new Array;return t[0]="categorys",t[1]="warrantys",t[2]="suppliers",t[3]="customers",t[4]="wallets",t[5]="branchs",t[6]="taxs",t[7]="vhemployees",t[8]="promotions",t[9]="inventorytimes",t[10]="appsettingstations",t[11]="appsettingbranchs",t[12]="printers",t[13]="products",t[14]="discount_bills",t[15]="customer_classs",this.vhmongo_firebase.socketMongoDB().initSyncCollections(t)},t.prototype.closeSyncCollections=function(){this.vhmongo_firebase.socketMongoDB().closeSyncCollections()},t.prototype.callbackCollectionInsert=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackCollectionInsert().subscribe((function(n){if("vhemployees"===n.colname&&(n.colname="employees"),"categorys"===n.colname)t.getlocalCategory(n._id)||((o=Object.assign({},n.data))._id=n._id,t.categorys.push(o),t.publishObservableEventCategorys(),e.next(n.colname));else if("products"===n.colname){if(!t.getlocalProduct(n._id))(o=Object.assign({},n.data))._id=n._id,t.products.push(o),t.publishObservableEventProducts(),e.next(n.colname);e.next(n.colname)}else if("suppliers"===n.colname){if(!t.getlocalSupplier(n._id))(o=Object.assign({},n.data))._id=n._id,t.suppliers.push(o),t.publishObservableEventSuppliers(),e.next(n.colname)}else if("customers"===n.colname){if(!t.getlocalCustomer(n._id))(o=Object.assign({},n.data))._id=n._id,t.customers.push(o),t.publishObservableEventCustomers(),e.next(n.colname)}else if("wallets"===n.colname){if(!t.getlocalWallet(n._id))(o=Object.assign({},n.data))._id=n._id,t.wallets.push(o),t.publishObservableEventWallets(),e.next(n.colname)}else if("branchs"===n.colname){if(!t.getlocalBranch(n._id))(o=Object.assign({},n.data))._id=n._id,t.branchs.push(o),t.publishObservableEventBranchs(),e.next(n.colname)}else if("taxs"===n.colname){if(!t.getlocalTax(n._id))(o=Object.assign({},n.data))._id=n._id,t.taxs.push(o),t.publishObservableEventTaxs(),e.next(n.colname)}else if("employees"===n.colname){(o=Object.assign({},n.data))._id=n._id,t.vhAuth.insertlocalEmployeeFromSyncCollection(o),t.vhAuth.publishObservableEventEmployees(),e.next(n.colname)}else if("promotions"===n.colname){if(!t.getlocalPromotion(n._id))(o=Object.assign({},n.data))._id=n._id,t.promotions.push(o),t.publishObservableEventPromotions(),e.next(n.colname)}else if("inventorytimes"===n.colname){if(!t.getlocalInventorytime(n._id))(o=Object.assign({},n.data))._id=n._id,t.inventorytimes.push(o),t.publishObservableEventInventorytimes(),e.next(n.colname)}else if("appsettingbranchs"===n.colname){if(!t.getLocalAppSettingBranch(n._id)&&n.data.id_branch===t.getDefaultBranch()._id){var o=Object.assign(Object.assign({},n.data),{_id:n._id});t.appsettingbranchs.push(o),t.publishObservableEventAppSettingNameBranchs(),e.next(n.colname)}}else if("appsettingstations"===n.colname){if(!t.getLocalAppSettingStation(n._id))if(n.data.uuid===t.hwinfo.uuid)(o=Object.assign({},n.data))._id=n._id,delete o.uuid,t.appsettingstations.push(o),t.publishObservableEventAppSettingNameStations(),e.next(n.colname)}else if("printers"===n.colname){if(!t.getlocalPrinter(n._id))if(n.data.uuid===t.hwinfo.uuid)(o=Object.assign({},n.data))._id=n._id,delete o.uuid,t.printers.push(o),t.publishObservableEventPrinters(),e.next(n.colname)}else if("warrantys"===n.colname){if(!t.getlocalWarranty(n._id))(o=Object.assign({},n.data))._id=n._id,t.warrantys.push(o),t.publishObservableEventWarrantys(),e.next(n.colname)}else if("discount_bills"===n.colname){if(!t.getlocalDiscount_bill(n._id))(o=Object.assign({},n.data))._id=n._id,t.discount_bills.push(o),t.publishObservableEventDiscount_bills(),e.next(n.colname)}else if("customer_classs"===n.colname){if(!t.getlocalCustomerClass(n._id))(o=Object.assign({},n.data))._id=n._id,t.customer_classs.push(o),t.publishObservableEventCustomerClasss(),e.next(n.colname)}console.log("inserted",n.colname)}))}))},t.prototype.callbackCollectionUpdate=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackCollectionUpdate().subscribe((function(n){if("vhemployees"===n.colname?n.colname="employees":"branchs"===n.colname?n.colname="branchs":"printers"===n.colname?n.colname="printers":"appsettingstations"===n.colname&&(n.colname="appsettingstations"),"categorys"===n.colname){for(var o=0;o<t.categorys.length;o++)if(t.categorys[o]._id===n._id){t.categorys[o]=Object.assign(Object.assign({},t.categorys[o]),n.data),t.publishObservableEventCategorys(),e.next(n.colname);break}}else if("products"===n.colname){for(o=0;o<t.products.length;o++)if(t.products[o]._id===n._id){t.products[o]=Object.assign(Object.assign({},t.products[o]),n.data),t.publishObservableEventProducts(),e.next(n.colname);break}}else if("suppliers"===n.colname){for(o=0;o<t.suppliers.length;o++)if(t.suppliers[o]._id===n._id){t.suppliers[o]=Object.assign(Object.assign({},t.suppliers[o]),n.data),t.publishObservableEventSuppliers(),e.next(n.colname);break}}else if("customers"===n.colname){for(o=0;o<t.customers.length;o++)if(t.customers[o]._id===n._id){t.customers[o]=Object.assign(Object.assign({},t.customers[o]),n.data),t.publishObservableEventCustomers(),e.next(n.colname);break}}else if("wallets"===n.colname){for(o=0;o<t.wallets.length;o++)if(t.wallets[o]._id===n._id){t.wallets[o]=Object.assign(Object.assign({},t.wallets[o]),n.data),t.publishObservableEventWallets(),e.next(n.colname);break}}else if("branchs"===n.colname){for(o=0;o<t.branchs.length;o++)if(t.branchs[o]._id===n._id){t.branchs[o]=Object.assign(Object.assign({},t.branchs[o]),n.data),t.publishObservableEventBranchs(),e.next(n.colname);break}}else if("taxs"===n.colname){for(o=0;o<t.taxs.length;o++)if(t.taxs[o]._id===n._id){t.taxs[o]=Object.assign(Object.assign({},t.taxs[o]),n.data),t.publishObservableEventTaxs(),e.next(n.colname);break}}else if("employees"===n.colname)t.vhAuth.updateLocalEmployeeFromSyncCollection(n._id,n.data),t.vhAuth.publishObservableEventEmployees(),e.next(n.colname);else if("promotions"===n.colname){for(o=0;o<t.promotions.length;o++)if(t.promotions[o]._id===n._id){t.promotions[o]=Object.assign(Object.assign({},t.promotions[o]),n.data),t.publishObservableEventPromotions(),e.next(n.colname);break}}else if("inventorytimes"===n.colname){for(o=0;o<t.inventorytimes.length;o++)if(t.inventorytimes[o]._id===n._id){t.inventorytimes[o]=Object.assign(Object.assign({},t.inventorytimes[o]),n.data),t.publishObservableEventInventorytimes(),e.next(n.colname);break}}else if("appsettingbranchs"===n.colname){for(o=0;o<t.appsettingbranchs.length;o++)if(t.appsettingbranchs[o]._id===n._id){t.appsettingbranchs[o]=Object.assign(Object.assign({},t.appsettingbranchs[o]),n.data),t.publishObservableEventAppSettingNameBranchs(),e.next(n.colname);break}}else if("appsettingstations"===n.colname){for(o=0;o<t.appsettingstations.length;o++)if(t.appsettingstations[o]._id===n._id){t.appsettingstations[o]=Object.assign(Object.assign({},t.appsettingstations[o]),n.data),t.publishObservableEventAppSettingNameStations(),e.next(n.colname);break}}else if("printers"===n.colname){for(o=0;o<t.printers.length;o++)if(t.printers[o]._id===n._id){t.printers[o]=Object.assign(Object.assign({},t.printers[o]),n.data),t.publishObservableEventPrinters(),e.next(n.colname);break}}else if("warrantys"===n.colname){for(o=0;o<t.warrantys.length;o++)if(t.warrantys[o]._id===n._id){t.warrantys[o]=Object.assign(Object.assign({},t.warrantys[o]),n.data),t.publishObservableEventWarrantys(),e.next(n.colname);break}}else if("discount_bills"===n.colname){for(o=0;o<t.discount_bills.length;o++)if(t.discount_bills[o]._id===n._id){t.discount_bills[o]=Object.assign(Object.assign({},t.discount_bills[o]),n.data),t.publishObservableEventDiscount_bills(),e.next(n.colname);break}}else if("customer_classs"===n.colname)for(o=0;o<t.customer_classs.length;o++)if(t.customer_classs[o]._id===n._id){t.customer_classs[o]=Object.assign(Object.assign({},t.customer_classs[o]),n.data),t.publishObservableEventCustomerClasss(),e.next(n.colname);break}console.log("updated",n.colname)}))}))},t.prototype.callbackCollectionDelete=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackCollectionDelete().subscribe((function(n){if("vhemployees"===n.colname&&(n.colname="employees"),"categorys"===n.colname){for(var o=0;o<t.categorys.length;o++)if(t.categorys[o]._id===n._id){t.categorys.splice(o,1),t.publishObservableEventCategorys(),e.next(n.colname);break}}else if("products"===n.colname){for(o=0;o<t.products.length;o++)if(t.products[o]._id===n._id){t.products.splice(o,1),t.publishObservableEventProducts(),e.next(n.colname);break}}else if("suppliers"===n.colname){for(o=0;o<t.suppliers.length;o++)if(t.suppliers[o]._id===n._id){t.suppliers.splice(o,1),t.publishObservableEventSuppliers(),e.next(n.colname);break}}else if("customers"===n.colname){for(o=0;o<t.customers.length;o++)if(t.customers[o]._id===n._id){t.customers.splice(o,1),t.publishObservableEventCustomers(),e.next(n.colname);break}}else if("wallets"===n.colname){for(o=0;o<t.wallets.length;o++)if(t.wallets[o]._id===n._id){t.wallets.splice(o,1),t.publishObservableEventWallets(),e.next(n.colname);break}}else if("branchs"===n.colname){for(o=0;o<t.branchs.length;o++)if(t.branchs[o]._id===n._id){t.branchs.splice(o,1),t.publishObservableEventBranchs(),e.next(n.colname);break}}else if("taxs"===n.colname){for(o=0;o<t.taxs.length;o++)if(t.taxs[o]._id===n._id){t.taxs.splice(o,1),t.publishObservableEventTaxs(),e.next(n.colname);break}}else if("employees"===n.colname)t.vhAuth.deleteLocalEmployeeFromSyncCollection(n._id),t.vhAuth.publishObservableEventEmployees(),e.next(n.colname);else if("promotions"===n.colname){for(o=0;o<t.promotions.length;o++)if(t.promotions[o]._id===n._id){t.promotions.splice(o,1),t.publishObservableEventPromotions(),e.next(n.colname);break}}else if("inventorytimes"===n.colname){for(o=0;o<t.inventorytimes.length;o++)if(t.inventorytimes[o]._id===n._id){t.inventorytimes.splice(o,1),t.publishObservableEventInventorytimes(),e.next(n.colname);break}}else if("appsettingbranchs"===n.colname){for(o=0;o<t.appsettingbranchs.length;o++)if(t.appsettingbranchs[o]._id===n._id){t.appsettingbranchs.splice(o,1),t.publishObservableEventAppSettingNameBranchs(),e.next(n.colname);break}}else if("appsettingstations"===n.colname){for(o=0;o<t.appsettingstations.length;o++)if(t.appsettingstations[o]._id===n._id){t.appsettingstations.splice(o,1),t.publishObservableEventAppSettingNameStations(),e.next(n.colname);break}}else if("printers"===n.colname){for(o=0;o<t.printers.length;o++)if(t.printers[o]._id===n._id){t.printers.splice(o,1),t.publishObservableEventPrinters(),e.next(n.colname);break}}else if("warrantys"===n.colname){for(o=0;o<t.warrantys.length;o++)if(t.warrantys[o]._id===n._id){t.warrantys.splice(o,1),t.publishObservableEventWarrantys(),e.next(n.colname);break}}else if("discount_bills"===n.colname){for(o=0;o<t.discount_bills.length;o++)if(t.discount_bills[o]._id===n._id){t.discount_bills.splice(o,1),t.publishObservableEventDiscount_bills(),e.next(n.colname);break}}else if("customer_classs"===n.colname)for(o=0;o<t.customer_classs.length;o++)if(t.customer_classs[o]._id===n._id){t.customer_classs.splice(o,1),t.publishObservableEventCustomerClasss(),e.next(n.colname);break}console.log("deleted",n.colname)}))}))},t.prototype.initChatToAppCare=function(){return this.vhmongo_firebase.socketMongoDB().initChat("vhmessages",{})},t.prototype.listeningChatToAppCare_Insert=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackChatInsert().subscribe((function(t){e.next(t)}))}))},t.prototype.listeningChatToAppCare_Update=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackChatUpdate().subscribe((function(t){e.next(t)}))}))},t.prototype.getOldMessages=function(t){return this.vhmongo_firebase.database().getDocsByFields("vhmessages",{},{},{date:1},t)},t.prototype.sendMessageToAppCare=function(t){var e=this;return new Promise((function(n,o){var i={msg:t,date:new Date,avatar:e.getLocalAppSettingNameStation("store_info").img,email:e.getLocalAppSettingNameStation("store_info").email,company:e.getLocalAppSettingNameStation("store_info").company,align:"left"};e.vhmongo_firebase.database().addDoc("vhmessages",i).then((function(t){n(t)}),(function(t){o(t)})),e.vhmongo_firebase.socketMongoDB().saytoAppCareFirebase()}))},t.prototype.sendImageToAppCare=function(t){var e=this;return new Promise((function(n,o){var i={img:t,date:new Date,avatar:e.getLocalAppSettingNameStation("store_info").img,email:e.getLocalAppSettingNameStation("store_info").email,company:e.getLocalAppSettingNameStation("store_info").company,align:"left"};e.vhmongo_firebase.database().addDoc("vhmessages",i).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.startLocalStorage=function(){var t=this;return new Promise((function(e){var n=new Array;n[0]=t.vhAuth.refreshLocalMyPermission(),n[1]=t.refreshLocalDeliverys(),n[2]=t.refreshLocalAddresss(),t.vhQuery.asyncPromiseAll(n).then((function(){e(null)}))}))},t.prototype.initPurchase=function(){var t=this;this.platform.ready().then((function(){t.iap2.verbosity=t.iap2.DEBUG,t.initPaymentOnAPPStore("in_vhsales_3days",3),t.initPaymentOnAPPStore("in_vhsales_30days",30),t.initPaymentOnAPPStore("in_vhsales_90days",90),t.initPaymentOnAPPStore("in_vhsales_180days",180),t.initPaymentOnAPPStore("in_vhsales_365days",365),t.iap2.refresh()}))},t.prototype.initPaymentOnAPPStore=function(t,e){this.iap2.register({id:t,alias:t,type:this.iap2.CONSUMABLE}),this.registerHandlersForPurchase(t,e)},t.prototype.registerHandlersForPurchase=function(t,e){var n=this;this.iap2.when(t).updated((function(t){})),this.iap2.when(t).registered((function(t){console.log("Registered1: "+JSON.stringify(t))})),this.iap2.when(t).owned((function(t){console.log("owned1: "+JSON.stringify(t))})),this.iap2.when(t).approved((function(o){console.log("approved1: "+JSON.stringify(o)),o.verify(),n.vhmongo_firebase.auth().createSubscribedTime(t,e).then((function(){}))})),this.iap2.when(t).refunded((function(t){console.log("refunded1: "+JSON.stringify(t))})),this.iap2.when(t).expired((function(t){console.log("expired1: "+JSON.stringify(t))})),this.iap2.when(t).verified((function(t){console.log("verified1: "+JSON.stringify(t)),t.finish()}))},t.prototype.paymentOnAPPStore=function(t){try{this.iap2.order(t).then((function(t){console.log("Purchase Succesful1"+JSON.stringify(t))})).catch((function(t){console.log("Error Ordering From Store1"+t)}))}catch(t){console.log("Error Ordering1 "+JSON.stringify(t))}},t.prototype.refreshPurchase=function(){this.iap2.refresh()},t.prototype.publishObservableEventProducts=function(){this.subjectproducts.next()},t.prototype.observableLocalProducts=function(){return this.subjectproducts},t.prototype.getObservableLocalProducts=function(t){var e=this;return new c.Observable((function(n){e.observableLocalProducts().subscribe((function(){n.next(e.getlocalProducts(t))})),e.publishObservableEventProducts()}))},t.prototype.getlocalProductAndCombos=function(t){for(var e=new Array,n=0;n<this.products.length;n++)if(this.products[n]._id===t&&e.push(Object.assign({},this.products[n])),null!=this.products[n].combos)for(var o=0;o<this.products[n].combos.length;o++)if(this.products[n].combos[o].id_product===t){e.push(Object.assign({},this.products[n]));break}return e},t.prototype.getlocalProduct=function(t){for(var e=0;e<this.products.length;e++)if(this.products[e]._id===t)return JSON.parse(JSON.stringify(this.products[e]));return null},t.prototype.getlocalProducts=function(t){var e=new Array;return e=this.products.filter((function(e){if(1===t||2===t||5===t){if(e.type===t)return!0}else if(15===t){if(1===e.type||5===e.type)return!0}else if(25===t){if(2===e.type||5===e.type)return!0}else{if(12!==t)return!0;if(1===e.type||2===e.type)return!0}})),JSON.parse(JSON.stringify(e))},t.prototype.refreshLocalProducts=function(){return new Promise((function(t,e){t(null)}))},t.prototype.addProduct=function(t){var e=this;return new Promise((function(n,o){1===(null==t?void 0:t.type)&&(t.quantity=0,t.quantity_branch={},e.branchs.forEach((function(e){t.quantity_branch[e._id]=0}))),e.vhmongo_firebase.database().addDoc("products",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.addProducts=function(t){var e=this;return new Promise((function(n,o){for(var i,a=new Array,s=function(n){1===(null===(i=t[n])||void 0===i?void 0:i.type)&&(t[n].quantity=0,t[n].quantity_branch={},e.branchs.forEach((function(e){t[n].quantity_branch[e._id]=0}))),a[n]=new Promise((function(o){e.vhmongo_firebase.database().addDoc("products",t[n]).then((function(t){o(t)}),(function(){o(null)}))}))},r=0;r<t.length;r++)s(r);Promise.all(a).then((function(t){var e=t.filter((function(t){return null!=t}));n(e)}))}))},t.prototype.updateProduct=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("products",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteProduct=function(t){var e=this;return new Promise((function(n,o){var i=new Array;e.getlocalProductAndCombos(t).forEach((function(t){i.push(t._id)})),1===i.length?e.vhmongo_firebase.database().getDocsByFields("vhbill_details",{id_product:{$in:i}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("products",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)})):(console.log("Bạn không thể xóa, vì sản phẩm đang liên kết với sản phẩm khác"),n(!1))}))},t.prototype.getProduct=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("products",t).then((function(t){n(t)}))}))},t.prototype.getProducts=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("products").then((function(n){t.products=n,e(n)}),(function(t){n(t)}))}))},t.prototype.addCombosProduct=function(t,e){for(var n,o=this,i=0;i<e.length;i++)null===(n=e[i])||void 0===n||delete n.name;return new Promise((function(n,i){for(var a=new Array,s=0;s<e.length;s++)a[s]=Object.assign(Object.assign({},e[s]),{_id:o.vhAlgorithm.ObjectId()});var r,l=!1,c=0,u=setInterval((function(){var e,s;if(c++,r=o.getlocalProduct(t)){l=!0,void 0===r.combos&&(r.combos=new Array);for(var d=0;d<r.combos.length;d++)null===(e=r.combos[d])||void 0===e||delete e.name,null===(s=r.combos[d])||void 0===s||delete s.img;var _=E(r.combos,a);o.vhmongo_firebase.database().updateDoc("products",t,{combos:_}).then((function(){for(var t=0;t<a.length;t++){var e=o.getlocalProduct(a[t].id_product);if(a[t].name=e.name,a[t].img=e.img,null!=a[t].id_subproduct)for(var i=0;i<e.subs.length;i++)if(a[t].id_subproduct===e.subs[i]._id){a[t].name=a[t].name+"("+e.subs[i].name+")";break}}n(a)}),(function(){i(null)}))}!0!==l&&20!==c||clearInterval(u)}),100)}))},t.prototype.updateComboProduct=function(t,e,n){var o=this;return null==n||delete n.name,null==n||delete n.quantity,new Promise((function(i,a){var s=o.getlocalProduct(t);if(null!=s.combos){s.combos.forEach((function(t){null==t||delete t.name,null==t||delete t.img}));for(var r=0;r<s.combos.length;r++)if(s.combos[r]._id===e){s.combos[r]=Object.assign(Object.assign({},s.combos[r]),n),o.vhmongo_firebase.database().updateDoc("products",s._id,{combos:s.combos}).then((function(t){i(t)}),(function(t){a(t)}));break}}}))},t.prototype.publishObservableEventCustomers=function(){this.subjectcustomers.next(this.customers)},t.prototype.observableLocalCustomers=function(){return this.subjectcustomers},t.prototype.getObservableLocalCustomers=function(){var t=this;return new c.Observable((function(e){t.observableLocalCustomers().subscribe((function(t){e.next(t)})),t.publishObservableEventCustomers()}))},t.prototype.getlocalCustomer=function(t){for(var e=0;e<this.customers.length;e++)if(this.customers[e]._id===t)return this.customers[e];return null},t.prototype.getlocalCustomers=function(){return this.customers},t.prototype.refreshLocalCustomers=function(){return new Promise((function(t){t(null)}))},t.prototype.addCustomer=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("customers",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.addCustomers=function(t){var e=this;return new Promise((function(n,o){for(var i=new Array,a=function(n){i[n]=new Promise((function(o){e.vhmongo_firebase.database().addDoc("customers",t[n]).then((function(t){o(t)}),(function(){o(null)}))}))},s=0;s<t.length;s++)a(s);Promise.all(i).then((function(t){var e=t.filter((function(t){return null!=t}));n(e)}))}))},t.prototype.updateCustomer=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("customers",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteCustomer=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("bills",{id_customer:{$eq:t}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("customers",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getCustomer=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("customers",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getCustomers=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("customers").then((function(n){t.customers=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventSuppliers=function(){this.subjectsuppliers.next(this.suppliers)},t.prototype.observableLocalSuppliers=function(){return this.subjectsuppliers},t.prototype.getObservableLocalSuppliers=function(){var t=this;return new c.Observable((function(e){t.observableLocalSuppliers().subscribe((function(t){e.next(E(t))})),t.publishObservableEventSuppliers()}))},t.prototype.getlocalSupplier=function(t){for(var e=0;e<this.suppliers.length;e++)if(this.suppliers[e]._id===t)return this.suppliers[e];return null},t.prototype.getlocalSuppliers=function(){return E(this.suppliers)},t.prototype.refreshLocalSuppliers=function(){return new Promise((function(t){t(null)}))},t.prototype.addSupplier=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("suppliers",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.addSuppliers=function(t){var e=this;return new Promise((function(n,o){for(var i=new Array,a=function(n){i[n]=new Promise((function(o){e.vhmongo_firebase.database().addDoc("suppliers",t[n]).then((function(t){o(t)}),(function(){o(null)}))}))},s=0;s<t.length;s++)a(s);Promise.all(i).then((function(t){var e=t.filter((function(t){return null!=t}));n(e)}))}))},t.prototype.updateSupplier=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("suppliers",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteSupplier=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("bills",{id_supplier:{$eq:t}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("suppliers",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getSupplier=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("suppliers",t).then((function(t){n(t)}))}))},t.prototype.getSuppliers=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("suppliers").then((function(n){t.suppliers=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventWallets=function(){this.subjectwallets.next(this.wallets)},t.prototype.observableLocalWallets=function(){return this.subjectwallets},t.prototype.getObservableLocalWallets=function(){var t=this;return new c.Observable((function(e){t.observableLocalWallets().subscribe((function(t){e.next(t)})),t.publishObservableEventWallets()}))},t.prototype.getlocalWallet=function(t){for(var e=0;e<this.wallets.length;e++)if(this.wallets[e]._id===t)return this.wallets[e];return null},t.prototype.getlocalWallets=function(){return E(this.wallets)},t.prototype.refreshLocalWallets=function(){return new Promise((function(t){t(null)}))},t.prototype.addWallet=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("wallets",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateWallet=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("wallets",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteWallet=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("bills",{id_wallet:{$eq:t}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("wallets",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getWallet=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("wallets",t).then((function(t){n(t)}))}))},t.prototype.getWallets=function(){var t=this;return new Promise((function(e,n){t.wallets=new Array,t.vhmongo_firebase.database().getDocs("wallets").then((function(n){t.wallets=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventTaxs=function(){this.subjecttaxs.next(this.taxs)},t.prototype.observableLocalTaxs=function(){return this.subjecttaxs},t.prototype.getObservableLocalTaxs=function(){var t=this;return new c.Observable((function(e){t.observableLocalTaxs().subscribe((function(t){e.next(t)})),t.publishObservableEventTaxs()}))},t.prototype.getlocalTax=function(t){for(var e=0;e<this.taxs.length;e++)if(this.taxs[e]._id===t)return this.taxs[e];return null},t.prototype.getlocalTaxs=function(){return this.taxs},t.prototype.refreshLocalTaxs=function(){return new Promise((function(t){t(null)}))},t.prototype.addTax=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("taxs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateTax=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("taxs",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteTax=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("taxs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getTax=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("taxs",t).then((function(t){n(t)}))}))},t.prototype.getTaxs=function(){var t=this;return new Promise((function(e,n){t.taxs=new Array,t.vhmongo_firebase.database().getDocs("taxs").then((function(n){t.taxs=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventCategorys=function(){this.subjectcategorys.next()},t.prototype.observableLocalCategorys=function(){return this.subjectcategorys},t.prototype.getObservableLocalCategorys=function(t){var e=this;return new c.Observable((function(n){e.observableLocalCategorys().subscribe((function(){n.next(e.getlocalCategorys(t))})),e.publishObservableEventCategorys()}))},t.prototype.getlocalCategory=function(t){for(var e=0;e<this.categorys.length;e++)if(this.categorys[e]._id===t)return Object.assign({},this.categorys[e]);return null},t.prototype.getlocalCategorys=function(t){var e=new Array;return 1===t||2===t||5===t?this.categorys.forEach((function(n){n.type===t&&e.push(Object.assign({},n))})):12===t?this.categorys.forEach((function(t){1!==t.type&&2!==t.type||e.push(Object.assign({},t))})):this.categorys.forEach((function(t){e.push(Object.assign({},t))})),e},t.prototype.refreshLocalCategorys=function(){return new Promise((function(t){t(null)}))},t.prototype.addCategory=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("categorys",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.addCategorys=function(t){var e=this;return new Promise((function(n,o){for(var i=new Array,a=function(n){i[n]=new Promise((function(o){e.vhmongo_firebase.database().addDoc("categorys",t[n]).then((function(t){o(t)}),(function(){o(null)}))}))},s=0;s<t.length;s++)a(s);Promise.all(i).then((function(t){var e=t.filter((function(t){return null!=t}));n(e)}))}))},t.prototype.updateCategory=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("categorys",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteCategory=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("products",{id_category:{$eq:t}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("categorys",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getCategory=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("categorys",t).then((function(t){n(t)}))}))},t.prototype.getCategorys=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("categorys").then((function(n){t.categorys=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventInventorytimes=function(){this.subjectinventorytimes.next(this.inventorytimes)},t.prototype.observableLocalInventorytimes=function(){return this.subjectinventorytimes},t.prototype.getObservableLocalInventorytimes=function(){var t=this;return new c.Observable((function(e){t.observableLocalInventorytimes().subscribe((function(t){e.next(t)})),t.publishObservableEventInventorytimes()}))},t.prototype.getlocalInventorytime=function(t){for(var e=0;e<this.inventorytimes.length;e++)if(this.inventorytimes[e]._id===t)return this.inventorytimes[e];return null},t.prototype.getlocalInventorytimes=function(){return this.inventorytimes},t.prototype.refreshLocalInventorytimes=function(){return new Promise((function(t){t(null)}))},t.prototype.addInventorytime=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("inventorytimes",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateInventorytime=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("inventorytimes",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteInventorytime=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("inventorytimes",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getInventorytime=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("inventorytimes",t).then((function(t){n(t)}))}))},t.prototype.getInventorytimes=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("inventorytimes").then((function(n){t.inventorytimes=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventWarrantys=function(){this.subjectwarrantys.next(this.warrantys)},t.prototype.observableLocalWarrantys=function(){return this.subjectwarrantys},t.prototype.getObservableLocalWarrantys=function(){var t=this;return new c.Observable((function(e){t.observableLocalWarrantys().subscribe((function(t){e.next(t)})),t.publishObservableEventWarrantys()}))},t.prototype.getlocalWarranty=function(t){for(var e=0;e<this.warrantys.length;e++)if(this.warrantys[e]._id===t)return this.warrantys[e];return null},t.prototype.getlocalWarrantys=function(){return this.warrantys},t.prototype.refreshLocalWarrantys=function(){return new Promise((function(t){t(null)}))},t.prototype.addWarranty=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("warrantys",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateWarranty=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("warrantys",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteWarranty=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("warrantys",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getWarranty=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("warrantys",t).then((function(t){n(t)}))}))},t.prototype.getWarrantys=function(){var t=this;return new Promise((function(e,n){t.warrantys=new Array,t.vhmongo_firebase.database().getDocs("warrantys").then((function(n){t.warrantys=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventCustomerClasss=function(){this.subjectcustomer_classs.next(this.customer_classs)},t.prototype.observableLocalCustomerClasss=function(){return this.subjectcustomer_classs},t.prototype.getObservableLocalCustomerClasss=function(){var t=this;return new c.Observable((function(e){t.observableLocalCustomerClasss().subscribe((function(t){e.next(t)})),t.publishObservableEventCustomerClasss()}))},t.prototype.getlocalCustomerClass=function(t){for(var e=0;e<this.customer_classs.length;e++)if(this.customer_classs[e]._id===t)return JSON.parse(JSON.stringify(this.customer_classs[e]));return null},t.prototype.getlocalCustomerClasss=function(){return JSON.parse(JSON.stringify(this.customer_classs))},t.prototype.addCustomerClass=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("customer_classs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateCustomerClass=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("customer_classs",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteCustomerClass=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("customer_classs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.publishObservableEventDiscount_bills=function(){this.subjectdiscount_bills.next(this.discount_bills)},t.prototype.observableLocalDiscount_bills=function(){return this.subjectdiscount_bills},t.prototype.getObservableLocalDiscount_bills=function(){var t=this;return new c.Observable((function(e){t.observableLocalDiscount_bills().subscribe((function(t){e.next(t)})),t.publishObservableEventDiscount_bills()}))},t.prototype.getlocalDiscount_bill=function(t){for(var e=0;e<this.discount_bills.length;e++)if(this.discount_bills[e]._id===t)return JSON.parse(JSON.stringify(this.discount_bills[e]));return null},t.prototype.getlocalDiscount_bills=function(){return JSON.parse(JSON.stringify(this.discount_bills))},t.prototype.addDiscount_bill=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("discount_bills",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateDiscount_bill=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("discount_bills",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteDiscount_bill=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("discount_bills",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.addDiscount_sales=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("discount_saless",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateDiscount_sales=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("discount_saless",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteDiscount_sales=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("discount_saless",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getDiscount_sales=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("discount_saless",t).then((function(t){n(t)}))}))},t.prototype.getDiscount_saless=function(){var t=this;return new Promise((function(e,n){t.discount_saless=new Array,t.vhmongo_firebase.database().getDocs("discount_saless").then((function(n){t.discount_saless=n,e(n)}),(function(t){n(t)}))}))},t.prototype.addCommission=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("commissions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateCommission=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("commissions",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteCommission=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("commissions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getCommission=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("commissions",t).then((function(t){n(t)}))}))},t.prototype.getCommissions=function(){var t=this;return new Promise((function(e,n){t.commissions=new Array,t.vhmongo_firebase.database().getDocs("commissions").then((function(n){t.commissions=n,e(n)}),(function(t){n(t)}))}))},t.prototype.getlocalDelivery=function(t){for(var e=0;e<this.deliverys.length;e++)if(this.deliverys[e]._id===t)return this.deliverys[e];return null},t.prototype.getlocalDeliverys=function(){return this.deliverys},t.prototype.refreshLocalDeliverys=function(){var t=this;return new Promise((function(e){t.getDeliverys().then((function(){e(null)}))}))},t.prototype.addDelivery=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("deliverys",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateDelivery=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("deliverys",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteDelivery=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("deliverys",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getDelivery=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("deliverys",t).then((function(t){n(t)}))}))},t.prototype.getDeliverys=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("deliverys").then((function(n){t.deliverys=n,e(n)}),(function(t){n(t)}))}))},t.prototype.addAdss=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("adss",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateAds=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("adss",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteAds=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("adss",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getAds=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("adss",t).then((function(t){n(t)}))}))},t.prototype.getAdss=function(){var t=this;return new Promise((function(e){t.vhmongo_firebase.database().getDocs("adss").then((function(t){e(t)}))}))},t.prototype.getAdss_byFields=function(t,e,n,o){var i=this;return new Promise((function(a,s){void 0===e&&(e={}),void 0===n&&(n={}),void 0===o&&(o=0),i.vhmongo_firebase.database().getDocsByFields("adss",t,e,n,o).then((function(t){a(t)}),(function(t){s(t)}))}))},t.prototype.getlocalAddress=function(t){for(var e=0;e<this.addresss.length;e++)if(this.addresss[e]._id===t)return this.addresss[e];return null},t.prototype.getlocalAddresss=function(){return this.addresss},t.prototype.refreshLocalAddresss=function(){var t=this;return new Promise((function(e){t.getAddresss().then((function(){e(null)}))}))},t.prototype.addAddress=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("addresss",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateAddress=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("addresss",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteAddress=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("addresss",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getAddress=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("addresss",t).then((function(t){n(t)}))}))},t.prototype.getShippingAhamoveURL=function(){return this.vhmongo_firebase.auth().getShippingCloudURL()+"ahamove"},t.prototype.getShippingGHTKURL=function(){return this.vhmongo_firebase.auth().getShippingCloudURL()+"ghtk"},t.prototype.getAddresss=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("addresss").then((function(n){t.addresss=n,e(n)}),(function(t){n(t)}))}))},t.prototype.getlocalIncoming_group=function(t){for(var e=0;e<this.incoming_groups.length;e++)if(this.incoming_groups[e]._id===t)return Object.assign({},this.incoming_groups[e]);return null},t.prototype.getlocalIncoming_groups=function(){return E(this.incoming_groups)},t.prototype.refreshLocalIncoming_groups=function(){var t=this;return new Promise((function(e){t.getIncoming_groups().then((function(){e(null)}))}))},t.prototype.addIncoming_group=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("incoming_groups",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateIncoming_group=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("incoming_groups",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteIncoming_group=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("bills",{id_incoming_group:{$eq:t}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("incoming_groups",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getIncoming_groups=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("incoming_groups").then((function(n){t.incoming_groups=n,t.incoming_groups=t.vhAlgorithm.sortVietnamesebyASC(t.incoming_groups,"name"),e(t.incoming_groups)}),(function(t){n(t)}))}))},t.prototype.getlocalSpending_group=function(t){for(var e=0;e<this.spending_groups.length;e++)if(this.spending_groups[e]._id===t)return Object.assign({},this.spending_groups[e]);return null},t.prototype.getlocalSpending_groups=function(){return E(this.spending_groups)},t.prototype.refreshLocalSpending_groups=function(){var t=this;return new Promise((function(e){t.getSpending_groups().then((function(){e(null)}))}))},t.prototype.addSpending_group=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("spending_groups",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateSpending_group=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("spending_groups",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteSpending_group=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("bills",{id_spending_group:{$eq:t}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("spending_groups",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getSpending_groups=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("spending_groups").then((function(n){t.spending_groups=n,t.spending_groups=t.vhAlgorithm.sortVietnamesebyASC(t.spending_groups,"name"),e(t.spending_groups)}),(function(t){n(t)}))}))},t.prototype.updateDebtAtBeginningCustomer=function(t,e,n){var o=this;return new Promise((function(i,a){var s=o.getlocalCustomer(t),r={};null!=s[e]?r[e]=s[e]:r[e]={},r[e].debt_beginning=n,o.vhmongo_firebase.database().updateDoc("customers",t,Object.assign({},r)).then((function(t){i(t)}),(function(t){a(t)}))}))},t.prototype.getDebtAtBeginningCustomers_byIDcustomer=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("debt_at_beginning_customers",{id_customer:{$eq:t}},{}).then((function(t){n(t)})).catch((function(t){o(t)}))}))},t.prototype.getDebtAtBeginningCustomers_byIDbranch=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("debt_at_beginning_customers",{id_branch:{$eq:t}},{}).then((function(t){n(t)})).catch((function(t){o(t)}))}))},t.prototype.getDebtAtBeginningCustomers_byIDcustomer_byIDbranch=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().getDocsByFields("debt_at_beginning_customers",{id_customer:{$eq:t},id_branch:{$eq:e}},{}).then((function(t){o(t)})).catch((function(t){i(t)}))}))},t.prototype.getDebtAtBeginningCustomers=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("debt_at_beginning_customers").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.updateDebtAtBeginningSupplier=function(t,e,n){var o=this;return new Promise((function(i,a){var s=o.getlocalSupplier(t),r={};null!=s[e]?r[e]=s[e]:r[e]={},r[e].debt_beginning=n,o.vhmongo_firebase.database().updateDoc("suppliers",t,Object.assign({},r)).then((function(t){i(t)}),(function(t){a(t)}))}))},t.prototype.getDebtAtBeginningSuppliers_byIDsupplier=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("debt_at_beginning_suppliers",{id_supplier:{$eq:t}},{}).then((function(t){n(t)})).catch((function(t){o(t)}))}))},t.prototype.getDebtAtBeginningSuppliers_byIDbranch=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("debt_at_beginning_suppliers",{id_branch:{$eq:t}},{}).then((function(t){n(t)})).catch((function(t){o(t)}))}))},t.prototype.getDebtAtBeginningSuppliers_byIDsupplier_byIDbranch=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().getDocsByFields("debt_at_beginning_suppliers",{id_supplier:{$eq:t},id_branch:{$eq:e}},{}).then((function(t){o(t)})).catch((function(t){i(t)}))}))},t.prototype.getDebtAtBeginningSuppliers=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("debt_at_beginning_suppliers").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.setDefaultBranch=function(t){for(var e=0;e<this.branchs.length;e++)if(this.branchs[e]._id===t){localStorage.setItem(this.vhmongo_firebase.auth().getProjectName()+"_default_branch",JSON.stringify(this.branchs[e]));break}},t.prototype.getDefaultBranch=function(){return 0==this.branchs.length?null:localStorage.getItem(this.vhmongo_firebase.auth().getProjectName()+"_default_branch")?JSON.parse(localStorage.getItem(this.vhmongo_firebase.auth().getProjectName()+"_default_branch")):null},t.prototype.clearDefaultBranch=function(){localStorage.setItem(this.vhmongo_firebase.auth().getProjectName()+"_default_branch",null)},t.prototype.isChains=function(){return 0==this.branchs.length?null:1!=this.branchs.length},t.prototype.publishObservableEventBranchs=function(){this.subjectbranchs.next(this.branchs)},t.prototype.observableLocalBranchs=function(){return this.subjectbranchs},t.prototype.getObservableLocalBranchs=function(){var t=this;return new c.Observable((function(e){t.observableLocalBranchs().subscribe((function(t){e.next(t)})),t.publishObservableEventBranchs()}))},t.prototype.getlocalBranch=function(t){for(var e=0;e<this.branchs.length;e++)if(this.branchs[e]._id===t)return this.branchs[e];return null},t.prototype.getlocalBranchs=function(){var t=new Array;return this.branchs.forEach((function(e){t.push(Object.assign({},e))})),t},t.prototype.refreshLocalBranchs=function(){var t=this;return new Promise((function(e){t.getBranchs().then((function(){e(null)}))}))},t.prototype.addBranch=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("branchs",t).then((function(t){var o=new Array,i=e.getlocalProducts(1),a=Object.assign(Object.assign({},t),{opentime:"8h:00 AM",closetime:"10h:00 PM",img:"",tax_number:""});a.appsetting_name="store_info",a.id_branch=t._id,delete a._id,o.push(e.vhmongo_firebase.database().addDoc("appsettingbranchs",a));for(var s=0;s<i.length;s++)i[s].quantity_branch[t._id]=0,o.push(e.updateProduct(i[s]._id,{quantity_branch:i[s].quantity_branch}));Promise.all(o).then((function(){e.vhAuth.getStore();var o={};o[t._id]={ecommerce_expire:{ecommerce_package:"advanced",ecommerce_package_expire:!1},ecommerce_restriction:{shop_number:4,show_report_duration:92},main_expire:{main_package:"advanced",main_package_expire:!0},main_restriction:{show_report_duration:92,user_number:3}},e.vhmongo_firebase.database().updateDoc_onRootCollectionsFirebase("stores",e.vhmongo_firebase.auth().getDatabase(),Object.assign({},o)).then((function(e){e&&n(t)}))}))}),(function(t){o(t)}))}))},t.prototype.updateBranch=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("branchs",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteBranch=function(t){var e=this;return new Promise((function(n,o){var i=new Array;i[0]=e.vhmongo_firebase.database().getDocsByFields("wallets",{id_branch:{$eq:t}},{},{},1),i[1]=e.vhmongo_firebase.database().getDocsByFields("bills",{id_branch:{$eq:t}},{},{},1),i[2]=e.vhmongo_firebase.database().getDocsByFields("bills",{id_branch_receive:{$eq:t}},{},{},1),Promise.all(i).then((function(i){0===i[0].length&&0===i[1].length&&0===i[2].length?e.vhmongo_firebase.database().deleteDoc("branchs",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getBranch=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("branchs",t).then((function(t){n(t)}))}))},t.prototype.getBranchs=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("branchs").then((function(n){t.branchs=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventPrinters=function(){this.subjectprinters.next(this.printers)},t.prototype.observableLocalPrinters=function(){return this.subjectprinters},t.prototype.getObservableLocalPrinters=function(){var t=this;return new c.Observable((function(e){t.observableLocalPrinters().subscribe((function(t){e.next(t)})),t.publishObservableEventPrinters()}))},t.prototype.getlocalPrinter=function(t){for(var e=0;e<this.printers.length;e++)if(this.printers[e]._id===t)return this.printers[e];return null},t.prototype.getlocalPrinters=function(){return this.printers},t.prototype.refreshLocalPrinters=function(){return new Promise((function(t,e){t(null)}))},t.prototype.addPrinter=function(t){var e=this;return new Promise((function(n,o){var i=Object.assign({},t);i.uuid=e.hwinfo.uuid,e.vhmongo_firebase.database().addDoc("printers",i).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updatePrinter=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("printers",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deletePrinter=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("printers",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPrinter=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("printers",t).then((function(t){t&&(null==t||delete t.uuid),n(t)}),(function(t){o(t)}))}))},t.prototype.getPrinters=function(){var t=this;return new Promise((function(e){t.vhmongo_firebase.database().getDocsByFields("printers",{uuid:{$eq:t.hwinfo.uuid}},{},{},0).then((function(n){t.printers=new Array,n.length>0&&n.forEach((function(e){null==e||delete e.uuid,t.printers.push(e)})),e(t.printers)}))}))},t.prototype.createBill_Billdetail_51=function(t,e){var n=this;return new Promise((function(o,i){n.sync_code=Math.random().toString(36).substr(2,10).toUpperCase(),t.sync_code=n.sync_code,t.date=new Date,t.bill_type=51,t.bill_code=n.vhAlgorithm.createBillCode(null==t?void 0:t.date),n.vhmongo_firebase.database().addDoc("bills",t).then((function(i){if(i){for(var a=new Array,s=0;s<e.length;s++){var r=e[s];r.id_bill=i._id,t.bill_code&&(r.bill_code=t.bill_code),t.date&&(r.date=t.date),"number"==typeof t.tax&&(r.tax=t.tax),r.bill_type=51,t.id_cashier&&(r.id_cashier=t.id_cashier),t.id_employee&&(r.id_employee=t.id_employee),t.id_customer&&(r.id_customer=t.id_customer),t.id_branch&&(r.id_branch=t.id_branch),a[s]=n.vhmongo_firebase.database().addDoc("vhbill_details",r)}n.vhQuery.asyncPromiseAll(a).then((function(){if(51===t.bill_type){for(var a=JSON.parse(JSON.stringify(e)),s=function(t){if(!a[t].dev_checked){for(var e=t+1;e<a.length;e++)a[t].id_product===a[e].id_product&&(a[t].quantity=a[t].quantity+a[e].quantity,a[e].dev_checked=!0);n.getPaymentCardCode(a[t].id_payment_card_code).then((function(e){for(var o=0;o<e.products.length;o++)e.products[o].id_product===a[t].id_product&&(e.products[o].outquantity=e.products[o].outquantity+a[t].quantity,n.updatePaymentCardCode(e._id,e.products[o]))}),(function(t){console.log("error",t)}))}},r=0;r<a.length;r++)s(r);var l=new Array;for(r=0;r<e.length;r++)l[r]=n.updatePaymentCardCode(e[r].id_payment_card_code,{date_used:t.date,status:4});n.vhQuery.asyncPromiseAll(l).then((function(){o(i)}))}}))}}))}))},t.prototype.createBill_Billdetail_41=function(t,e){var n=this;return new Promise((function(o,i){n.sync_code=Math.random().toString(36).substr(2,10).toUpperCase(),t.sync_code=n.sync_code,t.date=new Date,t.bill_type=41,t.bill_code=n.vhAlgorithm.createBillCode(null==t?void 0:t.date),n.vhmongo_firebase.database().addDoc("bills",t).then((function(i){if(i){for(var a=new Array,s=0;s<e.length;s++){var r=e[s];r.id_bill=i._id,t.bill_code&&(r.bill_code=t.bill_code),t.date&&(r.date=t.date),"number"==typeof t.tax&&(r.tax=t.tax),r.bill_type=41,t.id_cashier&&(r.id_cashier=t.id_cashier),t.id_employee&&(r.id_employee=t.id_employee),t.id_customer&&(r.id_customer=t.id_customer),t.id_branch&&(r.id_branch=t.id_branch),a[s]=n.vhmongo_firebase.database().addDoc("vhbill_details",r)}n.vhQuery.asyncPromiseAll(a).then((function(){if(41===t.bill_type){for(var a=new Array,s=0;s<e.length;s++)a[s]=n.updateVoucherCode(e[s].id_voucher_code,{date_used:t.date,status:4});n.vhQuery.asyncPromiseAll(a).then((function(){o(i)}))}}))}else o(null)}),(function(t){i(t)}))}))},t.prototype.createBill_Billdetail=function(t,e){var n=this;return new Promise((function(o,i){n.sync_code=Math.random().toString(36).substr(2,10).toUpperCase(),t.sync_code=n.sync_code,t.bill_code=n.vhAlgorithm.createBillCode(null==t?void 0:t.date),n.vhmongo_firebase.database().addDoc("bills",t).then((function(a){if(a){for(var s=new Array,r=0;r<e.length;r++){var l=e[r];l.id_bill=a._id,t.bill_code&&(l.bill_code=t.bill_code),t.date&&(l.date=t.date),"number"==typeof t.tax&&(l.tax=t.tax),"number"==typeof t.bill_type&&(l.bill_type=t.bill_type),t.id_cashier&&(l.id_cashier=t.id_cashier),t.id_employee&&(l.id_employee=t.id_employee),t.id_supplier&&(l.id_supplier=t.id_supplier),t.id_customer&&(l.id_customer=t.id_customer),t.id_inventorytime&&(l.id_inventorytime=t.id_inventorytime),t.id_branch&&(l.id_branch=t.id_branch),s[r]=n.vhmongo_firebase.database().addDoc("vhbill_details",l)}n.vhQuery.asyncPromiseAll(s).then((function(i){if(1===t.bill_type||10===t.bill_type||15===t.bill_type||30===t.bill_type){for(var s=new Array,r=0;r<e.length;r++)if(1===e[r].ptype){if(!e[r].calculated){var l=e[r].quantity;e[r].calculated=!0;for(var c=0;c<e.length;c++)if(e[c].id_product===e[r].id_product&&(e[c].calculated||(l+=e[c].quantity,e[c].calculated=!0)),5===e[c].ptype)for(var u=0;u<e[c].combos.length;u++)e[c].combos[u].id_product===e[r].id_product&&(e[c].combos[u].calculated||(l+=e[c].quantity*e[c].combos[u].quantity,e[c].combos[u].calculated=!0));var d={};null!=(b=n.getlocalProduct(e[r].id_product)).quantity_branch?(d=b.quantity_branch,null!=b.quantity_branch[t.id_branch]?d[t.id_branch]=d[t.id_branch]-l:d[t.id_branch]=-l):d[t.id_branch]=-l;var _=b.quantity-l;s[s.length]=n.vhmongo_firebase.database().updateDoc("products",b._id,{quantity:_,quantity_branch:d})}}else if(5===e[r].ptype){for(var p=0;p<e[r].combos.length;p++)if(!e[r].combos[p].calculated){l=e[r].quantity*e[r].combos[p].quantity;e[r].combos[p].calculated=!0;for(c=0;c<e.length;c++)if(e[c].id_product===e[r].combos[p].id_product&&(e[c].calculated||(l+=e[c].quantity,e[c].calculated=!0)),5===e[c].ptype)for(u=0;u<e[c].combos.length;u++)e[c].combos[u].id_product===e[r].combos[p].id_product&&(e[c].combos[u].calculated||(l+=e[c].quantity*e[c].combos[u].quantity,e[c].combos[u].calculated=!0));d={};null!=(b=n.getlocalProduct(e[r].combos[p].id_product)).quantity_branch?(d=b.quantity_branch,null!=b.quantity_branch[t.id_branch]?d[t.id_branch]=d[t.id_branch]-l:d[t.id_branch]=-l):d[t.id_branch]=-l;_=b.quantity-l;s[s.length]=n.vhmongo_firebase.database().updateDoc("products",b._id,{quantity:_,quantity_branch:d})}}else s[s.length]=new Promise((function(t){t(null)}));n.vhQuery.asyncPromiseAll(s).then((function(){o(a)}))}else if(2===t.bill_type||3===t.bill_type||31===t.bill_type){for(s=new Array,r=0;r<e.length;r++)if(1===e[r].ptype){if(!e[r].calculated){l=e[r].quantity;e[r].calculated=!0;for(c=0;c<e.length;c++)if(e[c].id_product===e[r].id_product&&(e[c].calculated||(l+=e[c].quantity,e[c].calculated=!0)),5===e[c].ptype)for(u=0;u<e[c].combos.length;u++)e[c].combos[u].id_product===e[r].id_product&&(e[c].combos[u].calculated||(l+=e[c].quantity*e[c].combos[u].quantity,e[c].combos[u].calculated=!0));d={};null!=(b=n.getlocalProduct(e[r].id_product)).quantity_branch?(d=b.quantity_branch,null!=b.quantity_branch[t.id_branch]?d[t.id_branch]=d[t.id_branch]+l:d[t.id_branch]=l):d[t.id_branch]=l;_=b.quantity+l;s[s.length]=n.vhmongo_firebase.database().updateDoc("products",b._id,{quantity:_,quantity_branch:d})}}else if(5===e[r].ptype){for(p=0;p<e[r].combos.length;p++)if(!e[r].combos[p].calculated){l=e[r].quantity*e[r].combos[p].quantity;e[r].combos[p].calculated=!0;for(c=0;c<e.length;c++)if(e[c].id_product===e[r].combos[p].id_product&&(e[c].calculated||(l+=e[c].quantity,e[c].calculated=!0)),5===e[c].ptype)for(u=0;u<e[c].combos.length;u++)e[c].combos[u].id_product===e[r].combos[p].id_product&&(e[c].combos[u].calculated||(l+=e[c].quantity*e[c].combos[u].quantity,e[c].combos[u].calculated=!0));var b;d={};null!=(b=n.getlocalProduct(e[r].combos[p].id_product)).quantity_branch?(d=b.quantity_branch,null!=b.quantity_branch[t.id_branch]?d[t.id_branch]=d[t.id_branch]+l:d[t.id_branch]=l):d[t.id_branch]=l;_=b.quantity+l;s[s.length]=n.vhmongo_firebase.database().updateDoc("products",b._id,{quantity:_,quantity_branch:d})}}else s[s.length]=new Promise((function(t){t(null)}));n.vhQuery.asyncPromiseAll(s).then((function(){o(a)}))}else if(9===t.bill_type){s=new Array;var f=function(o){s[o]=new Promise((function(i){var a;if(1===e[o].ptype){var s=n.getlocalProduct(e[o].id_product),r={};null!=s.quantity_branch?(r=s.quantity_branch,null!=s.quantity_branch[t.id_branch]?r[t.id_branch]=r[t.id_branch]+e[o].quantity:r[t.id_branch]=e[o].quantity):r[t.id_branch]=e[o].quantity;var l=s.quantity+e[o].quantity,c={};null!=s[t.id_branch]&&null!=s[t.id_branch].inventory&&(c[t.id_branch]=s[t.id_branch],null===(a=c[t.id_branch])||void 0===a||delete a.inventory),n.vhmongo_firebase.database().updateDoc("products",s._id,Object.assign({quantity:l,quantity_branch:r},c)).then((function(){i(null)}))}else i(null)}))};for(r=0;r<e.length;r++)f(r);n.vhQuery.asyncPromiseAll(s).then((function(){o(a)}))}else 5!==t.bill_type&&6!==t.bill_type&&13!==t.bill_type&&14!==t.bill_type&&16!==t.bill_type&&18!==t.bill_type&&19!==t.bill_type&&20!==t.bill_type&&21!==t.bill_type&&29!==t.bill_type||o(a)}))}else i({message:"Invoice creation failed"})}),(function(t){i(t)}))}))},t.prototype.createBill_Detail=function(t){var e=this;return new Promise((function(n,o){t.id_bill?e.vhmongo_firebase.database().getDoc("bills",t.id_bill).then((function(i){var a=t;i.bill_code&&(a.bill_code=i.bill_code),i.id_branch&&(a.id_branch=i.id_branch),"number"==typeof i.bill_type&&(a.bill_type=i.bill_type),e.vhmongo_firebase.database().addDoc("vhbill_details",a).then((function(t){n(t)}),(function(t){o(t)}))}),(function(t){console.log("error",t)})):console.log("error","không tồn tại id_bill trong data")}))},t.prototype.updateBill_Detail=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("vhbill_details",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteBill_Detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("vhbill_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.saveBill_Billdetail=function(t){var e=this;return new Promise((function(n,o){e.sync_code=Math.random().toString(36).substr(2,10).toUpperCase();var i=e.vhmongo_firebase.database().getDoc("bills",t),a=e.vhmongo_firebase.database().getDocsByFields("vhbill_details",{id_bill:{$eq:t}},{},{},0);Promise.all([i,a]).then((function(o){if(5===o[0].bill_type){for(var i=new Array,a=0;a<o[1].length;a++){var s=Object.assign({},o[1][a]);s.id_bill=o[0]._id,s.bill_type=1,o[0].date&&(s.date=o[0].date),"number"==typeof o[0].tax&&(s.tax=o[0].tax),"number"==typeof o[0].bill_type&&(s.bill_type=1),o[0].id_cashier&&(s.id_cashier=o[0].id_cashier),o[0].id_employee&&(s.id_employee=o[0].id_employee),o[0].id_supplier&&(s.id_supplier=o[0].id_supplier),o[0].id_customer&&(s.id_customer=o[0].id_customer),i[a]=e.vhmongo_firebase.database().updateDoc("vhbill_details",o[1][a]._id,s)}i[o[1].length]=e.vhmongo_firebase.database().updateDoc("bills",t,{bill_type:1,uuid:null,sync_code:e.sync_code}),Promise.all(i).then((function(){for(var t=new Array,i=0;i<o[1].length;i++)if(1===o[1][i].ptype){if(!o[1][i].calculated){var a=o[1][i].quantity;o[1][i].calculated=!0;for(var s=0;s<o[1].length;s++)if(o[1][s].id_product===o[1][i].id_product&&(o[1][s].calculated||(a+=o[1][s].quantity,o[1][s].calculated=!0)),5===o[1][s].ptype)for(var r=0;r<o[1][s].combos.length;r++)o[1][s].combos[r].id_product===o[1][i].id_product&&(o[1][s].combos[r].calculated||(a+=o[1][s].quantity*o[1][s].combos[r].quantity,o[1][s].combos[r].calculated=!0));var l={};null!=(d=e.getlocalProduct(o[1][i].id_product)).quantity_branch?(l=d.quantity_branch,null!=d.quantity_branch[o[0].id_branch]?l[o[0].id_branch]=l[o[0].id_branch]-a:l[o[0].id_branch]=-a):l[o[0].id_branch]=-a;var c=d.quantity-a;t[t.length]=e.vhmongo_firebase.database().updateDoc("products",d._id,{quantity:c,quantity_branch:l})}}else if(5===o[1][i].ptype){for(var u=0;u<o[1][i].combos.length;u++)if(!o[1][i].combos[u].calculated){a=o[1][i].quantity*o[1][i].combos[u].quantity;o[1][i].combos[u].calculated=!0;for(s=0;s<o[1].length;s++)if(o[1][s].id_product===o[1][i].combos[u].id_product&&(o[1][s].calculated||(a+=o[1][s].quantity,o[1][s].calculated=!0)),5===o[1][s].ptype)for(r=0;r<o[1][s].combos.length;r++)o[1][s].combos[r].id_product===o[1][i].combos[u].id_product&&(o[1][s].combos[r].calculated||(a+=o[1][s].quantity*o[1][s].combos[r].quantity,o[1][s].combos[r].calculated=!0));var d;l={};null!=(d=e.getlocalProduct(o[1][i].combos[u].id_product)).quantity_branch?(l=d.quantity_branch,null!=d.quantity_branch[o[0].id_branch]?l[o[0].id_branch]=l[o[0].id_branch]-a:l[o[0].id_branch]=-a):l[o[0].id_branch]=-a;c=d.quantity-a;t[t.length]=e.vhmongo_firebase.database().updateDoc("products",d._id,{quantity:c,quantity_branch:l})}}else t[t.length]=new Promise((function(t){t(null)}));e.vhQuery.asyncPromiseAll(t).then((function(){n(o)}))}))}}))}))},t.prototype.updateBill_Billdetail=function(t,e,n){var o=this;return new Promise((function(i,a){o.sync_code=Math.random().toString(36).substr(2,10).toUpperCase(),e.sync_code=o.sync_code,new Promise((function(n){var i=o.vhmongo_firebase.database().getDoc("bills",t),s=o.vhmongo_firebase.database().getDocsByFields("vhbill_details",{id_bill:{$eq:t}},{},{},0);o.vhQuery.asyncPromiseAll([i,s]).then((function(t){if(1===t[0].bill_type||10===t[0].bill_type||15===t[0].bill_type){for(var i=new Array,s=0;s<t[1].length;s++)i[s]=o.vhmongo_firebase.database().deleteDoc("vhbill_details",t[1][s]._id);o.vhQuery.asyncPromiseAll(i).then((function(){for(var e=new Array,i=0;i<t[1].length;i++)if(1===t[1][i].ptype){if(!t[1][i].calculated){var a=t[1][i].quantity;t[1][i].calculated=!0;for(var s=0;s<t[1].length;s++)if(t[1][s].id_product===t[1][i].id_product&&(t[1][s].calculated||(a+=t[1][s].quantity,t[1][s].calculated=!0)),5===t[1][s].ptype)for(var r=0;r<t[1][s].combos.length;r++)t[1][s].combos[r].id_product===t[1][i].id_product&&(t[1][s].combos[r].calculated||(a+=t[1][s].quantity*t[1][s].combos[r].quantity,t[1][s].combos[r].calculated=!0));var l={};null!=(d=o.getlocalProduct(t[1][i].id_product)).quantity_branch?(l=d.quantity_branch,null!=d.quantity_branch[t[0].id_branch]?l[t[0].id_branch]=l[t[0].id_branch]+a:l[t[0].id_branch]=a):l[t[0].id_branch]=a;var c=d.quantity+a;e[e.length]=o.vhmongo_firebase.database().updateDoc("products",d._id,{quantity:c,quantity_branch:l})}}else if(5===t[1][i].ptype){for(var u=0;u<t[1][i].combos.length;u++)if(!t[1][i].combos[u].calculated){a=t[1][i].quantity*t[1][i].combos[u].quantity;t[1][i].combos[u].calculated=!0;for(s=0;s<t[1].length;s++)if(t[1][s].id_product===t[1][i].combos[u].id_product&&(t[1][s].calculated||(a+=t[1][s].quantity,t[1][s].calculated=!0)),5===t[1][s].ptype)for(r=0;r<t[1][s].combos.length;r++)t[1][s].combos[r].id_product===t[1][i].combos[u].id_product&&(t[1][s].combos[r].calculated||(a+=t[1][s].quantity*t[1][s].combos[r].quantity,t[1][s].combos[r].calculated=!0));var d;l={};null!=(d=o.getlocalProduct(t[1][i].combos[u].id_product)).quantity_branch?(l=d.quantity_branch,null!=d.quantity_branch[t[0].id_branch]?l[t[0].id_branch]=l[t[0].id_branch]+a:l[t[0].id_branch]=a):l[t[0].id_branch]=a;c=d.quantity+a;e[e.length]=o.vhmongo_firebase.database().updateDoc("products",d._id,{quantity:c,quantity_branch:l})}}else e[e.length]=new Promise((function(t){t(null)}));o.vhQuery.asyncPromiseAll(e).then((function(){n(t)}))}))}else if(2===t[0].bill_type||3===t[0].bill_type){for(i=new Array,s=0;s<t[1].length;s++)i[s]=o.vhmongo_firebase.database().deleteDoc("vhbill_details",t[1][s]._id);o.vhQuery.asyncPromiseAll(i).then((function(){for(var e=new Array,i=0;i<t[1].length;i++)if(1===t[1][i].ptype){if(!t[1][i].calculated){var a=t[1][i].quantity;t[1][i].calculated=!0;for(var s=0;s<t[1].length;s++)if(t[1][s].id_product===t[1][i].id_product&&(t[1][s].calculated||(a+=t[1][s].quantity,t[1][s].calculated=!0)),5===t[1][s].ptype)for(var r=0;r<t[1][s].combos.length;r++)t[1][s].combos[r].id_product===t[1][i].id_product&&(t[1][s].combos[r].calculated||(a+=t[1][s].quantity*t[1][s].combos[r].quantity,t[1][s].combos[r].calculated=!0));var l={};null!=(d=o.getlocalProduct(t[1][i].id_product)).quantity_branch?(l=d.quantity_branch,null!=d.quantity_branch[t[0].id_branch]?l[t[0].id_branch]=l[t[0].id_branch]-a:l[t[0].id_branch]=-a):l[t[0].id_branch]=-a;var c=d.quantity-a;e[e.length]=o.vhmongo_firebase.database().updateDoc("products",d._id,{quantity:c,quantity_branch:l})}}else if(5===t[1][i].ptype){for(var u=0;u<t[1][i].combos.length;u++)if(!t[1][i].combos[u].calculated){a=t[1][i].quantity*t[1][i].combos[u].quantity;t[1][i].combos[u].calculated=!0;for(s=0;s<t[1].length;s++)if(t[1][s].id_product===t[1][i].combos[u].id_product&&(t[1][s].calculated||(a+=t[1][s].quantity,t[1][s].calculated=!0)),5===t[1][s].ptype)for(r=0;r<t[1][s].combos.length;r++)t[1][s].combos[r].id_product===t[1][i].combos[u].id_product&&(t[1][s].combos[r].calculated||(a+=t[1][s].quantity*t[1][s].combos[r].quantity,t[1][s].combos[r].calculated=!0));var d;l={};null!=(d=o.getlocalProduct(t[1][i].combos[u].id_product)).quantity_branch?(l=d.quantity_branch,null!=d.quantity_branch[t[0].id_branch]?l[t[0].id_branch]=l[t[0].id_branch]-a:l[t[0].id_branch]=-a):l[t[0].id_branch]=-a;c=d.quantity-a;e[e.length]=o.vhmongo_firebase.database().updateDoc("products",d._id,{quantity:c,quantity_branch:l})}}else e[e.length]=new Promise((function(t){t(null)}));o.vhQuery.asyncPromiseAll(e).then((function(){n(t)}))}))}else if(9===t[0].bill_type){for(i=new Array,s=0;s<t[1].length;s++)i[s]=o.vhmongo_firebase.database().deleteDoc("vhbill_details",t[1][s]._id);o.vhQuery.asyncPromiseAll(i).then((function(){for(var i=new Array,a=function(n){i[n]=new Promise((function(i){var a;if(1===t[1][n].ptype){var s=o.getlocalProduct(t[1][n].id_product),r={};null!=s.quantity_branch?(r=s.quantity_branch,null!=s.quantity_branch[e.id_branch]?r[e.id_branch]=r[e.id_branch]-t[1][n].quantity:r[e.id_branch]=-t[1][n].quantity):r[e.id_branch]=-t[1][n].quantity;var l=s.quantity-t[1][n].quantity,c={};null!=s[e.id_branch]&&null!=s[e.id_branch].inventory&&(c[e.id_branch]=s[e.id_branch],null===(a=c[e.id_branch])||void 0===a||delete a.inventory),o.vhmongo_firebase.database().updateDoc("products",s._id,Object.assign({quantity:l,quantity_branch:r},c)).then((function(){i(null)}))}else i(null)}))},s=0;s<t[1].length;s++)a(s);o.vhQuery.asyncPromiseAll(i).then((function(){n(t)}))}))}else if(5===t[0].bill_type||6===t[0].bill_type||13===t[0].bill_type||14===t[0].bill_type||16===t[0].bill_type||18===t[0].bill_type||19===t[0].bill_type||20===t[0].bill_type||21===t[0].bill_type||29===t[0].bill_type){for(i=new Array,s=0;s<t[1].length;s++)i[s]=o.vhmongo_firebase.database().deleteDoc("vhbill_details",t[1][s]._id);o.vhQuery.asyncPromiseAll(i).then((function(){n(t)}))}else a("Lưu không thành công, vui lòng kiểm tra lại.")}))})).then((function(a){if(1===e.bill_type||10===e.bill_type||15===e.bill_type){var s=new Array;(l=Object.assign({},e)).bill_code=a[0].bill_code,l.id_branch=a[0].id_branch,l.date||(l.date=a[0].date),s[n.length]=o.vhmongo_firebase.database().updateDoc("bills",t,l);for(var r=0;r<n.length;r++){(_=Object.assign({},n[r])).id_bill=t,a[0].bill_code&&(_.bill_code=a[0].bill_code),a[0].id_branch&&(_.id_branch=a[0].id_branch),a[0].date&&(_.date=a[0].date),e.date&&(_.date=e.date),"number"==typeof e.tax&&(_.tax=e.tax),"number"==typeof e.bill_type&&(_.bill_type=e.bill_type),e.id_cashier&&(_.id_cashier=e.id_cashier),e.id_employee&&(_.id_employee=e.id_employee),e.id_supplier&&(_.id_supplier=e.id_supplier),e.id_customer&&(_.id_customer=e.id_customer),e.id_inventorytime&&(_.id_inventorytime=e.id_inventorytime),s[r]=o.vhmongo_firebase.database().addDoc("vhbill_details",_)}o.vhQuery.asyncPromiseAll(s).then((function(){for(var a=new Array,s=0;s<n.length;s++)if(1===n[s].ptype){if(!n[s].calculated){var r=n[s].quantity;n[s].calculated=!0;for(var l=0;l<n.length;l++)if(n[l].id_product===n[s].id_product&&(n[l].calculated||(r+=n[l].quantity,n[l].calculated=!0)),5===n[l].ptype)for(var c=0;c<n[l].combos.length;c++)n[l].combos[c].id_product===n[s].id_product&&(n[l].combos[c].calculated||(r+=n[l].quantity*n[l].combos[c].quantity,n[l].combos[c].calculated=!0));var u={};null!=(p=o.getlocalProduct(n[s].id_product)).quantity_branch?(u=p.quantity_branch,null!=p.quantity_branch[e.id_branch]?u[e.id_branch]=u[e.id_branch]-r:u[e.id_branch]=-r):u[e.id_branch]=-r;var d=p.quantity-r;a[a.length]=o.vhmongo_firebase.database().updateDoc("products",p._id,{quantity:d,quantity_branch:u})}}else if(5===n[s].ptype){for(var _=0;_<n[s].combos.length;_++)if(!n[s].combos[_].calculated){r=n[s].quantity*n[s].combos[_].quantity;n[s].combos[_].calculated=!0;for(l=0;l<n.length;l++)if(n[l].id_product===n[s].combos[_].id_product&&(n[l].calculated||(r+=n[l].quantity,n[l].calculated=!0)),5===n[l].ptype)for(c=0;c<n[l].combos.length;c++)n[l].combos[c].id_product===n[s].combos[_].id_product&&(n[l].combos[c].calculated||(r+=n[l].quantity*n[l].combos[c].quantity,n[l].combos[c].calculated=!0));var p;u={};null!=(p=o.getlocalProduct(n[s].combos[_].id_product)).quantity_branch?(u=p.quantity_branch,null!=p.quantity_branch[e.id_branch]?u[e.id_branch]=u[e.id_branch]-r:u[e.id_branch]=-r):u[e.id_branch]=-r;d=p.quantity-r;a[a.length]=o.vhmongo_firebase.database().updateDoc("products",p._id,{quantity:d,quantity_branch:u})}}else a[a.length]=new Promise((function(t){t(null)}));o.vhQuery.asyncPromiseAll(a).then((function(){i(t)}))}))}else if(2===e.bill_type||3===e.bill_type){s=new Array;(l=Object.assign({},e)).bill_code=a[0].bill_code,l.id_branch=a[0].id_branch,l.date||(l.date=a[0].date),s[n.length]=o.vhmongo_firebase.database().updateDoc("bills",t,l);for(r=0;r<n.length;r++){(_=Object.assign({},n[r])).id_bill=t,a[0].bill_code&&(_.bill_code=a[0].bill_code),a[0].id_branch&&(_.id_branch=a[0].id_branch),a[0].date&&(_.date=a[0].date),e.date&&(_.date=e.date),"number"==typeof e.tax&&(_.tax=e.tax),"number"==typeof e.bill_type&&(_.bill_type=e.bill_type),e.id_cashier&&(_.id_cashier=e.id_cashier),e.id_employee&&(_.id_employee=e.id_employee),e.id_supplier&&(_.id_supplier=e.id_supplier),e.id_customer&&(_.id_customer=e.id_customer),e.id_inventorytime&&(_.id_inventorytime=e.id_inventorytime),s[r]=o.vhmongo_firebase.database().addDoc("vhbill_details",_)}o.vhQuery.asyncPromiseAll(s).then((function(){for(var a=new Array,s=0;s<n.length;s++)if(1===n[s].ptype){if(!n[s].calculated){var r=n[s].quantity;n[s].calculated=!0;for(var l=0;l<n.length;l++)if(n[l].id_product===n[s].id_product&&(n[l].calculated||(r+=n[l].quantity,n[l].calculated=!0)),5===n[l].ptype)for(var c=0;c<n[l].combos.length;c++)n[l].combos[c].id_product===n[s].id_product&&(n[l].combos[c].calculated||(r+=n[l].quantity*n[l].combos[c].quantity,n[l].combos[c].calculated=!0));var u={};null!=(p=o.getlocalProduct(n[s].id_product)).quantity_branch?(u=p.quantity_branch,null!=p.quantity_branch[e.id_branch]?u[e.id_branch]=u[e.id_branch]+r:u[e.id_branch]=+r):u[e.id_branch]=+r;var d=p.quantity+r;a[a.length]=o.vhmongo_firebase.database().updateDoc("products",p._id,{quantity:d,quantity_branch:u})}}else if(5===n[s].ptype){for(var _=0;_<n[s].combos.length;_++)if(!n[s].combos[_].calculated){r=n[s].quantity*n[s].combos[_].quantity;n[s].combos[_].calculated=!0;for(l=0;l<n.length;l++)if(n[l].id_product===n[s].combos[_].id_product&&(n[l].calculated||(r+=n[l].quantity,n[l].calculated=!0)),5===n[l].ptype)for(c=0;c<n[l].combos.length;c++)n[l].combos[c].id_product===n[s].combos[_].id_product&&(n[l].combos[c].calculated||(r+=n[l].quantity*n[l].combos[c].quantity,n[l].combos[c].calculated=!0));var p;u={};null!=(p=o.getlocalProduct(n[s].combos[_].id_product)).quantity_branch?(u=p.quantity_branch,null!=p.quantity_branch[e.id_branch]?u[e.id_branch]=u[e.id_branch]+r:u[e.id_branch]=+r):u[e.id_branch]=+r;d=p.quantity+r;a[a.length]=o.vhmongo_firebase.database().updateDoc("products",p._id,{quantity:d,quantity_branch:u})}}else a[a.length]=new Promise((function(t){t(null)}));o.vhQuery.asyncPromiseAll(a).then((function(){i(t)}))}))}else if(9===e.bill_type){s=new Array;(l=Object.assign({},e)).bill_code=a[0].bill_code,l.id_branch=a[0].id_branch,l.date||(l.date=a[0].date),s[n.length]=o.vhmongo_firebase.database().updateDoc("bills",t,l);for(r=0;r<n.length;r++){(_=Object.assign({},n[r])).id_bill=t,a[0].bill_code&&(_.bill_code=a[0].bill_code),a[0].id_branch&&(_.id_branch=a[0].id_branch),a[0].date&&(_.date=a[0].date),e.date&&(_.date=e.date),"number"==typeof e.tax&&(_.tax=e.tax),"number"==typeof e.bill_type&&(_.bill_type=e.bill_type),e.id_cashier&&(_.id_cashier=e.id_cashier),e.id_employee&&(_.id_employee=e.id_employee),e.id_supplier&&(_.id_supplier=e.id_supplier),e.id_customer&&(_.id_customer=e.id_customer),e.id_inventorytime&&(_.id_inventorytime=e.id_inventorytime),s[r]=o.vhmongo_firebase.database().addDoc("vhbill_details",_)}o.vhQuery.asyncPromiseAll(s).then((function(){for(var a=new Array,s=function(t){a[t]=new Promise((function(i){var a;if(1===n[t].ptype){var s=o.getlocalProduct(n[t].id_product),r={};null!=s.quantity_branch?(r=s.quantity_branch,null!=s.quantity_branch[e.id_branch]?r[e.id_branch]=r[e.id_branch]+n[t].quantity:r[e.id_branch]=n[t].quantity):r[e.id_branch]=n[t].quantity;var l=s.quantity+n[t].quantity,c={};null!=s[e.id_branch]&&null!=s[e.id_branch].inventory&&(c[e.id_branch]=s[e.id_branch],null===(a=c[e.id_branch])||void 0===a||delete a.inventory),o.vhmongo_firebase.database().updateDoc("products",s._id,Object.assign({quantity:l,quantity_branch:r},c)).then((function(){i(null)}))}else i(null)}))},r=0;r<n.length;r++)s(r);o.vhQuery.asyncPromiseAll(a).then((function(){i(t)}))}))}else if(5===e.bill_type||6===e.bill_type||13===e.bill_type||14===e.bill_type||16===e.bill_type||18===e.bill_type||19===e.bill_type||20===e.bill_type||21===e.bill_type||29===e.bill_type){var l;s=new Array;(l=Object.assign({},e)).bill_code=a[0].bill_code,l.id_branch=a[0].id_branch,l.date||(l.date=a[0].date),s[n.length]=o.vhmongo_firebase.database().updateDoc("bills",t,l);for(r=0;r<n.length;r++){(_=Object.assign({},n[r])).id_bill=t,a[0].bill_code&&(_.bill_code=a[0].bill_code),a[0].id_branch&&(_.id_branch=a[0].id_branch),a[0].date&&(_.date=a[0].date),e.date&&(_.date=e.date),"number"==typeof e.tax&&(_.tax=e.tax),"number"==typeof e.bill_type&&(_.bill_type=e.bill_type),e.id_cashier&&(_.id_cashier=e.id_cashier),e.id_employee&&(_.id_employee=e.id_employee),e.id_supplier&&(_.id_supplier=e.id_supplier),e.id_customer&&(_.id_customer=e.id_customer),e.id_inventorytime&&(_.id_inventorytime=e.id_inventorytime),s[r]=o.vhmongo_firebase.database().addDoc("vhbill_details",_)}o.vhQuery.asyncPromiseAll(s).then((function(){i(t)}))}else if(3031===e.bill_type){var c=new Array,u=new Array,d=Object.assign({},a[0]);d.bill_type=30,u[n.length]=o.vhmongo_firebase.database().updateDoc("bills",t,d);for(r=0;r<n.length;r++){var _;(_=Object.assign({},n[r])).id_bill=t,a[0].bill_code&&(_.bill_code=a[0].bill_code),a[0].date&&(_.date=a[0].date),a[0].id_branch&&(_.id_branch=a[0].id_branch),"number"==typeof e.tax&&(_.tax=e.tax),_.bill_type=30,e.id_cashier&&(_.id_cashier=e.id_cashier),e.id_employee&&(_.id_employee=e.id_employee),e.id_supplier&&(_.id_supplier=e.id_supplier),e.id_customer&&(_.id_customer=e.id_customer),e.id_inventorytime&&(_.id_inventorytime=e.id_inventorytime),u[r]=o.vhmongo_firebase.database().addDoc("vhbill_details",_)}o.vhQuery.asyncPromiseAll(u).then((function(){for(var t=new Array,i=0;i<n.length;i++)if(1===n[i].ptype){if(!n[i].calculated){var a=n[i].quantity;n[i].calculated=!0;for(var s=0;s<n.length;s++)if(n[s].id_product===n[i].id_product&&(n[s].calculated||(a+=n[s].quantity,n[s].calculated=!0)),5===n[s].ptype)for(var r=0;r<n[s].combos.length;r++)n[s].combos[r].id_product===n[i].id_product&&(n[s].combos[r].calculated||(a+=n[s].quantity*n[s].combos[r].quantity,n[s].combos[r].calculated=!0));var l={};null!=(_=o.getlocalProduct(n[i].id_product)).quantity_branch?(l=_.quantity_branch,null!=_.quantity_branch[e.id_branch]?l[e.id_branch]=l[e.id_branch]-a:l[e.id_branch]=-a):l[e.id_branch]=-a;var u=_.quantity-a;t[t.length]=o.vhmongo_firebase.database().updateDoc("products",_._id,{quantity:u,quantity_branch:l})}}else if(5===n[i].ptype){for(var d=0;d<n[i].combos.length;d++)if(!n[i].combos[d].calculated){a=n[i].quantity*n[i].combos[d].quantity;n[i].combos[d].calculated=!0;for(s=0;s<n.length;s++)if(n[s].id_product===n[i].combos[d].id_product&&(n[s].calculated||(a+=n[s].quantity,n[s].calculated=!0)),5===n[s].ptype)for(r=0;r<n[s].combos.length;r++)n[s].combos[r].id_product===n[i].combos[d].id_product&&(n[s].combos[r].calculated||(a+=n[s].quantity*n[s].combos[r].quantity,n[s].combos[r].calculated=!0));var _;l={};null!=(_=o.getlocalProduct(n[i].combos[d].id_product)).quantity_branch?(l=_.quantity_branch,null!=_.quantity_branch[e.id_branch]?l[e.id_branch]=l[e.id_branch]-a:l[e.id_branch]=-a):l[e.id_branch]=-a;u=_.quantity-a;t[t.length]=o.vhmongo_firebase.database().updateDoc("products",_._id,{quantity:u,quantity_branch:l})}}else t[t.length]=new Promise((function(t){t(null)}));c[0]=o.vhQuery.asyncPromiseAll(t)}));var p=new Array,b=Object.assign({},e);null==b||delete b.id_branch_receive,b.bill_type=31,b.bill_code=a[0].bill_code,b.id_branch=a[0].id_branch_receive,b.id_branch_send=a[0].id_branch,b.date=a[0].date,o.vhmongo_firebase.database().addDoc("bills",b).then((function(t){for(var i=0;i<n.length;i++){var s=Object.assign({},n[i]);s.id_bill=t._id,a[0].bill_code&&(s.bill_code=a[0].bill_code),a[0].date&&(s.date=a[0].date),a[0].id_branch&&(s.id_branch=a[0].id_branch_receive),"number"==typeof e.tax&&(s.tax=e.tax),s.bill_type=31,e.id_cashier&&(s.id_cashier=e.id_cashier),e.id_employee&&(s.id_employee=e.id_employee),e.id_supplier&&(s.id_supplier=e.id_supplier),e.id_customer&&(s.id_customer=e.id_customer),e.id_inventorytime&&(s.id_inventorytime=e.id_inventorytime),p[i]=o.vhmongo_firebase.database().addDoc("vhbill_details",s)}o.vhQuery.asyncPromiseAll(p).then((function(){for(var t=new Array,i=0;i<n.length;i++)if(1===n[i].ptype){if(!n[i].calculated){var a=n[i].quantity;n[i].calculated=!0;for(var s=0;s<n.length;s++)if(n[s].id_product===n[i].id_product&&(n[s].calculated||(a+=n[s].quantity,n[s].calculated=!0)),5===n[s].ptype)for(var r=0;r<n[s].combos.length;r++)n[s].combos[r].id_product===n[i].id_product&&(n[s].combos[r].calculated||(a+=n[s].quantity*n[s].combos[r].quantity,n[s].combos[r].calculated=!0));var l={};null!=(_=o.getlocalProduct(n[i].id_product)).quantity_branch?(l=_.quantity_branch,null!=_.quantity_branch[e.id_branch]?l[e.id_branch]=l[e.id_branch]+a:l[e.id_branch]=+a):l[e.id_branch]=+a;var u=_.quantity+a;t[t.length]=o.vhmongo_firebase.database().updateDoc("products",_._id,{quantity:u,quantity_branch:l})}}else if(5===n[i].ptype){for(var d=0;d<n[i].combos.length;d++)if(!n[i].combos[d].calculated){a=n[i].quantity*n[i].combos[d].quantity;n[i].combos[d].calculated=!0;for(s=0;s<n.length;s++)if(n[s].id_product===n[i].combos[d].id_product&&(n[s].calculated||(a+=n[s].quantity,n[s].calculated=!0)),5===n[s].ptype)for(r=0;r<n[s].combos.length;r++)n[s].combos[r].id_product===n[i].combos[d].id_product&&(n[s].combos[r].calculated||(a+=n[s].quantity*n[s].combos[r].quantity,n[s].combos[r].calculated=!0));var _;l={};null!=(_=o.getlocalProduct(n[i].combos[d].id_product)).quantity_branch?(l=_.quantity_branch,null!=_.quantity_branch[e.id_branch]?l[e.id_branch]=l[e.id_branch]+a:l[e.id_branch]=a):l[e.id_branch]=a;u=_.quantity+a;t[t.length]=o.vhmongo_firebase.database().updateDoc("products",_._id,{quantity:u,quantity_branch:l})}}else t[t.length]=new Promise((function(t){t(null)}));c[1]=o.vhQuery.asyncPromiseAll(t)}))}),(function(t){console.log("error",t)})),o.vhQuery.asyncPromiseAll(c).then((function(){i(t)}))}}),(function(t){return a(t)}))}))},t.prototype.deleteBill_Billdetail=function(t){var e=this;return new Promise((function(n,o){var i=e.vhmongo_firebase.database().getDoc("bills",t),a=e.vhmongo_firebase.database().getDocsByFields("vhbill_details",{id_bill:{$eq:t}},{},{},0);e.vhQuery.asyncPromiseAll([i,a]).then((function(i){var a=new Array;if(!i[0])return o({message:"id_bill "+t+" không tồn tại"});if(1===i[0].bill_type){for(var s=0;s<i[1].length;s++)a[s]=e.vhmongo_firebase.database().deleteDoc("vhbill_details",i[1][s]._id);a[i[1].length]=e.vhmongo_firebase.database().deleteDoc("bills",t),null!=i[0].id_shop&&null!=i[0].order_number_ecommerce&&e.vhmongo_firebase.database().updateDoc(i[0].id_shop,i[0].order_number_ecommerce,{id_bill_delivered_goods:null})}else if(2===i[0].bill_type){for(s=0;s<i[1].length;s++)a[s]=e.vhmongo_firebase.database().deleteDoc("vhbill_details",i[1][s]._id);a[i[1].length]=e.vhmongo_firebase.database().deleteDoc("bills",t)}else if(3===i[0].bill_type){for(s=0;s<i[1].length;s++)a[s]=e.vhmongo_firebase.database().deleteDoc("vhbill_details",i[1][s]._id);a[i[1].length]=e.vhmongo_firebase.database().deleteDoc("bills",t),null!=i[0].id_shop&&null!=i[0].order_number_ecommerce&&e.vhmongo_firebase.database().updateDoc(i[0].id_shop,i[0].order_number_ecommerce,{id_bill_received_goods:null})}else if(10===i[0].bill_type){for(s=0;s<i[1].length;s++)a[s]=e.vhmongo_firebase.database().deleteDoc("vhbill_details",i[1][s]._id);a[i[1].length]=e.vhmongo_firebase.database().deleteDoc("bills",t)}else if(15===i[0].bill_type){for(s=0;s<i[1].length;s++)a[s]=e.vhmongo_firebase.database().deleteDoc("vhbill_details",i[1][s]._id);a[i[1].length]=e.vhmongo_firebase.database().deleteDoc("bills",t)}else if(9===i[0].bill_type){for(s=0;s<i[1].length;s++)a[s]=e.vhmongo_firebase.database().deleteDoc("vhbill_details",i[1][s]._id);a[i[1].length]=e.vhmongo_firebase.database().deleteDoc("bills",t)}else{if(5!==i[0].bill_type&&6!==i[0].bill_type&&13!==i[0].bill_type&&14!==i[0].bill_type&&16!==i[0].bill_type&&18!==i[0].bill_type&&19!==i[0].bill_type&&20!==i[0].bill_type&&21!==i[0].bill_type&&29!==i[0].bill_type)return 7===i[0].bill_type||8===i[0].bill_type||11===i[0].bill_type||12===i[0].bill_type?o({message:"Loại bill_type "+i[0].bill_type+"này không phát sinh bill_detail dùng hàm deleteBill xóa"}):o({message:"Loại bill_type "+i[0].bill_type+" này không thể xóa hoặc liên hệ anh Huy"});for(s=0;s<i[1].length;s++)a[s]=e.vhmongo_firebase.database().deleteDoc("vhbill_details",i[1][s]._id);a[i[1].length]=e.vhmongo_firebase.database().deleteDoc("bills",t)}1===i[0].bill_type||10===i[0].bill_type||15===i[0].bill_type?e.vhQuery.asyncPromiseAll(a).then((function(){for(var t=new Array,o=0;o<i[1].length;o++)if(1===i[1][o].ptype){if(!i[1][o].calculated){var a=i[1][o].quantity;i[1][o].calculated=!0;for(var s=0;s<i[1].length;s++)if(i[1][s].id_product===i[1][o].id_product&&(i[1][s].calculated||(a+=i[1][s].quantity,i[1][s].calculated=!0)),5===i[1][s].ptype)for(var r=0;r<i[1][s].combos.length;r++)i[1][s].combos[r].id_product===i[1][o].id_product&&(i[1][s].combos[r].calculated||(a+=i[1][s].quantity*i[1][s].combos[r].quantity,i[1][s].combos[r].calculated=!0));var l={};null!=(d=e.getlocalProduct(i[1][o].id_product)).quantity_branch?(l=d.quantity_branch,null!=d.quantity_branch[i[0].id_branch]?l[i[0].id_branch]=l[i[0].id_branch]+a:l[i[0].id_branch]=a):l[i[0].id_branch]=a;var c=d.quantity+a;t[t.length]=e.vhmongo_firebase.database().updateDoc("products",d._id,{quantity:c,quantity_branch:l})}}else if(5===i[1][o].ptype){for(var u=0;u<i[1][o].combos.length;u++)if(!i[1][o].combos[u].calculated){a=i[1][o].quantity*i[1][o].combos[u].quantity;i[1][o].combos[u].calculated=!0;for(s=0;s<i[1].length;s++)if(i[1][s].id_product===i[1][o].combos[u].id_product&&(i[1][s].calculated||(a+=i[1][s].quantity,i[1][s].calculated=!0)),5===i[1][s].ptype)for(r=0;r<i[1][s].combos.length;r++)i[1][s].combos[r].id_product===i[1][o].combos[u].id_product&&(i[1][s].combos[r].calculated||(a+=i[1][s].quantity*i[1][s].combos[r].quantity,i[1][s].combos[r].calculated=!0));var d;l={};null!=(d=e.getlocalProduct(i[1][o].combos[u].id_product)).quantity_branch?(l=d.quantity_branch,null!=d.quantity_branch[i[0].id_branch]?l[i[0].id_branch]=l[i[0].id_branch]+a:l[i[0].id_branch]=a):l[i[0].id_branch]=a;c=d.quantity+a;t[t.length]=e.vhmongo_firebase.database().updateDoc("products",d._id,{quantity:c,quantity_branch:l})}}else t[t.length]=new Promise((function(t){t(null)}));e.vhQuery.asyncPromiseAll(t).then((function(){n(null)}))})):2===i[0].bill_type||3===i[0].bill_type?e.vhQuery.asyncPromiseAll(a).then((function(){for(var t=new Array,o=0;o<i[1].length;o++)if(1===i[1][o].ptype){if(!i[1][o].calculated){var a=i[1][o].quantity;i[1][o].calculated=!0;for(var s=0;s<i[1].length;s++)if(i[1][s].id_product===i[1][o].id_product&&(i[1][s].calculated||(a+=i[1][s].quantity,i[1][s].calculated=!0)),5===i[1][s].ptype)for(var r=0;r<i[1][s].combos.length;r++)i[1][s].combos[r].id_product===i[1][o].id_product&&(i[1][s].combos[r].calculated||(a+=i[1][s].quantity*i[1][s].combos[r].quantity,i[1][s].combos[r].calculated=!0));var l={};null!=(d=e.getlocalProduct(i[1][o].id_product)).quantity_branch?(l=d.quantity_branch,null!=d.quantity_branch[i[0].id_branch]?l[i[0].id_branch]=l[i[0].id_branch]-a:l[i[0].id_branch]=-a):l[i[0].id_branch]=-a;var c=d.quantity-a;t[t.length]=e.vhmongo_firebase.database().updateDoc("products",d._id,{quantity:c,quantity_branch:l})}}else if(5===i[1][o].ptype){for(var u=0;u<i[1][o].combos.length;u++)if(!i[1][o].combos[u].calculated){a=i[1][o].quantity*i[1][o].combos[u].quantity;i[1][o].combos[u].calculated=!0;for(s=0;s<i[1].length;s++)if(i[1][s].id_product===i[1][o].combos[u].id_product&&(i[1][s].calculated||(a+=i[1][s].quantity,i[1][s].calculated=!0)),5===i[1][s].ptype)for(r=0;r<i[1][s].combos.length;r++)i[1][s].combos[r].id_product===i[1][o].combos[u].id_product&&(i[1][s].combos[r].calculated||(a+=i[1][s].quantity*i[1][s].combos[r].quantity,i[1][s].combos[r].calculated=!0));var d;l={};null!=(d=e.getlocalProduct(i[1][o].combos[u].id_product)).quantity_branch?(l=d.quantity_branch,null!=d.quantity_branch[i[0].id_branch]?l[i[0].id_branch]=l[i[0].id_branch]-a:l[i[0].id_branch]=-a):l[i[0].id_branch]=-a;c=d.quantity-a;t[t.length]=e.vhmongo_firebase.database().updateDoc("products",d._id,{quantity:c,quantity_branch:l})}}else t[t.length]=new Promise((function(t){t(null)}));e.vhQuery.asyncPromiseAll(t).then((function(){n(null)}))})):9===i[0].bill_type?e.vhQuery.asyncPromiseAll(a).then((function(){for(var t=new Array,o=function(n){t[n]=new Promise((function(t){var o;if(1===i[1][n].ptype){var a=e.getlocalProduct(i[1][n].id_product),s={};null!=a.quantity_branch?(s=a.quantity_branch,null!=a.quantity_branch[i[0].id_branch]?s[i[0].id_branch]=s[i[0].id_branch]-i[1][n].quantity:s[i[0].id_branch]=-i[1][n].quantity):s[i[0].id_branch]=-i[1][n].quantity;var r=a.quantity-i[1][n].quantity,l={};null!=a[i[0].id_branch]&&null!=a[i[0].id_branch].inventory&&(l[i[0].id_branch]=a[i[0].id_branch],null===(o=l[i[0].id_branch])||void 0===o||delete o.inventory),e.vhmongo_firebase.database().updateDoc("products",a._id,Object.assign({quantity:r,quantity_branch:s},l)).then((function(){t(null)}))}else t(null)}))},a=0;a<i[1].length;a++)o(a);e.vhQuery.asyncPromiseAll(t).then((function(){n(null)}))})):e.vhQuery.asyncPromiseAll(a).then((function(){n(null)}))}),(function(t){console.log("error",t),o(t)}))}))},t.prototype.getBill_details_byId_bill=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("vhbill_details",{id_bill:{$eq:t}},{},{},0).then((function(t){var e=new Array;if(t.length>0)for(var o=0;o<t.length;o++){var i=Object.assign({},t[o]);null==i||delete i.bill_code,null==i||delete i.date,null==i||delete i.tax,null==i||delete i.bill_type,null==i||delete i.id_cashier,null==i||delete i.id_employee,null==i||delete i.id_supplier,null==i||delete i.id_customer,null==i||delete i.id_inventorytime,null==i||delete i.id_branch,e.push(i)}n(e)}),(function(t){o(t)}))}))},t.prototype.getBill_detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("vhbill_details",t).then((function(t){if(t){var e=Object.assign({},t);null==e||delete e.bill_code,null==e||delete e.date,null==e||delete e.tax,null==e||delete e.bill_type,null==e||delete e.id_cashier,null==e||delete e.id_employee,null==e||delete e.id_supplier,null==e||delete e.id_customer,null==e||delete e.id_inventorytime,null==e||delete e.id_branch,n(e)}else n(t)}),(function(t){o(t)}))}))},t.prototype.getBill_details=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("vhbill_details").then((function(t){var n=new Array;if(t.length>0)for(var o=0;o<t.length;o++){var i=Object.assign({},t[o]);null==i||delete i.bill_code,null==i||delete i.date,null==i||delete i.tax,null==i||delete i.bill_type,null==i||delete i.id_cashier,null==i||delete i.id_employee,null==i||delete i.id_supplier,null==i||delete i.id_customer,null==i||delete i.id_inventorytime,null==i||delete i.id_branch,n.push(i)}e(n)}),(function(t){n(t)}))}))},t.prototype.getBill=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("bills",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getBills=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.database().getDocsByFields("bills",t,{},n,o).then((function(t){e(t)})).catch((function(t){a(t)}))}))},t.prototype.createBill=function(t){var e=this;return new Promise((function(n,o){e.sync_code=Math.random().toString(36).substr(2,10).toUpperCase(),t.sync_code=e.sync_code,e.vhmongo_firebase.database().addDoc("bills",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateBill=function(t,e){var n=this;return new Promise((function(o,i){n.sync_code=Math.random().toString(36).substr(2,10).toUpperCase(),e.sync_code=n.sync_code,"3334"===(null==e?void 0:e.bill_type)?n.vhmongo_firebase.database().getDoc("bills",t).then((function(a){32===a.bill_type?n.vhmongo_firebase.database().getDoc("bills",t).then((function(a){var s=new Array;s[0]=n.vhmongo_firebase.database().updateDoc("bills",t,{bill_type:33,sync_code:n.sync_code});var r=Object.assign({},e);null==r||delete r.id_branch_receive,r.bill_type=34,r.bill_code=a.bill_code,r.id_branch=a.id_branch_receive,r.id_branch_send=a.id_branch,r.date=a.date,s[1]=n.vhmongo_firebase.database().addDoc("bills",r),Promise.all(s).then((function(){o(!0)})).catch((function(t){i(t)}))})):i("Lưu không thành công, vui lòng kiểm tra lại.")})):n.vhmongo_firebase.database().updateDoc("bills",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteBill=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("bills",t).then((function(i){if(i){var a=void 0;(7===i.bill_type||8===i.bill_type||11===i.bill_type||12===i.bill_type||32===i.bill_type)&&(a=e.vhmongo_firebase.database().deleteDoc("bills",t)),a.then((function(t){return n(t)}))}else o({message:t+" no exist"})}))}))},t.prototype.observableSyncOpeningBill=function(t,e){var n=this;return new c.Observable((function(o){var i=0;n.callbacksyncopeningbill=n.vhmongo_firebase.socketMongoDB().initSyncOpeningBill(t).subscribe((function(a){if(a.exists)if(a.data().sync_code!=n.sync_code)if(a.data().bill_type===e){if(i++){var s=Object.assign(Object.assign({},n.vhmongo_firebase.database().cvtDataFB2MG(a.data())),{_id:a.id});console.log("id_bill",t),o.next({vcode:0,message:"repaired bill by another device",data:s})}}else console.log("id_bill",t),o.next({vcode:1,message:"changed bill_type by another device"});else i++;else console.log("id_bill",t),o.next({vcode:2,message:"deleted bill by unknown device"})}))}))},t.prototype.closeSyncOpeningBill=function(){this.callbacksyncopeningbill.unsubscribe(),this.vhmongo_firebase.socketMongoDB().closeSyncOpeningBill()},t.prototype.createPaymentVnpay=function(t,e,n,o){this.vhmongo_firebase.paymentVNPAY().createPaymentVnpay(t,e,n,o).then((function(t){window.location=t.data}),(function(t){console.log("error",t)}))},t.prototype.createPaymentVnpay_iFrame=function(t,e,n,o){var i=this;return new Promise((function(a,s){i.vhmongo_firebase.paymentVNPAY().Create_Payment_Url_Vnpay_iFrame(t,e,n,o).then((function(t){a(t.data)}),(function(t){s(t)}))}))},t.prototype.createPayment=function(t){var e=this;return new Promise((function(n,o){t.payment_code=e.vhAlgorithm.createPaymentCode(null==t?void 0:t.date),t.id_store=e.vhmongo_firebase.auth().getDatabase(),e.vhmongo_firebase.rootdatabase().addDoc("payments",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updatePayment=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.rootdatabase().updateDoc("payments",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deletePayment=function(t){var e=this;return new Promise((function(n,o){var i={id_payment:{$eq:t}};e.vhmongo_firebase.rootdatabase().getDocsByFields("payment_details",i,{},{},0).then((function(t){if(t.length>0)for(var n=0;n<t.length;n++)e.vhmongo_firebase.rootdatabase().deleteDoc("payment_details",t[n]._id)}),(function(t){console.log(t,t)})),e.vhmongo_firebase.rootdatabase().deleteDoc("payments",t).then((function(t){n(t)}),(function(t){console.log(t,t)}))}))},t.prototype.getPayments=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.rootdatabase().getDocsByFields("payments",t,{},n,o).then((function(t){e(t)}),(function(t){console.log(t,t)}))}))},t.prototype.getPayment=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.rootdatabase().getDoc("payments",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.createPayment_Detail=function(t){var e=this;return new Promise((function(n,o){null!=t.id_payment&&null!=t.id_payment?e.vhmongo_firebase.rootdatabase().getDoc("payments",t.id_payment).then((function(i){var a=t;a.activating=!1,a.invalid=!1,a.date=i.date,i.id_store&&(a.id_store=i.id_store),"number"==typeof i.payment_type&&(a.payment_type=i.payment_type),e.vhmongo_firebase.rootdatabase().addDoc("payment_details",a).then((function(t){n(t)}),(function(t){o(t)}))}),(function(t){console.log("error",t)})):console.log("error","không tồn tại id_bill trong data")}))},t.prototype.updatePayment_Detail=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.rootdatabase().updateDoc("payment_details",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.getPayment_details=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.rootdatabase().getDocsByFields("payment_details",t,{},n,o).then((function(t){e(t)}),(function(t){console.log(t,t)}))}))},t.prototype.getPayment_detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.rootdatabase().getDoc("payment_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.deletePayment_Detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.rootdatabase().deleteDoc("payment_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPackage=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.rootdatabase().getDoc("packages",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.publishObservableEventPromotions=function(){this.subjectpromotions.next(this.promotions)},t.prototype.observableLocalPromotions=function(){return this.subjectpromotions},t.prototype.getObservableLocalPromotions=function(){var t=this;return new c.Observable((function(e){t.observableLocalPromotions().subscribe((function(t){e.next(t)})),t.publishObservableEventPromotions()}))},t.prototype.getlocalPromotion=function(t){for(var e=0;e<this.promotions.length;e++)if(this.promotions[e]._id===t)return this.suppliers[e];return null},t.prototype.getlocalPromotions=function(){return this.promotions},t.prototype.refreshLocalPromotions=function(){return new Promise((function(t,e){t(null)}))},t.prototype.addPromotion=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("promotions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updatePromotion=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("promotions",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deletePromotion=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("promotions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPromotion=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("promotions",t).then((function(t){n(t)}))}))},t.prototype.getPromotions=function(){var t=this;return new Promise((function(e){t.vhmongo_firebase.database().getDocs("promotions").then((function(n){t.promotions=n,e(n)}))}))},t.prototype.addPromotion_detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("promotion_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updatePromotion_detail=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("promotion_details",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deletePromotion_detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("promotion_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPromotion_detail=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("promotion_details",t).then((function(t){n(t)}))}))},t.prototype.getPromotion_details=function(){var t=this;return new Promise((function(e){t.vhmongo_firebase.database().getDocs("promotion_details").then((function(t){e(t)}))}))},t.prototype.addPromotion_Promotiondetail=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().addDoc("promotions",t).then((function(t){for(var a=new Array,s=0;s<e.length;s++){var r=e[s];r.id_promotion=t._id,a[s]=n.vhmongo_firebase.database().addDoc("promotion_details",r)}Promise.all(a).then((function(){o(t)})).catch((function(t){i(t)}))}),(function(t){i(t)}))}))},t.prototype.updatePromotion_Promotiondetail=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.database().getDocsByFields("promotion_details",{id_promotion:{$eq:t}},{},{},0).then((function(s){for(var r=new Array,l=0;l<s.length;l++)r[l]=o.vhmongo_firebase.database().deleteDoc("promotion_details",s[l]._id);var c=Object.assign({},e);r[s.length]=o.vhmongo_firebase.database().updateDoc("promotions",t,c);for(l=0;l<n.length;l++){var u=n[l];u.id_promotion=t,r[l+s.length+1]=o.vhmongo_firebase.database().addDoc("promotion_details",u)}Promise.all(r).then((function(){i(!0)})).catch((function(t){a(t)}))})).catch((function(){i(!1)}))}))},t.prototype.deletePromotion_Promotiondetail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("promotion_details",{id_promotion:{$eq:t}},{},{},0).then((function(i){for(var a=new Array,s=0;s<i.length;s++)a[s]=e.vhmongo_firebase.database().deleteDoc("promotion_details",i[s]._id);a[i.length]=e.vhmongo_firebase.database().deleteDoc("promotions",t),Promise.all(a).then((function(){n(!0)})).catch((function(t){o(t)}))})).catch((function(){n(!1)}))}))},t.prototype.getPromotion_details_byId_promotion=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDocsByFields("promotion_details",{id_promotion:{$eq:t}},{},{},0).then((function(t){n(t)})).catch((function(){n(!1)}))}))},t.prototype.checkNewPromotion=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.database().getDocs("promotions").then((function(s){var r=new Array,l=new Array;if(s.length>0){for(var c=0;c<s.length;c++)new Date(t)<new Date(s[c].date_start)?new Date(e)>=new Date(s[c].date_start)&&r.push(s[c]._id):new Date(t)>=new Date(s[c].date_start)&&new Date(t)<=new Date(s[c].date_end)&&r.push(s[c]._id);r.length>0?o.vhmongo_firebase.database().getDocsByFields("promotion_details",{id_promotion:{$in:r}},{},{},0).then((function(t){if(t.length){for(var e=0;e<n.length;e++)for(var o=0;o<t.length;o++)if(n[e]===t[o].id_product){l.push(n[e]);break}i(l)}else i(l)})).catch((function(t){a(t)})):i(l)}else i(l)}),(function(t){console.log("error",t)}))}))},t.prototype.checkOldPromotion=function(t,e,n,o){var i=this;return new Promise((function(a,s){i.vhmongo_firebase.database().getDocs("promotions").then((function(s){var r=new Array,l=new Array;if(s.length>0){for(var c=0;c<s.length;c++)new Date(t)<new Date(s[c].date_start)?new Date(e)>=new Date(s[c].date_start)&&s[c]._id!=o&&r.push(s[c]._id):new Date(t)>=new Date(s[c].date_start)&&new Date(t)<=new Date(s[c].date_end)&&s[c]._id!=o&&r.push(s[c]._id);r.length>0?i.vhmongo_firebase.database().getDocsByFields("promotion_details",{id_promotion:{$in:r}},{},{},0).then((function(t){if(t.length>0){for(var e=0;e<n.length;e++)for(var o=0;o<t.length;o++)if(n[e]===t[o].id_product){l.push(n[e]);break}a(l)}else a(l)}),(function(t){console.log("error",t)})):a(l)}else a(l)}))}))},t.prototype.publishObservableEventAppSettingNameStations=function(){this.subjectappsettingstations.next()},t.prototype.observableLocalAppSettingNameStations=function(){return this.subjectappsettingstations},t.prototype.getObservableLocalAppSettingNameStations=function(){var t=this;return new c.Observable((function(e){t.observableLocalAppSettingNameStations().subscribe((function(){for(var n=new Array,o=0;o<t.appsettingstations.length;o++)n.push(t.appsettingstations[o].appsetting_name);e.next(n)})),t.publishObservableEventAppSettingNameStations()}))},t.prototype.getLocalAppSettingNameStations=function(){for(var t=new Array,e=0;e<this.appsettingstations.length;e++)t.push(this.appsettingstations[e].appsetting_name);return t},t.prototype.getLocalAppSettingNameStation=function(t){for(var e={},n=0;n<this.appsettingstations.length;n++)if(this.appsettingstations[n].appsetting_name===t){delete(e=Object.assign({},this.appsettingstations[n]))._id,delete e.appsetting_name;break}return e},t.prototype.getLocalAppSettingStation=function(t){for(var e=0;e<this.appsettingstations.length;e++)if(this.appsettingstations[e]._id===t)return this.appsettingstations[e];return null},t.prototype.refreshLocalAppSettingNameStations=function(){return new Promise((function(t,e){t(null)}))},t.prototype.getAppSettingStations=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocsByFields("appsettingstations",{uuid:{$eq:t.hwinfo.uuid}},{},{},0).then((function(n){n.length>0&&(t.appsettingstations=n),e(null)}),(function(t){n(t)}))}))},t.prototype.updateAppSettingNameStation=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().getDocsByFields("appsettingstations",{appsetting_name:{$eq:t},uuid:{$eq:n.hwinfo.uuid}},{},{},0).then((function(a){if(a.length>0)n.vhmongo_firebase.database().updateDoc("appsettingstations",a[0]._id,e).then((function(t){o(t)}),(function(t){i(t)}));else{var s=Object.assign({},e);s.appsetting_name=t,s.uuid=n.hwinfo.uuid,n.vhmongo_firebase.database().addDoc("appsettingstations",s).then((function(){o(!0)}),(function(t){i(t)}))}}))}))},t.prototype.deleteAppSettingNameStation=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("appsettingstations",{appsetting_name:{$eq:t},uuid:{$eq:e.hwinfo.uuid}},{},{},0).then((function(t){t.length>0?e.vhmongo_firebase.database().deleteDoc("appsettingstations",t[0]._id).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}))}))},t.prototype.publishObservableEventAppSettingNameBranchs=function(){this.subjectappsettingbranchs.next()},t.prototype.observableLocalAppSettingNameBranchs=function(){return this.subjectappsettingbranchs},t.prototype.getObservableLocalAppSettingNameBranchs=function(){var t=this;return new c.Observable((function(e){t.observableLocalAppSettingNameBranchs().subscribe((function(){for(var n=new Array,o=0;o<t.appsettingbranchs.length;o++)n.push(t.appsettingbranchs[o].appsetting_name);e.next(n)})),t.publishObservableEventAppSettingNameBranchs()}))},t.prototype.getLocalAppSettingNameBranchs=function(){for(var t=new Array,e=0;e<this.appsettingbranchs.length;e++)t.push(this.appsettingbranchs[e].appsetting_name);return t},t.prototype.getLocalAppSettingNameBranch=function(t){for(var e={},n=0;n<this.appsettingbranchs.length;n++)if(this.appsettingbranchs[n].appsetting_name===t){delete(e=Object.assign({},this.appsettingbranchs[n]))._id,delete e.appsetting_name,delete e.id_branch;break}return e},t.prototype.getLocalAppSettingBranch=function(t){for(var e=0;e<this.appsettingbranchs.length;e++)if(this.appsettingbranchs[e]._id==t)return this.appsettingbranchs[e];return null},t.prototype.updateAppSettingNameBranch=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().getDocsByFields("appsettingbranchs",{appsetting_name:{$eq:t},id_branch:{$eq:n.getDefaultBranch()._id}},{},{},1).then((function(a){if(a.length>0)n.vhmongo_firebase.database().updateDoc("appsettingbranchs",a[0]._id,e).then((function(t){o(t)}),(function(t){i(t)}));else{var s=Object.assign({},e);s.appsetting_name=t,s.id_branch=n.getDefaultBranch()._id,n.vhmongo_firebase.database().addDoc("appsettingbranchs",s).then((function(){o(!0)}),(function(t){i(t)}))}}))}))},t.prototype.deleteAppSettingNameBranch=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("appsettingbranchs",{appsetting_name:{$eq:t},id_branch:{$eq:e.getDefaultBranch()._id}},{},{},0).then((function(t){t.length>0?e.vhmongo_firebase.database().deleteDoc("appsettingbranchs",t[0]._id).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}))}))},t.prototype.getReportSales_Categorys_byCategorys=function(t,e,n,o,i){var a=this;return console.log("type",o),o="all"===n?12:this.getlocalCategory(n).type,new Promise((function(s,r){var l,c,u={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};1===o?(c=1,l=[1,5]):2===o?(c=2,l=[2,5]):5===o?(c=5,l=[5]):12===o&&(c=12,l=[1,2,5]);var d,_=new Array,p=new Array;"all"===n?_=a.getlocalCategorys(c):_.push(a.getlocalCategory(n));for(var b=[1,3,15],f=0;f<b.length;f++)d="all"===i||void 0===i?{date:{$gte:t,$lte:e},ptype:{$in:l},bill_type:{$eq:b[f]}}:{date:{$gte:t,$lte:e},ptype:{$in:l},bill_type:{$eq:b[f]},id_branch:{$eq:i}},p[f]=a.vhmongo_firebase.database().getDocsByFields("vhbill_details",d,{},{date:1},0);_.length>0?Promise.all(p).then((function(t){var e=t.flat();if(e.length>0)for(var n=0;n<_.length;n++){for(var i=!1,a=Object.assign({},_[n]),r={id_category:a._id,name:a.name,sales_btax:0,sales_atax:0,quantity:0},l=0;l<e.length;l++)if(3==e[l].bill_type){if(1===o||2===o)if(5===e[l].ptype){if(null!=e[l].combos)for(var c=0;c<e[l].combos.length;c++)_[n]._id===e[l].combos[c].id_category&&(r.quantity=r.quantity-e[l].combos[c].quantity*e[l].quantity,r.sales_btax=r.sales_btax-e[l].combos[c].price*e[l].combos[c].quantity*e[l].quantity,r.sales_atax=r.sales_atax-e[l].combos[c].price*e[l].combos[c].quantity*e[l].quantity*(1+e[l].tax/100))}else _[n]._id===e[l].id_category&&(i=!0,r.quantity=r.quantity-e[l].quantity,r.sales_btax=r.sales_btax-e[l].price*e[l].quantity,r.sales_atax=r.sales_atax-e[l].price*e[l].quantity*(1+e[l].tax/100));else if(5===o){if(5===e[l].ptype&&null!=e[l].combos)for(c=0;c<e[l].combos.length;c++)_[n]._id===e[l].combos[c].id_category&&(r.quantity=r.quantity-e[l].combos[c].quantity*e[l].quantity,r.sales_btax=r.sales_btax-e[l].combos[c].price*e[l].combos[c].quantity*e[l].quantity,r.sales_atax=r.sales_atax-e[l].combos[c].price*e[l].combos[c].quantity*e[l].quantity*(1+e[l].tax/100))}else if(12===o)if(1===e[l].ptype)1===_[n].type&&_[n]._id===e[l].id_category&&(i=!0,r.quantity=r.quantity-e[l].quantity,r.sales_btax=r.sales_btax-e[l].price*e[l].quantity,r.sales_atax=r.sales_atax-e[l].price*e[l].quantity*(1+e[l].tax/100));else if(2===e[l].ptype)_[n]._id===e[l].id_category&&(i=!0,r.quantity=r.quantity-e[l].quantity,r.sales_btax=r.sales_btax-e[l].price*e[l].quantity,r.sales_atax=r.sales_atax-e[l].price*e[l].quantity*(1+e[l].tax/100));else if(5===e[l].ptype)for(c=0;c<e[l].combos.length;c++)_[n]._id===e[l].combos[c].id_category&&(i=!0,r.quantity=r.quantity-e[l].combos[c].quantity*e[l].quantity,r.sales_btax=r.sales_btax-e[l].combos[c].price*e[l].combos[c].quantity*e[l].quantity,r.sales_atax=r.sales_atax-e[l].combos[c].price*e[l].combos[c].quantity*e[l].quantity*(1+e[l].tax/100))}else if(1===o||2===o)if(5===e[l].ptype){if(null!=e[l].combos)for(c=0;c<e[l].combos.length;c++)_[n]._id===e[l].combos[c].id_category&&(r.quantity=r.quantity+e[l].combos[c].quantity*e[l].quantity,r.sales_btax=r.sales_btax+e[l].combos[c].price*e[l].combos[c].quantity*e[l].quantity,r.sales_atax=r.sales_atax+e[l].combos[c].price*e[l].combos[c].quantity*e[l].quantity*(1+e[l].tax/100))}else _[n]._id===e[l].id_category&&(i=!0,r.quantity=r.quantity+e[l].quantity,r.sales_btax=r.sales_btax+e[l].price*e[l].quantity,r.sales_atax=r.sales_atax+e[l].price*e[l].quantity*(1+e[l].tax/100));else if(5===o){if(5===e[l].ptype&&null!=e[l].combos)for(c=0;c<e[l].combos.length;c++)_[n]._id===e[l].combos[c].id_category&&(r.quantity=r.quantity+e[l].combos[c].quantity*e[l].quantity,r.sales_btax=r.sales_btax+e[l].combos[c].price*e[l].combos[c].quantity*e[l].quantity,r.sales_atax=r.sales_atax+e[l].combos[c].price*e[l].combos[c].quantity*e[l].quantity*(1+e[l].tax/100))}else if(12===o)if(1===e[l].ptype)1===_[n].type&&_[n]._id===e[l].id_category&&(i=!0,r.quantity=r.quantity+e[l].quantity,r.sales_btax=r.sales_btax+e[l].price*e[l].quantity,r.sales_atax=r.sales_atax+e[l].price*e[l].quantity*(1+e[l].tax/100));else if(2===e[l].ptype)_[n]._id===e[l].id_category&&(i=!0,r.quantity=r.quantity+e[l].quantity,r.sales_btax=r.sales_btax+e[l].price*e[l].quantity,r.sales_atax=r.sales_atax+e[l].price*e[l].quantity*(1+e[l].tax/100));else if(5===e[l].ptype){console.log("vhbill_details[j]",e[l]);for(c=0;c<e[l].combos.length;c++)_[n]._id===e[l].combos[c].id_category&&(console.log("data",r),i=!0,r.quantity=r.quantity+e[l].combos[c].quantity*e[l].quantity,r.sales_btax=r.sales_btax+e[l].combos[c].price*e[l].combos[c].quantity*e[l].quantity,r.sales_atax=r.sales_atax+e[l].combos[c].price*e[l].combos[c].quantity*e[l].quantity*(1+e[l].tax/100))}i&&(r.sales_atax=Math.round(1e6*r.sales_atax)/1e6,null!=r.subs&&r.subs.forEach((function(t){t.sales_atax=Math.round(1e6*t.sales_atax)/1e6})),null!=r.combos&&r.combos.forEach((function(t){t.sales_atax=Math.round(1e6*t.sales_atax)/1e6})),u.quantity=u.quantity+r.quantity,u.sales_btax=u.sales_btax+r.sales_btax,u.sales_atax=u.sales_atax+r.sales_atax,r.index=u.size+1,u.docs.push(r),u.size++,u.empty=!1)}console.log("getReportSales_Categorys_byCategorys"),s(u)})):s(u)}))},t.prototype.getReportSales_Categorys_byProducts=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l,c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0},u=i.getlocalProducts().filter((function(t){if(t.id_category===n)return!0})),d=i.getlocalCategory(n).type;1===d?r=[1,5]:2===d?r=[2,5]:5===d&&(r=[5]);for(var _=new Array,p=[1,3,15],b=0;b<p.length;b++)l="all"===o||void 0===o?{date:{$gte:t,$lte:e},ptype:{$in:r},bill_type:{$eq:p[b]}}:{date:{$gte:t,$lte:e},ptype:{$in:r},bill_type:{$eq:p[b]},id_branch:{$eq:o}},_[b]=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",l,{},{date:1},0);u.length>0?Promise.all(_).then((function(t){var e,n=t.flat();if(n.length>0)for(var o=0;o<u.length;o++){var i=!1,s=Object.assign({},u[o]),r={id_product:s._id,name:s.name,unit:s.unit,barcode:s.barcode,img:s.img,sales_btax:0,sales_atax:0,quantity:0};if(null!=s.combos){r.combos=new Array;for(var l=0;l<s.combos.length;l++){var _={id_product:s.combos[l].id_product,name:null===(e=s.combos[l])||void 0===e?void 0:e.name,sales_btax:0,sales_atax:0,quantity:0};null!=s.combos[l].id_subproduct&&(_.id_subproduct=s.combos[l].id_subproduct),r.combos.push(_)}}for(var p=0;p<n.length;p++)if(3==n[p].bill_type){if(1===d||2===d){if(1===n[p].ptype||2===n[p].ptype)u[o]._id===n[p].id_product&&(i=!0,r.quantity=r.quantity-n[p].quantity,r.sales_btax=r.sales_btax-n[p].price*n[p].quantity,r.sales_atax=r.sales_atax-n[p].price*n[p].quantity*(1+n[p].tax/100));else if(5===n[p].ptype)for(var b=0;b<n[p].combos.length;b++)u[o]._id===n[p].combos[b].id_product&&(i=!0,r.quantity=r.quantity-n[p].combos[b].quantity*n[p].quantity,r.sales_btax=r.sales_btax-n[p].combos[b].price*n[p].combos[b].quantity*n[p].quantity,r.sales_atax=r.sales_atax-n[p].combos[b].price*n[p].combos[b].quantity*n[p].quantity*(1+n[p].tax/100))}else if(5===d&&5===n[p].ptype&&u[o]._id===n[p].id_product&&(i=!0,r.quantity=r.quantity-n[p].quantity,r.sales_btax=r.sales_btax-n[p].price*n[p].quantity,r.sales_atax=r.sales_atax-n[p].price*n[p].quantity*(1+n[p].tax/100),null!=r.combos))for(l=0;l<r.combos.length;l++)u[o].combos[l].id_product===n[p].combos[l].id_product&&(r.combos[l].quantity=r.combos[l].quantity-n[p].combos[l].quantity*n[p].quantity,r.combos[l].sales_btax=r.combos[l].sales_btax-n[p].combos[l].price*n[p].combos[l].quantity*n[p].quantity,r.combos[l].sales_atax=r.combos[l].sales_atax-n[p].combos[l].price*n[p].combos[l].quantity*n[p].quantity*(1+n[p].tax/100))}else if(1===d||2===d){if(1===n[p].ptype||2===n[p].ptype)u[o]._id===n[p].id_product&&(i=!0,r.quantity=r.quantity+n[p].quantity,r.sales_btax=r.sales_btax+n[p].price*n[p].quantity,r.sales_atax=r.sales_atax+n[p].price*n[p].quantity*(1+n[p].tax/100));else if(5===n[p].ptype)for(b=0;b<n[p].combos.length;b++)u[o]._id===n[p].combos[b].id_product&&(i=!0,r.quantity=r.quantity+n[p].combos[b].quantity*n[p].quantity,r.sales_btax=r.sales_btax+n[p].combos[b].price*n[p].combos[b].quantity*n[p].quantity,r.sales_atax=r.sales_atax+n[p].combos[b].price*n[p].combos[b].quantity*n[p].quantity*(1+n[p].tax/100))}else if(5===d&&5===n[p].ptype&&u[o]._id===n[p].id_product&&(i=!0,r.quantity=r.quantity+n[p].quantity,r.sales_btax=r.sales_btax+n[p].price*n[p].quantity,r.sales_atax=r.sales_atax+n[p].price*n[p].quantity*(1+n[p].tax/100),null!=r.combos))for(l=0;l<r.combos.length;l++)u[o].combos[l].id_product===n[p].combos[l].id_product&&(r.combos[l].quantity=r.combos[l].quantity+n[p].combos[l].quantity*n[p].quantity,r.combos[l].sales_btax=r.combos[l].sales_btax+n[p].combos[l].price*n[p].combos[l].quantity*n[p].quantity,r.combos[l].sales_atax=r.combos[l].sales_atax+n[p].combos[l].price*n[p].combos[l].quantity*n[p].quantity*(1+n[p].tax/100));i&&(r.sales_atax=Math.round(1e6*r.sales_atax)/1e6,null!=r.subs&&r.subs.forEach((function(t){t.sales_atax=Math.round(1e6*t.sales_atax)/1e6})),null!=r.combos&&r.combos.forEach((function(t){t.sales_atax=Math.round(1e6*t.sales_atax)/1e6})),c.quantity=c.quantity+r.quantity,c.sales_btax=c.sales_btax+r.sales_btax,c.sales_atax=c.sales_atax+r.sales_atax,r.index=c.size+1,c.docs.push(r),c.size++,c.empty=!1)}console.log("jsons",c),a(c)})):a(c)}))},t.prototype.getReportSales_Categorys_byProduct=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0},l=i.getlocalProduct(n),c=new Array;i.getlocalProductAndCombos(n).forEach((function(t){c.push(t._id)}));for(var u,d=l.type,_=new Array,p=[1,3,15],b=0;b<p.length;b++)u="all"===o||void 0===o?{date:{$gte:t,$lte:e},id_product:{$in:c},bill_type:{$eq:p[b]}}:{date:{$gte:t,$lte:e},id_product:{$in:c},bill_type:{$eq:p[b]},id_branch:{$eq:o}},_[b]=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0);Promise.all(_).then((function(t){var e,n=t.flat();if(n.length>0)for(var o=0;o<n.length;o++){var s=new Array;if(s[0]={id_product:l._id,name:l.name,unit:l.unit,barcode:l.barcode,img:l.img,bill_code:n[o].bill_code,bill_type:n[o].bill_type,id_bill:n[o].id_bill,date:n[o].date,tax:n[o].tax,salesman:null===(e=i.vhAuth.getlocalEmployee(n[o].id_employee))||void 0===e?void 0:e.name,customer:i.getlocalCustomer(n[o].id_customer).name},3==n[o].bill_type)if(1===d||2===d)if(null!=n[o].combos)for(var c=0;c<n[o].combos.length;c++)n[o].combos[c].id_product===l._id&&(s[0].quantity=-n[o].combos[c].quantity*n[o].quantity,s[0].price=n[o].combos[c].price);else s[0].quantity=-n[o].quantity,s[0].price=n[o].price;else 5===d&&(s[0].quantity=-n[o].quantity,s[0].price=n[o].price);else if(1===d||2===d)if(null!=n[o].combos)for(c=0;c<n[o].combos.length;c++)n[o].combos[c].id_product===l._id&&(s[0].quantity=n[o].combos[c].quantity*n[o].quantity,s[0].price=n[o].combos[c].price);else s[0].quantity=n[o].quantity,s[0].price=n[o].price;else 5===d&&(s[0].quantity=n[o].quantity,s[0].price=n[o].price);s.forEach((function(t){t.sales_btax=t.price*t.quantity,t.sales_atax=t.price*t.quantity*(1+t.tax/100),t.index=r.size+1,r.docs.push(t),r.size++,r.empty=!1,r.quantity=r.quantity+t.quantity,r.sales_btax=r.sales_btax+t.price*t.quantity,r.sales_atax=r.sales_atax+t.price*t.quantity*(1+Number(t.tax)/100)}))}console.log("getReportSales_Categorys_byProduct"),a(r)}))}))},t.prototype.getReportSales_Products_byProducts=function(t,e,n,o,i){var a=this;return console.log("type",o),new Promise((function(s,r){var l,c,u={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};1===o?(c=1,l=[1,5]):2===o?(c=2,l=[2,5]):5===o?(c=5,l=[5]):12===o&&(c=12,l=[1,2]);var d,_=new Array,p=new Array,b=new Array;"all"===n?_=a.getlocalProducts(c):(_.push(a.getlocalProduct(n)),b=new Array,a.getlocalProductAndCombos(n).forEach((function(t){b.push(t._id)})));for(var f=[1,3,15],h=0;h<f.length;h++)d="all"===n?"all"===i||void 0===i?{date:{$gte:t,$lte:e},ptype:{$in:l},bill_type:{$eq:f[h]}}:{date:{$gte:t,$lte:e},ptype:{$in:l},bill_type:{$eq:f[h]},id_branch:{$eq:i}}:"all"===i||void 0===i?{date:{$gte:t,$lte:e},id_product:{$in:b},bill_type:{$eq:f[h]}}:{date:{$gte:t,$lte:e},id_product:{$in:b},bill_type:{$eq:f[h]},id_branch:{$eq:i}},p[h]=a.vhmongo_firebase.database().getDocsByFields("vhbill_details",d,{},{date:1},0);_.length>0?Promise.all(p).then((function(t){var e,n=t.flat();if(n.length>0)for(var i=0;i<_.length;i++){var a=!1,r=Object.assign({},_[i]),l={id_product:r._id,name:r.name,unit:r.unit,barcode:r.barcode,img:r.img,sales_btax:0,sales_atax:0,quantity:0};if(null!=r.combos){l.combos=new Array;for(var c=0;c<r.combos.length;c++){var d={id_product:r.combos[c].id_product,name:null===(e=r.combos[c])||void 0===e?void 0:e.name,sales_btax:0,sales_atax:0,quantity:0};l.combos.push(d)}}for(var p=0;p<n.length;p++)if(3==n[p].bill_type){if(1===o||2===o){if(1===n[p].ptype||2===n[p].ptype)_[i]._id===n[p].id_product&&(a=!0,l.quantity=l.quantity-n[p].quantity,l.sales_btax=l.sales_btax-n[p].price*n[p].quantity,l.sales_atax=l.sales_atax-n[p].price*n[p].quantity*(1+n[p].tax/100));else if(5===n[p].ptype)for(var b=0;b<n[p].combos.length;b++)_[i]._id===n[p].combos[b].id_product&&(a=!0,l.quantity=l.quantity-n[p].combos[b].quantity*n[p].quantity,l.sales_btax=l.sales_btax-n[p].combos[b].price*n[p].combos[b].quantity*n[p].quantity,l.sales_atax=l.sales_atax-n[p].combos[b].price*n[p].combos[b].quantity*n[p].quantity*(1+n[p].tax/100))}else if(5===o){if(5===n[p].ptype&&_[i]._id===n[p].id_product&&(a=!0,l.quantity=l.quantity-n[p].quantity,l.sales_btax=l.sales_btax-n[p].price*n[p].quantity,l.sales_atax=l.sales_atax-n[p].price*n[p].quantity*(1+n[p].tax/100),null!=l.combos))for(c=0;c<l.combos.length;c++)_[i].combos[c].id_product===n[p].combos[c].id_product&&(l.combos[c].quantity=l.combos[c].quantity-n[p].combos[c].quantity*n[p].quantity,l.combos[c].sales_btax=l.combos[c].sales_btax-n[p].combos[c].price*n[p].combos[c].quantity*n[p].quantity,l.combos[c].sales_atax=l.combos[c].sales_atax-n[p].combos[c].price*n[p].combos[c].quantity*n[p].quantity*(1+n[p].tax/100))}else if(12===o)if(1===n[p].ptype||2===n[p].ptype)_[i]._id===n[p].id_product&&(a=!0,l.quantity=l.quantity-n[p].quantity,l.sales_btax=l.sales_btax-n[p].price*n[p].quantity,l.sales_atax=l.sales_atax-n[p].price*n[p].quantity*(1+n[p].tax/100));else if(5===n[p].ptype)for(b=0;b<n[p].combos.length;b++)_[i]._id===n[p].combos[b].id_product&&(a=!0,l.quantity=l.quantity-n[p].combos[b].quantity*n[p].quantity,l.sales_btax=l.sales_btax-n[p].combos[b].price*n[p].combos[b].quantity*n[p].quantity,l.sales_atax=l.sales_atax-n[p].combos[b].price*n[p].combos[b].quantity*n[p].quantity*(1+n[p].tax/100))}else if(1===o||2===o){if(1===n[p].ptype||2===n[p].ptype)_[i]._id===n[p].id_product&&(a=!0,l.quantity=l.quantity+n[p].quantity,l.sales_btax=l.sales_btax+n[p].price*n[p].quantity,l.sales_atax=l.sales_atax+n[p].price*n[p].quantity*(1+n[p].tax/100));else if(5===n[p].ptype)for(b=0;b<n[p].combos.length;b++)_[i]._id===n[p].combos[b].id_product&&(a=!0,l.quantity=l.quantity+n[p].combos[b].quantity*n[p].quantity,l.sales_btax=l.sales_btax+n[p].combos[b].price*n[p].combos[b].quantity*n[p].quantity,l.sales_atax=l.sales_atax+n[p].combos[b].price*n[p].combos[b].quantity*n[p].quantity*(1+n[p].tax/100))}else if(5===o){if(5===n[p].ptype&&_[i]._id===n[p].id_product&&(a=!0,l.quantity=l.quantity+n[p].quantity,l.sales_btax=l.sales_btax+n[p].price*n[p].quantity,l.sales_atax=l.sales_atax+n[p].price*n[p].quantity*(1+n[p].tax/100),null!=l.combos))for(c=0;c<l.combos.length;c++)_[i].combos[c].id_product===n[p].combos[c].id_product&&(l.combos[c].quantity=l.combos[c].quantity+n[p].combos[c].quantity*n[p].quantity,l.combos[c].sales_btax=l.combos[c].sales_btax+n[p].combos[c].price*n[p].combos[c].quantity*n[p].quantity,l.combos[c].sales_atax=l.combos[c].sales_atax+n[p].combos[c].price*n[p].combos[c].quantity*n[p].quantity*(1+n[p].tax/100))}else if(12===o)if(1===n[p].ptype||2===n[p].ptype)_[i]._id===n[p].id_product&&(a=!0,l.quantity=l.quantity+n[p].quantity,l.sales_btax=l.sales_btax+n[p].price*n[p].quantity,l.sales_atax=l.sales_atax+n[p].price*n[p].quantity*(1+n[p].tax/100));else if(5===n[p].ptype)for(b=0;b<n[p].combos.length;b++)_[i]._id===n[p].combos[b].id_product&&(a=!0,l.quantity=l.quantity+n[p].combos[b].quantity*n[p].quantity,l.sales_btax=l.sales_btax+n[p].combos[b].price*n[p].combos[b].quantity*n[p].quantity,l.sales_atax=l.sales_atax+n[p].combos[b].price*n[p].combos[b].quantity*n[p].quantity*(1+n[p].tax/100));a&&(l.sales_atax=Math.round(1e6*l.sales_atax)/1e6,null!=l.subs&&l.subs.forEach((function(t){t.sales_atax=Math.round(1e6*t.sales_atax)/1e6})),null!=l.combos&&l.combos.forEach((function(t){t.sales_atax=Math.round(1e6*t.sales_atax)/1e6})),u.quantity=u.quantity+l.quantity,u.sales_btax=u.sales_btax+l.sales_btax,u.sales_atax=u.sales_atax+l.sales_atax,l.index=u.size+1,u.docs.push(l),u.size++,u.empty=!1)}console.log("jsons",u),s(u)})):s(u)}))},t.prototype.getReportSales_Products_byProduct=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0},l=i.getlocalProduct(n),c=new Array;i.getlocalProductAndCombos(n).forEach((function(t){c.push(t._id)}));for(var u,d=l.type,_=new Array,p=[1,3,15],b=0;b<p.length;b++)u="all"===o||void 0===o?{date:{$gte:t,$lte:e},id_product:{$in:c},bill_type:{$eq:p[b]}}:{date:{$gte:t,$lte:e},id_product:{$in:c},bill_type:{$eq:p[b]},id_branch:{$eq:o}},_[b]=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0);Promise.all(_).then((function(t){var e,n=t.flat();if(n.length>0)for(var o=0;o<n.length;o++){var s=new Array;if(s[0]={id_product:l._id,name:l.name,unit:l.unit,barcode:l.barcode,img:l.img,bill_code:n[o].bill_code,bill_type:n[o].bill_type,id_bill:n[o].id_bill,date:n[o].date,tax:n[o].tax,salesman:null===(e=i.vhAuth.getlocalEmployee(n[o].id_employee))||void 0===e?void 0:e.name,customer:i.getlocalCustomer(n[o].id_customer).name},3==n[o].bill_type)if(1===d||2===d)if(null!=n[o].combos)for(var c=0;c<n[o].combos.length;c++)n[o].combos[c].id_product===l._id&&(s[0].quantity=-n[o].combos[c].quantity*n[o].quantity,s[0].price=n[o].combos[c].price);else s[0].quantity=-n[o].quantity,s[0].price=n[o].price;else 5===d&&(s[0].quantity=-n[o].quantity,s[0].price=n[o].price);else if(1===d||2===d)if(null!=n[o].combos)for(c=0;c<n[o].combos.length;c++)n[o].combos[c].id_product===l._id&&(s[0].quantity=n[o].combos[c].quantity*n[o].quantity,s[0].price=n[o].combos[c].price);else s[0].quantity=n[o].quantity,s[0].price=n[o].price;else 5===d&&(s[0].quantity=n[o].quantity,s[0].price=n[o].price);s.forEach((function(t){t.sales_btax=t.price*t.quantity,t.sales_atax=t.price*t.quantity*(1+t.tax/100),t.index=r.size+1,r.docs.push(t),r.size++,r.empty=!1,r.quantity=r.quantity+t.quantity,r.sales_btax=r.sales_btax+t.price*t.quantity,r.sales_atax=r.sales_atax+t.price*t.quantity*(1+Number(t.tax)/100)}))}console.log("json",r),a(r)}))}))},t.prototype.getDiscount_bill_byCustomer=function(t,e){for(var n=this.getlocalCustomer(e),o=this.getlocalDiscount_bills(),i=this.getlocalCustomerClasss(),a=null,s=0;s<i.length;s++)if(i[s]._id===n.id_customer_class&&null!=i[s].id_discount_bill&&null!=i[s].id_discount_bill)for(var r=0;r<o.length;r++)if(o[r]._id===i[s].id_discount_bill){a={discount:0},1===o[r].method?(0!=o[r].level5.sales||0!=o[r].level5.discount)&&t>=o[r].level5.sales?1===o[r].type?(a.discount=a.discount+(o[r].level2.sales-o[r].level1.sales)*o[r].level1.discount/100,a.discount=a.discount+(o[r].level3.sales-o[r].level2.sales)*o[r].level2.discount/100,a.discount=a.discount+(o[r].level4.sales-o[r].level3.sales)*o[r].level3.discount/100,a.discount=a.discount+(o[r].level5.sales-o[r].level4.sales)*o[r].level4.discount/100,a.discount=a.discount+(t-o[r].level5.sales)*o[r].level5.discount/100):2===o[r].type&&(a.discount=o[r].level1.discount,a.discount=a.discount+o[r].level2.discount,a.discount=a.discount+o[r].level3.discount,a.discount=a.discount+o[r].level4.discount,a.discount=a.discount+o[r].level5.discount):(0!=o[r].level4.sales||0!=o[r].level4.discount)&&t>=o[r].level4.sales?1===o[r].type?(a.discount=a.discount+(o[r].level2.sales-o[r].level1.sales)*o[r].level1.discount/100,a.discount=a.discount+(o[r].level3.sales-o[r].level2.sales)*o[r].level2.discount/100,a.discount=a.discount+(o[r].level4.sales-o[r].level3.sales)*o[r].level3.discount/100,a.discount=a.discount+(t-o[r].level4.sales)*o[r].level4.discount/100):2===o[r].type&&(a.discount=o[r].level1.discount,a.discount=a.discount+o[r].level2.discount,a.discount=a.discount+o[r].level3.discount,a.discount=a.discount+o[r].level4.discount):(0!=o[r].level3.sales||0!=o[r].level3.discount)&&t>=o[r].level3.sales?1===o[r].type?(a.discount=a.discount+(o[r].level2.sales-o[r].level1.sales)*o[r].level1.discount/100,a.discount=a.discount+(o[r].level3.sales-o[r].level2.sales)*o[r].level2.discount/100,a.discount=a.discount+(t-o[r].level3.sales)*o[r].level3.discount/100):2===o[r].type&&(a.discount=o[r].level1.discount,a.discount=a.discount+o[r].level2.discount,a.discount=a.discount+o[r].level3.discount):(0!=o[r].level2.sales||0!=o[r].level2.discount)&&t>=o[r].level2.sales?1===o[r].type?(a.discount=a.discount+(o[r].level2.sales-o[r].level1.sales)*o[r].level1.discount/100,a.discount=a.discount+(t-o[r].level2.sales)*o[r].level2.discount/100):2===o[r].type&&(a.discount=o[r].level1.discount,a.discount=a.discount+o[r].level2.discount):(0!=o[r].level1.sales||0!=o[r].level1.discount)&&t>=o[r].level1.sales&&(1===o[r].type?a.discount=a.discount+(t-o[r].level1.sales)*o[r].level1.discount/100:2===o[r].type&&(a.discount=o[r].level1.discount)):2===o[r].method&&((0!=o[r].level5.sales||0!=o[r].level5.discount)&&t>=o[r].level5.sales?1===o[r].type?a.discount=t*o[r].level5.discount/100:2===o[r].type&&(a.discount=o[r].level5.discount):(0!=o[r].level4.sales||0!=o[r].level4.discount)&&t>=o[r].level4.sales?1===o[r].type?a.discount=t*o[r].level4.discount/100:2===o[r].type&&(a.discount=o[r].level4.discount):(0!=o[r].level3.sales||0!=o[r].level3.discount)&&t>=o[r].level3.sales?1===o[r].type?a.discount=t*o[r].level3.discount/100:2===o[r].type&&(a.discount=o[r].level3.discount):(0!=o[r].level2.sales||0!=o[r].level2.discount)&&t>=o[r].level2.sales?1===o[r].type?a.discount=t*o[r].level2.discount/100:2===o[r].type&&(a.discount=o[r].level2.discount):(0!=o[r].level1.sales||0!=o[r].level1.discount)&&t>=o[r].level1.sales&&(1===o[r].type?a.discount=t*o[r].level1.discount/100:2===o[r].type&&(a.discount=o[r].level1.discount)));break}return a},t.prototype.getReportDiscount_sales_Customers=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Array;if("all"===n)r=i.getlocalCustomers();else{var l=i.getlocalCustomer(n);r.push(l)}var c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,discount_btax:0,discount_atax:0};if(r.length>0){var u=void 0;u="all"===n?"all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1,3,15]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1,3,15]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$gte:t,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1,3,15]}}:{date:{$gte:t,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1,3,15]},id_branch:{$eq:o}};var d=i.vhmongo_firebase.database().getDocsByFields("discount_saless",{},{},{},0),_=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0),p=i.vhmongo_firebase.database().getDocsByFields("customer_classs",{},{},{},0);Promise.all([d,_,p]).then((function(t){var e,n=t[0],o=t[1],i=t[2];if(o.length>0)for(var s=0;s<r.length;s++){for(var l=!1,u={id_customer:r[s]._id,name:r[s].name,img:null===(e=r[s])||void 0===e?void 0:e.img,sales_btax:0,sales_atax:0,quantity:0,discount_btax:0,discount_atax:0,discount_name:""},d=0;d<o.length;d++)if(r[s]._id===o[d].id_customer)if(l=!0,3==o[d].bill_type)if(5===o[d].ptype){if(null!=o[d].combos)for(var _=0;_<o[d].combos.length;_++)u.quantity=u.quantity-o[d].combos[_].quantity*o[d].quantity,u.sales_btax=u.sales_btax-o[d].combos[_].price*o[d].combos[_].quantity*o[d].quantity,u.sales_atax=u.sales_atax-o[d].combos[_].price*o[d].combos[_].quantity*o[d].quantity*(1+o[d].tax/100)}else u.quantity=u.quantity-o[d].quantity,u.sales_btax=u.sales_btax-o[d].price*o[d].quantity,u.sales_atax=u.sales_atax-o[d].price*o[d].quantity*(1+o[d].tax/100);else if(5===o[d].ptype){if(null!=o[d].combos)for(_=0;_<o[d].combos.length;_++)u.quantity=u.quantity+o[d].combos[_].quantity*o[d].quantity,u.sales_btax=u.sales_btax+o[d].combos[_].price*o[d].combos[_].quantity*o[d].quantity,u.sales_atax=u.sales_atax+o[d].combos[_].price*o[d].combos[_].quantity*o[d].quantity*(1+o[d].tax/100)}else u.quantity=u.quantity+o[d].quantity,u.sales_btax=u.sales_btax+o[d].price*o[d].quantity,u.sales_atax=u.sales_atax+o[d].price*o[d].quantity*(1+o[d].tax/100);if(l&&null!=r[s].id_customer_class&&null!=r[s].id_customer_class)for(d=0;d<i.length;d++)if(i[d]._id===r[s].id_customer_class&&null!=i[d].id_discount_sales&&null!=i[d].id_discount_sales)for(var p=0;p<n.length;p++)if(n[p]._id===i[d].id_discount_sales){u.discount_name=n[p].name,1===n[p].method?(0!=n[p].level5.sales||0!=n[p].level5.discount)&&u.sales_btax>=n[p].level5.sales?1===n[p].type?(u.discount_btax=u.discount_btax+(n[p].level2.sales-n[p].level1.sales)*n[p].level1.discount/100,u.discount_btax=u.discount_btax+(n[p].level3.sales-n[p].level2.sales)*n[p].level2.discount/100,u.discount_btax=u.discount_btax+(n[p].level4.sales-n[p].level3.sales)*n[p].level3.discount/100,u.discount_btax=u.discount_btax+(n[p].level5.sales-n[p].level4.sales)*n[p].level4.discount/100,u.discount_btax=u.discount_btax+(u.sales_btax-n[p].level5.sales)*n[p].level5.discount/100):2===n[p].type&&(u.discount_btax=n[p].level1.discount,u.discount_btax=u.discount_btax+n[p].level2.discount,u.discount_btax=u.discount_btax+n[p].level3.discount,u.discount_btax=u.discount_btax+n[p].level4.discount,u.discount_btax=u.discount_btax+n[p].level5.discount):(0!=n[p].level4.sales||0!=n[p].level4.discount)&&u.sales_btax>=n[p].level4.sales?1===n[p].type?(u.discount_btax=u.discount_btax+(n[p].level2.sales-n[p].level1.sales)*n[p].level1.discount/100,u.discount_btax=u.discount_btax+(n[p].level3.sales-n[p].level2.sales)*n[p].level2.discount/100,u.discount_btax=u.discount_btax+(n[p].level4.sales-n[p].level3.sales)*n[p].level3.discount/100,u.discount_btax=u.discount_btax+(u.sales_btax-n[p].level4.sales)*n[p].level4.discount/100):2===n[p].type&&(u.discount_btax=n[p].level1.discount,u.discount_btax=u.discount_btax+n[p].level2.discount,u.discount_btax=u.discount_btax+n[p].level3.discount,u.discount_btax=u.discount_btax+n[p].level4.discount):(0!=n[p].level3.sales||0!=n[p].level3.discount)&&u.sales_btax>=n[p].level3.sales?1===n[p].type?(u.discount_btax=u.discount_btax+(n[p].level2.sales-n[p].level1.sales)*n[p].level1.discount/100,u.discount_btax=u.discount_btax+(n[p].level3.sales-n[p].level2.sales)*n[p].level2.discount/100,u.discount_btax=u.discount_btax+(u.sales_btax-n[p].level3.sales)*n[p].level3.discount/100):2===n[p].type&&(u.discount_btax=n[p].level1.discount,u.discount_btax=u.discount_btax+n[p].level2.discount,u.discount_btax=u.discount_btax+n[p].level3.discount):(0!=n[p].level2.sales||0!=n[p].level2.discount)&&u.sales_btax>=n[p].level2.sales?1===n[p].type?(u.discount_btax=u.discount_btax+(n[p].level2.sales-n[p].level1.sales)*n[p].level1.discount/100,u.discount_btax=u.discount_btax+(u.sales_btax-n[p].level2.sales)*n[p].level2.discount/100):2===n[p].type&&(u.discount_btax=n[p].level1.discount,u.discount_btax=u.discount_btax+n[p].level2.discount):(0!=n[p].level1.sales||0!=n[p].level1.discount)&&u.sales_btax>=n[p].level1.sales&&(1===n[p].type?u.discount_btax=u.discount_btax+(u.sales_btax-n[p].level1.sales)*n[p].level1.discount/100:2===n[p].type&&(u.discount_btax=n[p].level1.discount)):2===n[p].method&&((0!=n[p].level5.sales||0!=n[p].level5.discount)&&u.sales_btax>=n[p].level5.sales?1===n[p].type?u.discount_btax=u.sales_btax*n[p].level5.discount/100:2===n[p].type&&(u.discount_btax=n[p].level5.discount):(0!=n[p].level4.sales||0!=n[p].level4.discount)&&u.sales_btax>=n[p].level4.sales?1===n[p].type?u.discount_btax=u.sales_btax*n[p].level4.discount/100:2===n[p].type&&(u.discount_btax=n[p].level4.discount):(0!=n[p].level3.sales||0!=n[p].level3.discount)&&u.sales_btax>=n[p].level3.sales?1===n[p].type?u.discount_btax=u.sales_btax*n[p].level3.discount/100:2===n[p].type&&(u.discount_btax=n[p].level3.discount):(0!=n[p].level2.sales||0!=n[p].level2.discount)&&u.sales_btax>=n[p].level2.sales?1===n[p].type?u.discount_btax=u.sales_btax*n[p].level2.discount/100:2===n[p].type&&(u.discount_btax=n[p].level2.discount):(0!=n[p].level1.sales||0!=n[p].level1.discount)&&u.sales_btax>=n[p].level1.sales&&(1===n[p].type?u.discount_btax=u.sales_btax*n[p].level1.discount/100:2===n[p].type&&(u.discount_btax=n[p].level1.discount))),1===n[p].method?(0!=n[p].level5.sales||0!=n[p].level5.discount)&&u.sales_atax>=n[p].level5.sales?1===n[p].type?(u.discount_atax=u.discount_atax+(n[p].level2.sales-n[p].level1.sales)*n[p].level1.discount/100,u.discount_atax=u.discount_atax+(n[p].level3.sales-n[p].level2.sales)*n[p].level2.discount/100,u.discount_atax=u.discount_atax+(n[p].level4.sales-n[p].level3.sales)*n[p].level3.discount/100,u.discount_atax=u.discount_atax+(n[p].level5.sales-n[p].level4.sales)*n[p].level4.discount/100,u.discount_atax=u.discount_atax+(u.sales_atax-n[p].level5.sales)*n[p].level5.discount/100):2===n[p].type&&(u.discount_atax=n[p].level1.discount,u.discount_atax=u.discount_atax+n[p].level2.discount,u.discount_atax=u.discount_atax+n[p].level3.discount,u.discount_atax=u.discount_atax+n[p].level4.discount,u.discount_atax=u.discount_atax+n[p].level5.discount):(0!=n[p].level4.sales||0!=n[p].level4.discount)&&u.sales_atax>=n[p].level4.sales?1===n[p].type?(u.discount_atax=u.discount_atax+(n[p].level2.sales-n[p].level1.sales)*n[p].level1.discount/100,u.discount_atax=u.discount_atax+(n[p].level3.sales-n[p].level2.sales)*n[p].level2.discount/100,u.discount_atax=u.discount_atax+(n[p].level4.sales-n[p].level3.sales)*n[p].level3.discount/100,u.discount_atax=u.discount_atax+(u.sales_atax-n[p].level4.sales)*n[p].level4.discount/100):2===n[p].type&&(u.discount_atax=n[p].level1.discount,u.discount_atax=u.discount_atax+n[p].level2.discount,u.discount_atax=u.discount_atax+n[p].level3.discount,u.discount_atax=u.discount_atax+n[p].level4.discount):(0!=n[p].level3.sales||0!=n[p].level3.discount)&&u.sales_atax>=n[p].level3.sales?1===n[p].type?(u.discount_atax=u.discount_atax+(n[p].level2.sales-n[p].level1.sales)*n[p].level1.discount/100,u.discount_atax=u.discount_atax+(n[p].level3.sales-n[p].level2.sales)*n[p].level2.discount/100,u.discount_atax=u.discount_atax+(u.sales_atax-n[p].level3.sales)*n[p].level3.discount/100):2===n[p].type&&(u.discount_atax=n[p].level1.discount,u.discount_atax=u.discount_atax+n[p].level2.discount,u.discount_atax=u.discount_atax+n[p].level3.discount):(0!=n[p].level2.sales||0!=n[p].level2.discount)&&u.sales_atax>=n[p].level2.sales?1===n[p].type?(u.discount_atax=u.discount_atax+(n[p].level2.sales-n[p].level1.sales)*n[p].level1.discount/100,u.discount_atax=u.discount_atax+(u.sales_atax-n[p].level2.sales)*n[p].level2.discount/100):2===n[p].type&&(u.discount_atax=n[p].level1.discount,u.discount_atax=u.discount_atax+n[p].level2.discount):(0!=n[p].level1.sales||0!=n[p].level1.discount)&&u.sales_atax>=n[p].level1.sales&&(1===n[p].type?u.discount_atax=u.discount_atax+(u.sales_atax-n[p].level1.sales)*n[p].level1.discount/100:2===n[p].type&&(u.discount_atax=n[p].level1.discount)):2===n[p].method&&((0!=n[p].level5.sales||0!=n[p].level5.discount)&&u.sales_atax>=n[p].level5.sales?1===n[p].type?u.discount_atax=u.sales_atax*n[p].level5.discount/100:2===n[p].type&&(u.discount_atax=n[p].level5.discount):(0!=n[p].level4.sales||0!=n[p].level4.discount)&&u.sales_atax>=n[p].level4.sales?1===n[p].type?u.discount_atax=u.sales_atax*n[p].level4.discount/100:2===n[p].type&&(u.discount_atax=n[p].level4.discount):(0!=n[p].level3.sales||0!=n[p].level3.discount)&&u.sales_atax>=n[p].level3.sales?1===n[p].type?u.discount_atax=u.sales_atax*n[p].level3.discount/100:2===n[p].type&&(u.discount_atax=n[p].level3.discount):(0!=n[p].level2.sales||0!=n[p].level2.discount)&&u.sales_atax>=n[p].level2.sales?1===n[p].type?u.discount_atax=u.sales_atax*n[p].level2.discount/100:2===n[p].type&&(u.discount_atax=n[p].level2.discount):(0!=n[p].level1.sales||0!=n[p].level1.discount)&&u.sales_atax>=n[p].level1.sales&&(1===n[p].type?u.discount_atax=u.sales_atax*n[p].level1.discount/100:2===n[p].type&&(u.discount_atax=n[p].level1.discount))),c.sales_btax=c.sales_btax+u.sales_btax,c.sales_atax=c.sales_atax+u.sales_atax,c.discount_btax=c.discount_btax+u.discount_btax,c.discount_atax=c.discount_atax+u.discount_atax,u.index=c.size+1,c.docs.push(u),c.size++,c.empty=!1;break}}console.log("getReportDiscount_Customers",c),a(c)}))}else a(c)}))},t.prototype.getReportCommission_Employees=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Array;if("all"===n)r=i.vhAuth.getlocalEmployees();else{var l=i.vhAuth.getlocalEmployee(n);r.push(l)}var c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,commission_btax:0,commission_atax:0};if(r.length>0){var u=void 0;u="all"===n?"all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1,3,15]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1,3,15]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$gte:t,$lte:e},id_employee:{$eq:n},bill_type:{$in:[1,3,15]}}:{date:{$gte:t,$lte:e},id_employee:{$eq:n},bill_type:{$in:[1,3,15]},id_branch:{$eq:o}};var d=i.vhmongo_firebase.database().getDocsByFields("commissions",{},{},{},0),_=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0),p=i.vhmongo_firebase.database().getDocsByFields("employee_classs",{},{},{},0);Promise.all([d,_,p]).then((function(t){var e=t[0],n=t[1],o=t[2];if(n.length>0)for(var i=0;i<r.length;i++){for(var s=!1,l={id_employee:r[i]._id,name:r[i].name,sales_btax:0,sales_atax:0,quantity:0,commission_btax:0,commission_atax:0,commission_name:""},u=0;u<n.length;u++)if(r[i]._id===n[u].id_employee)if(s=!0,3==n[u].bill_type)if(5===n[u].ptype){if(null!=n[u].combos)for(var d=0;d<n[u].combos.length;d++)l.quantity=l.quantity-n[u].combos[d].quantity*n[u].quantity,l.sales_btax=l.sales_btax-n[u].combos[d].price*n[u].combos[d].quantity*n[u].quantity,l.sales_atax=l.sales_atax-n[u].combos[d].price*n[u].combos[d].quantity*n[u].quantity*(1+n[u].tax/100)}else l.quantity=l.quantity-n[u].quantity,l.sales_btax=l.sales_btax-n[u].price*n[u].quantity,l.sales_atax=l.sales_atax-n[u].price*n[u].quantity*(1+n[u].tax/100);else if(5===n[u].ptype){if(null!=n[u].combos)for(d=0;d<n[u].combos.length;d++)l.quantity=l.quantity+n[u].combos[d].quantity*n[u].quantity,l.sales_btax=l.sales_btax+n[u].combos[d].price*n[u].combos[d].quantity*n[u].quantity,l.sales_atax=l.sales_atax+n[u].combos[d].price*n[u].combos[d].quantity*n[u].quantity*(1+n[u].tax/100)}else l.quantity=l.quantity+n[u].quantity,l.sales_btax=l.sales_btax+n[u].price*n[u].quantity,l.sales_atax=l.sales_atax+n[u].price*n[u].quantity*(1+n[u].tax/100);if(s&&null!=r[i].id_employee_class&&null!=r[i].id_employee_class)for(u=0;u<o.length;u++)if(o[u]._id===r[i].id_employee_class&&null!=o[u].id_commission&&null!=o[u].id_commission)for(var _=0;_<e.length;_++)if(e[_]._id===o[u].id_commission){l.commission_name=e[_].name,1===e[_].method?(0!=e[_].level5.sales||0!=e[_].level5.commission)&&l.sales_btax>=e[_].level5.sales?1===e[_].type?(l.commission_btax=l.commission_btax+(e[_].level2.sales-e[_].level1.sales)*e[_].level1.commission/100,l.commission_btax=l.commission_btax+(e[_].level3.sales-e[_].level2.sales)*e[_].level2.commission/100,l.commission_btax=l.commission_btax+(e[_].level4.sales-e[_].level3.sales)*e[_].level3.commission/100,l.commission_btax=l.commission_btax+(e[_].level5.sales-e[_].level4.sales)*e[_].level4.commission/100,l.commission_btax=l.commission_btax+(l.sales_btax-e[_].level5.sales)*e[_].level5.commission/100):2===e[_].type&&(l.commission_btax=e[_].level1.commission,l.commission_btax=l.commission_btax+e[_].level2.commission,l.commission_btax=l.commission_btax+e[_].level3.commission,l.commission_btax=l.commission_btax+e[_].level4.commission,l.commission_btax=l.commission_btax+e[_].level5.commission):(0!=e[_].level4.sales||0!=e[_].level4.commission)&&l.sales_btax>=e[_].level4.sales?1===e[_].type?(l.commission_btax=l.commission_btax+(e[_].level2.sales-e[_].level1.sales)*e[_].level1.commission/100,l.commission_btax=l.commission_btax+(e[_].level3.sales-e[_].level2.sales)*e[_].level2.commission/100,l.commission_btax=l.commission_btax+(e[_].level4.sales-e[_].level3.sales)*e[_].level3.commission/100,l.commission_btax=l.commission_btax+(l.sales_btax-e[_].level4.sales)*e[_].level4.commission/100):2===e[_].type&&(l.commission_btax=e[_].level1.commission,l.commission_btax=l.commission_btax+e[_].level2.commission,l.commission_btax=l.commission_btax+e[_].level3.commission,l.commission_btax=l.commission_btax+e[_].level4.commission):(0!=e[_].level3.sales||0!=e[_].level3.commission)&&l.sales_btax>=e[_].level3.sales?1===e[_].type?(l.commission_btax=l.commission_btax+(e[_].level2.sales-e[_].level1.sales)*e[_].level1.commission/100,l.commission_btax=l.commission_btax+(e[_].level3.sales-e[_].level2.sales)*e[_].level2.commission/100,l.commission_btax=l.commission_btax+(l.sales_btax-e[_].level3.sales)*e[_].level3.commission/100):2===e[_].type&&(l.commission_btax=e[_].level1.commission,l.commission_btax=l.commission_btax+e[_].level2.commission,l.commission_btax=l.commission_btax+e[_].level3.commission):(0!=e[_].level2.sales||0!=e[_].level2.commission)&&l.sales_btax>=e[_].level2.sales?1===e[_].type?(l.commission_btax=l.commission_btax+(e[_].level2.sales-e[_].level1.sales)*e[_].level1.commission/100,l.commission_btax=l.commission_btax+(l.sales_btax-e[_].level2.sales)*e[_].level2.commission/100):2===e[_].type&&(l.commission_btax=e[_].level1.commission,l.commission_btax=l.commission_btax+e[_].level2.commission):(0!=e[_].level1.sales||0!=e[_].level1.commission)&&l.sales_btax>=e[_].level1.sales&&(1===e[_].type?l.commission_btax=l.commission_btax+(l.sales_btax-e[_].level1.sales)*e[_].level1.commission/100:2===e[_].type&&(l.commission_btax=e[_].level1.commission)):2===e[_].method&&((0!=e[_].level5.sales||0!=e[_].level5.commission)&&l.sales_btax>=e[_].level5.sales?1===e[_].type?l.commission_btax=l.sales_btax*e[_].level5.commission/100:2===e[_].type&&(l.commission_btax=e[_].level5.commission):(0!=e[_].level4.sales||0!=e[_].level4.commission)&&l.sales_btax>=e[_].level4.sales?1===e[_].type?l.commission_btax=l.sales_btax*e[_].level4.commission/100:2===e[_].type&&(l.commission_btax=e[_].level4.commission):(0!=e[_].level3.sales||0!=e[_].level3.commission)&&l.sales_btax>=e[_].level3.sales?1===e[_].type?l.commission_btax=l.sales_btax*e[_].level3.commission/100:2===e[_].type&&(l.commission_btax=e[_].level3.commission):(0!=e[_].level2.sales||0!=e[_].level2.commission)&&l.sales_btax>=e[_].level2.sales?1===e[_].type?l.commission_btax=l.sales_btax*e[_].level2.commission/100:2===e[_].type&&(l.commission_btax=e[_].level2.commission):(0!=e[_].level1.sales||0!=e[_].level1.commission)&&l.sales_btax>=e[_].level1.sales&&(1===e[_].type?l.commission_btax=l.sales_btax*e[_].level1.commission/100:2===e[_].type&&(l.commission_btax=e[_].level1.commission))),1===e[_].method?(0!=e[_].level5.sales||0!=e[_].level5.commission)&&l.sales_atax>=e[_].level5.sales?1===e[_].type?(l.commission_atax=l.commission_atax+(e[_].level2.sales-e[_].level1.sales)*e[_].level1.commission/100,l.commission_atax=l.commission_atax+(e[_].level3.sales-e[_].level2.sales)*e[_].level2.commission/100,l.commission_atax=l.commission_atax+(e[_].level4.sales-e[_].level3.sales)*e[_].level3.commission/100,l.commission_atax=l.commission_atax+(e[_].level5.sales-e[_].level4.sales)*e[_].level4.commission/100,l.commission_atax=l.commission_atax+(l.sales_atax-e[_].level5.sales)*e[_].level5.commission/100):2===e[_].type&&(l.commission_atax=e[_].level1.commission,l.commission_atax=l.commission_atax+e[_].level2.commission,l.commission_atax=l.commission_atax+e[_].level3.commission,l.commission_atax=l.commission_atax+e[_].level4.commission,l.commission_atax=l.commission_atax+e[_].level5.commission):(0!=e[_].level4.sales||0!=e[_].level4.commission)&&l.sales_atax>=e[_].level4.sales?1===e[_].type?(l.commission_atax=l.commission_atax+(e[_].level2.sales-e[_].level1.sales)*e[_].level1.commission/100,l.commission_atax=l.commission_atax+(e[_].level3.sales-e[_].level2.sales)*e[_].level2.commission/100,l.commission_atax=l.commission_atax+(e[_].level4.sales-e[_].level3.sales)*e[_].level3.commission/100,l.commission_atax=l.commission_atax+(l.sales_atax-e[_].level4.sales)*e[_].level4.commission/100):2===e[_].type&&(l.commission_atax=e[_].level1.commission,l.commission_atax=l.commission_atax+e[_].level2.commission,l.commission_atax=l.commission_atax+e[_].level3.commission,l.commission_atax=l.commission_atax+e[_].level4.commission):(0!=e[_].level3.sales||0!=e[_].level3.commission)&&l.sales_atax>=e[_].level3.sales?1===e[_].type?(l.commission_atax=l.commission_atax+(e[_].level2.sales-e[_].level1.sales)*e[_].level1.commission/100,l.commission_atax=l.commission_atax+(e[_].level3.sales-e[_].level2.sales)*e[_].level2.commission/100,l.commission_atax=l.commission_atax+(l.sales_atax-e[_].level3.sales)*e[_].level3.commission/100):2===e[_].type&&(l.commission_atax=e[_].level1.commission,l.commission_atax=l.commission_atax+e[_].level2.commission,l.commission_atax=l.commission_atax+e[_].level3.commission):(0!=e[_].level2.sales||0!=e[_].level2.commission)&&l.sales_atax>=e[_].level2.sales?1===e[_].type?(l.commission_atax=l.commission_atax+(e[_].level2.sales-e[_].level1.sales)*e[_].level1.commission/100,l.commission_atax=l.commission_atax+(l.sales_atax-e[_].level2.sales)*e[_].level2.commission/100):2===e[_].type&&(l.commission_atax=e[_].level1.commission,l.commission_atax=l.commission_atax+e[_].level2.commission):(0!=e[_].level1.sales||0!=e[_].level1.commission)&&l.sales_atax>=e[_].level1.sales&&(1===e[_].type?l.commission_atax=l.commission_atax+(l.sales_atax-e[_].level1.sales)*e[_].level1.commission/100:2===e[_].type&&(l.commission_atax=e[_].level1.commission)):2===e[_].method&&((0!=e[_].level5.sales||0!=e[_].level5.commission)&&l.sales_atax>=e[_].level5.sales?1===e[_].type?l.commission_atax=l.sales_atax*e[_].level5.commission/100:2===e[_].type&&(l.commission_atax=e[_].level5.commission):(0!=e[_].level4.sales||0!=e[_].level4.commission)&&l.sales_atax>=e[_].level4.sales?1===e[_].type?l.commission_atax=l.sales_atax*e[_].level4.commission/100:2===e[_].type&&(l.commission_atax=e[_].level4.commission):(0!=e[_].level3.sales||0!=e[_].level3.commission)&&l.sales_atax>=e[_].level3.sales?1===e[_].type?l.commission_atax=l.sales_atax*e[_].level3.commission/100:2===e[_].type&&(l.commission_atax=e[_].level3.commission):(0!=e[_].level2.sales||0!=e[_].level2.commission)&&l.sales_atax>=e[_].level2.sales?1===e[_].type?l.commission_atax=l.sales_atax*e[_].level2.commission/100:2===e[_].type&&(l.commission_atax=e[_].level2.commission):(0!=e[_].level1.sales||0!=e[_].level1.commission)&&l.sales_atax>=e[_].level1.sales&&(1===e[_].type?l.commission_atax=l.sales_atax*e[_].level1.commission/100:2===e[_].type&&(l.commission_atax=e[_].level1.commission))),c.sales_btax=c.sales_btax+l.sales_btax,c.sales_atax=c.sales_atax+l.sales_atax,c.commission_btax=c.commission_btax+l.commission_btax,c.commission_atax=c.commission_atax+l.commission_atax,l.index=c.size+1,c.docs.push(l),c.size++,c.empty=!1;break}}console.log("getReportCommission_Employees",c),a(c)}))}else a(c)}))},t.prototype.getReportSales_Customers_byCustomers=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Array;if("all"===n)r=i.getlocalCustomers();else{var l=i.getlocalCustomer(n);r.push(l)}var c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};if(r.length>0){var u=void 0;u="all"===n?"all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1,3,15]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1,3,15]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$gte:t,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1,3,15]}}:{date:{$gte:t,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1,3,15]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0).then((function(t){var e;if(t.length>0)for(var n=0;n<r.length;n++){for(var o=!1,i={id_customer:r[n]._id,name:r[n].name,img:null===(e=r[n])||void 0===e?void 0:e.img,sales_btax:0,sales_atax:0,quantity:0},s=0;s<t.length;s++)if(r[n]._id===t[s].id_customer)if(o=!0,3==t[s].bill_type)if(5===t[s].ptype){if(null!=t[s].combos)for(var l=0;l<t[s].combos.length;l++)i.quantity=i.quantity-t[s].combos[l].quantity*t[s].quantity,i.sales_btax=i.sales_btax-t[s].combos[l].price*t[s].combos[l].quantity*t[s].quantity,i.sales_atax=i.sales_atax-t[s].combos[l].price*t[s].combos[l].quantity*t[s].quantity*(1+t[s].tax/100)}else i.quantity=i.quantity-t[s].quantity,i.sales_btax=i.sales_btax-t[s].price*t[s].quantity,i.sales_atax=i.sales_atax-t[s].price*t[s].quantity*(1+t[s].tax/100);else if(5===t[s].ptype){if(null!=t[s].combos)for(l=0;l<t[s].combos.length;l++)i.quantity=i.quantity+t[s].combos[l].quantity*t[s].quantity,i.sales_btax=i.sales_btax+t[s].combos[l].price*t[s].combos[l].quantity*t[s].quantity,i.sales_atax=i.sales_atax+t[s].combos[l].price*t[s].combos[l].quantity*t[s].quantity*(1+t[s].tax/100)}else i.quantity=i.quantity+t[s].quantity,i.sales_btax=i.sales_btax+t[s].price*t[s].quantity,i.sales_atax=i.sales_atax+t[s].price*t[s].quantity*(1+t[s].tax/100);o&&(c.quantity=c.quantity+i.quantity,c.sales_btax=c.sales_btax+i.sales_btax,c.sales_atax=c.sales_atax+i.sales_atax,i.index=c.size+1,c.docs.push(i),c.size++,c.empty=!1)}console.log("getReportSales_Customers_byCustomers"),a(c)}))}else a(c)}))},t.prototype.getReportSales_Customers_byProducts=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l=i.getlocalProducts(12);r=r="all"===o||void 0===o?{date:{$gte:t,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1,3,15]}}:{date:{$gte:t,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1,3,15]},id_branch:{$eq:o}};var c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};l.length>0?i.vhmongo_firebase.database().getDocsByFields("vhbill_details",r,{},{date:1},0).then((function(t){if(t.length>0)for(var e=0;e<l.length;e++){for(var o=!1,i=Object.assign({},l[e]),s={id_product:i._id,name:i.name,unit:i.unit,barcode:i.barcode,img:i.img,id_customer:n,sales_btax:0,sales_atax:0,quantity:0},r=0;r<t.length;r++)if(3==t[r].bill_type)if(5===t[r].ptype)for(var u=0;u<t[r].combos.length;u++)l[e]._id===t[r].combos[u].id_product&&(o=!0,s.quantity=s.quantity-t[r].combos[u].quantity*t[r].quantity,s.sales_btax=s.sales_btax-t[r].combos[u].price*t[r].combos[u].quantity*t[r].quantity,s.sales_atax=s.sales_atax-t[r].combos[u].price*t[r].combos[u].quantity*t[r].quantity*(1+t[r].tax/100));else l[e]._id===t[r].id_product&&(o=!0,s.quantity=s.quantity-t[r].quantity,s.sales_btax=s.sales_btax-t[r].price*t[r].quantity,s.sales_atax=s.sales_atax-t[r].price*t[r].quantity*(1+t[r].tax/100));else if(5===t[r].ptype)for(u=0;u<t[r].combos.length;u++)l[e]._id===t[r].combos[u].id_product&&(o=!0,s.quantity=s.quantity+t[r].combos[u].quantity*t[r].quantity,s.sales_btax=s.sales_btax+t[r].combos[u].price*t[r].combos[u].quantity*t[r].quantity,s.sales_atax=s.sales_atax+t[r].combos[u].price*t[r].combos[u].quantity*t[r].quantity*(1+t[r].tax/100));else l[e]._id===t[r].id_product&&(o=!0,s.quantity=s.quantity+t[r].quantity,s.sales_btax=s.sales_btax+t[r].price*t[r].quantity,s.sales_atax=s.sales_atax+t[r].price*t[r].quantity*(1+t[r].tax/100));o&&(s.sales_atax=Math.round(1e6*s.sales_atax)/1e6,c.quantity=c.quantity+s.quantity,c.sales_btax=c.sales_btax+s.sales_btax,c.sales_atax=c.sales_atax+s.sales_atax,s.index=c.size+1,c.docs.push(s),c.size++,c.empty=!1)}console.log("getReportSales_Customers_byProducts"),a(c)})):a(c)}))},t.prototype.getReportSales_Customers_byProducts_Analytics=function(t,e,n,o,i,a){var s=this;return new Promise((function(r,l){var c,u=s.getlocalProducts(15);u=(u=u.filter((function(t){return!0===t.allow_sell}))).filter((function(t){if(null!=t[a]&&!0===t.allow_sell){if("shopee"===i&&null!=t[a].shopees&&null!=t[a].shopees.length)for(var e=0;e<t[a].shopees.length;e++)if(t[a].shopees[e].id_shop===o)return!0;if("tiki"===i&&null!=t[a].tikis&&null!=t[a].tikis.length)for(e=0;e<t[a].tikis.length;e++)if(t[a].tikis[e].id_shop===o)return!0;if("lazada"===i&&null!=t[a].lazadas&&null!=t[a].lazadas.length)for(e=0;e<t[a].lazadas.length;e++)if(t[a].lazadas[e].id_shop===o)return!0;if("sendo"===i&&null!=t[a].sendos&&null!=t[a].sendos.length)for(e=0;e<t[a].sendos.length;e++)if(t[a].sendos[e].id_shop===o)return!0}return!1})),console.log("hello products",u),c=c="all"===a||void 0===a?{date:{$gte:t,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1,3,15]}}:{date:{$gte:t,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1,3,15]},id_branch:{$eq:a}};var d={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};u.length>0?s.vhmongo_firebase.database().getDocsByFields("vhbill_details",c,{},{date:1},0).then((function(t){if(t.length>0)for(var e=0;e<u.length;e++){for(var o=Object.assign({},u[e]),i={id_product:o._id,name:o.name,unit:o.unit,barcode:o.barcode,img:o.img,id_customer:n,sales_btax:0,sales_atax:0,quantity:0},a=0;a<t.length;a++)if(3==t[a].bill_type)if(5===t[a].ptype)for(var s=0;s<t[a].combos.length;s++)u[e]._id===t[a].combos[s].id_product&&(!0,i.quantity=i.quantity-t[a].combos[s].quantity*t[a].quantity,i.sales_btax=i.sales_btax-t[a].combos[s].price*t[a].combos[s].quantity*t[a].quantity,i.sales_atax=i.sales_atax-t[a].combos[s].price*t[a].combos[s].quantity*t[a].quantity*(1+t[a].tax/100));else u[e]._id===t[a].id_product&&(!0,i.quantity=i.quantity-t[a].quantity,i.sales_btax=i.sales_btax-t[a].price*t[a].quantity,i.sales_atax=i.sales_atax-t[a].price*t[a].quantity*(1+t[a].tax/100));else if(5===t[a].ptype)for(s=0;s<t[a].combos.length;s++)u[e]._id===t[a].combos[s].id_product&&(!0,i.quantity=i.quantity+t[a].combos[s].quantity*t[a].quantity,i.sales_btax=i.sales_btax+t[a].combos[s].price*t[a].combos[s].quantity*t[a].quantity,i.sales_atax=i.sales_atax+t[a].combos[s].price*t[a].combos[s].quantity*t[a].quantity*(1+t[a].tax/100));else u[e]._id===t[a].id_product&&(!0,i.quantity=i.quantity+t[a].quantity,i.sales_btax=i.sales_btax+t[a].price*t[a].quantity,i.sales_atax=i.sales_atax+t[a].price*t[a].quantity*(1+t[a].tax/100));i.sales_atax=Math.round(1e6*i.sales_atax)/1e6,d.quantity=d.quantity+i.quantity,d.sales_btax=d.sales_btax+i.sales_btax,d.sales_atax=d.sales_atax+i.sales_atax,i.index=d.size+1,d.docs.push(i),d.size++,d.empty=!1}console.log("getReportSales_Customers_byProducts_Analytics"),r(d)})):r(d)}))},t.prototype.getReportSales_Customers_byProduct=function(t,e,n,o,i){var a=this;return new Promise((function(s,r){var l=a.getlocalProduct(o),c=new Array;a.getlocalProductAndCombos(o).forEach((function(t){c.push(t._id)}));for(var u,d=l.type,_={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0},p=new Array,b=[1,3,15],f=0;f<b.length;f++)u="all"===i||void 0===i?{date:{$gte:t,$lte:e},id_customer:{$eq:n},id_product:{$in:c},bill_type:{$eq:b[f]}}:{date:{$gte:t,$lte:e},id_customer:{$eq:n},id_product:{$in:c},bill_type:{$eq:b[f]},id_branch:{$eq:i}},p[f]=a.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0);Promise.all(p).then((function(t){var e,n=t.flat();if(n.length>0)for(var o=0;o<n.length;o++){var i=new Array;if(i[0]={id_product:l._id,name:l.name,unit:l.unit,barcode:l.barcode,img:l.img,bill_code:n[o].bill_code,bill_type:n[o].bill_type,id_bill:n[o].id_bill,date:n[o].date,tax:n[o].tax,salesman:null===(e=a.vhAuth.getlocalEmployee(n[o].id_employee))||void 0===e?void 0:e.name,customer:a.getlocalCustomer(n[o].id_customer).name},3==n[o].bill_type)if(1===d||2===d)if(null!=n[o].combos)for(var r=0;r<n[o].combos.length;r++)n[o].combos[r].id_product===l._id&&(i[0].quantity=-n[o].combos[r].quantity*n[o].quantity,i[0].price=n[o].combos[r].price);else i[0].quantity=-n[o].quantity,i[0].price=n[o].price;else 5===d&&(i[0].quantity=-n[o].quantity,i[0].price=n[o].price);else if(1===d||2===d)if(null!=n[o].combos)for(r=0;r<n[o].combos.length;r++)n[o].combos[r].id_product===l._id&&(i[0].quantity=n[o].combos[r].quantity*n[o].quantity,i[0].price=n[o].combos[r].price);else i[0].quantity=n[o].quantity,i[0].price=n[o].price;else 5===d&&(i[0].quantity=n[o].quantity,i[0].price=n[o].price);i.forEach((function(t){t.sales_btax=t.price*t.quantity,t.sales_atax=t.price*t.quantity*(1+t.tax/100),t.index=_.size+1,_.docs.push(t),_.size++,_.empty=!1,_.quantity=_.quantity+t.quantity,_.sales_btax=_.sales_btax+t.price*t.quantity,_.sales_atax=_.sales_atax+t.price*t.quantity*(1+Number(t.tax)/100)}))}console.log("getReportSales_Customers_byProduct"),s(_)}))}))},t.prototype.getReportSales_Employees_byEmployees=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Array;if("all"===n)r=i.vhAuth.getlocalEmployees();else{var l=i.vhAuth.getlocalEmployee(n);r.push(l)}var c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};if(r.length>0){var u=void 0;u="all"===n?"all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1,3,15]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1,3,15]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$gte:t,$lte:e},id_employee:{$eq:n},bill_type:{$in:[1,3,15]}}:{date:{$gte:t,$lte:e},id_employee:{$eq:n},bill_type:{$in:[1,3,15]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0).then((function(t){if(t.length>0)for(var e=0;e<r.length;e++){for(var n=!1,o={id_employee:r[e]._id,name:r[e].name,sales_btax:0,sales_atax:0,quantity:0},i=0;i<t.length;i++)if(r[e]._id===t[i].id_employee)if(n=!0,3==t[i].bill_type)if(5===t[i].ptype){if(null!=t[i].combos)for(var s=0;s<t[i].combos.length;s++)o.quantity=o.quantity-t[i].combos[s].quantity*t[i].quantity,o.sales_btax=o.sales_btax-t[i].combos[s].price*t[i].combos[s].quantity*t[i].quantity,o.sales_atax=o.sales_atax-t[i].combos[s].price*t[i].combos[s].quantity*t[i].quantity*(1+t[i].tax/100)}else o.quantity=o.quantity-t[i].quantity,o.sales_btax=o.sales_btax-t[i].price*t[i].quantity,o.sales_atax=o.sales_atax-t[i].price*t[i].quantity*(1+t[i].tax/100);else if(5===t[i].ptype){if(null!=t[i].combos)for(s=0;s<t[i].combos.length;s++)o.quantity=o.quantity+t[i].combos[s].quantity*t[i].quantity,o.sales_btax=o.sales_btax+t[i].combos[s].price*t[i].combos[s].quantity*t[i].quantity,o.sales_atax=o.sales_atax+t[i].combos[s].price*t[i].combos[s].quantity*t[i].quantity*(1+t[i].tax/100)}else o.quantity=o.quantity+t[i].quantity,o.sales_btax=o.sales_btax+t[i].price*t[i].quantity,o.sales_atax=o.sales_atax+t[i].price*t[i].quantity*(1+t[i].tax/100);n&&(c.quantity=c.quantity+o.quantity,c.sales_btax=c.sales_btax+o.sales_btax,c.sales_atax=c.sales_atax+o.sales_atax,o.index=c.size+1,c.docs.push(o),c.size++,c.empty=!1)}console.log("getReportSales_Employees_byEmployees"),a(c)}))}else a(c)}))},t.prototype.getReportSales_Employees_byProducts=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l=i.getlocalProducts(12);r=r="all"===o||void 0===o?{date:{$gte:t,$lte:e},id_employee:{$eq:n},bill_type:{$in:[1,3,15]}}:{date:{$gte:t,$lte:e},id_employee:{$eq:n},bill_type:{$in:[1,3,15]},id_branch:{$eq:o}};var c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};l.length>0?i.vhmongo_firebase.database().getDocsByFields("vhbill_details",r,{},{date:1},0).then((function(t){if(t.length>0)for(var e=0;e<l.length;e++){for(var n=!1,o=Object.assign({},l[e]),i={id_product:o._id,name:o.name,unit:o.unit,barcode:o.barcode,img:o.img,sales_btax:0,sales_atax:0,quantity:0},s=0;s<t.length;s++)if(3==t[s].bill_type)if(5===t[s].ptype)for(var r=0;r<t[s].combos.length;r++)l[e]._id===t[s].combos[r].id_product&&(n=!0,i.quantity=i.quantity-t[s].combos[r].quantity*t[s].quantity,i.sales_btax=i.sales_btax-t[s].combos[r].price*t[s].combos[r].quantity*t[s].quantity,i.sales_atax=i.sales_atax-t[s].combos[r].price*t[s].combos[r].quantity*t[s].quantity*(1+t[s].tax/100));else l[e]._id===t[s].id_product&&(n=!0,i.quantity=i.quantity-t[s].quantity,i.sales_btax=i.sales_btax-t[s].price*t[s].quantity,i.sales_atax=i.sales_atax-t[s].price*t[s].quantity*(1+t[s].tax/100));else if(5===t[s].ptype)for(r=0;r<t[s].combos.length;r++)l[e]._id===t[s].combos[r].id_product&&(n=!0,i.quantity=i.quantity+t[s].combos[r].quantity*t[s].quantity,i.sales_btax=i.sales_btax+t[s].combos[r].price*t[s].combos[r].quantity*t[s].quantity,i.sales_atax=i.sales_atax+t[s].combos[r].price*t[s].combos[r].quantity*t[s].quantity*(1+t[s].tax/100));else l[e]._id===t[s].id_product&&(n=!0,i.quantity=i.quantity+t[s].quantity,i.sales_btax=i.sales_btax+t[s].price*t[s].quantity,i.sales_atax=i.sales_atax+t[s].price*t[s].quantity*(1+t[s].tax/100));n&&(i.sales_atax=Math.round(1e6*i.sales_atax)/1e6,c.quantity=c.quantity+i.quantity,c.sales_btax=c.sales_btax+i.sales_btax,c.sales_atax=c.sales_atax+i.sales_atax,i.index=c.size+1,c.docs.push(i),c.size++,c.empty=!1)}console.log("getReportSales_Employees_byProducts"),a(c)})):a(c)}))},t.prototype.getReportSales_Employees_byProduct=function(t,e,n,o,i){var a=this;return new Promise((function(s,r){var l=a.getlocalProduct(o),c=new Array;a.getlocalProductAndCombos(o).forEach((function(t){c.push(t._id)}));for(var u,d=l.type,_={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0},p=new Array,b=[1,3,15],f=0;f<b.length;f++)u="all"===i||void 0===i?{date:{$gte:t,$lte:e},id_employee:{$eq:n},id_product:{$in:c},bill_type:{$eq:b[f]}}:{date:{$gte:t,$lte:e},id_employee:{$eq:n},id_product:{$in:c},bill_type:{$eq:b[f]},id_branch:{$eq:i}},p[f]=a.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0);Promise.all(p).then((function(t){var e,n=t.flat();if(n.length>0)for(var o=0;o<n.length;o++){var i=new Array;if(i[0]={id_product:l._id,name:l.name,unit:l.unit,barcode:l.barcode,img:l.img,bill_code:n[o].bill_code,bill_type:n[o].bill_type,id_bill:n[o].id_bill,date:n[o].date,tax:n[o].tax,salesman:null===(e=a.vhAuth.getlocalEmployee(n[o].id_employee))||void 0===e?void 0:e.name,customer:a.getlocalCustomer(n[o].id_customer).name},3==n[o].bill_type)if(1===d||2===d)if(null!=n[o].combos)for(var r=0;r<n[o].combos.length;r++)n[o].combos[r].id_product===l._id&&(i[0].quantity=-n[o].combos[r].quantity*n[o].quantity,i[0].price=n[o].combos[r].price);else i[0].quantity=-n[o].quantity,i[0].price=n[o].price;else 5===d&&(i[0].quantity=-n[o].quantity,i[0].price=n[o].price);else if(1===d||2===d)if(null!=n[o].combos)for(r=0;r<n[o].combos.length;r++)n[o].combos[r].id_product===l._id&&(i[0].quantity=n[o].combos[r].quantity*n[o].quantity,i[0].price=n[o].combos[r].price);else i[0].quantity=n[o].quantity,i[0].price=n[o].price;else 5===d&&(i[0].quantity=n[o].quantity,i[0].price=n[o].price);i.forEach((function(t){t.sales_btax=t.price*t.quantity,t.sales_atax=t.price*t.quantity*(1+t.tax/100),t.index=_.size+1,_.docs.push(t),_.size++,_.empty=!1,_.quantity=_.quantity+t.quantity,_.sales_btax=_.sales_btax+t.price*t.quantity,_.sales_atax=_.sales_atax+t.price*t.quantity*(1+Number(t.tax)/100)}))}console.log("getReportSales_Employees_byProduct"),s(_)}))}))},t.prototype.getReportInputOutputReturns_byTime_byIDProduct_byBillTypeArray=function(t,e,n,o,i,a){var s=this;return new Promise((function(r,l){var c=new Array,u=new Array,d=new Array;if(1===o?d=[1,5]:2===o&&(d=[2,5]),"all"===n)c=s.vhAlgorithm.sortVietnamesebyASC(s.getlocalProducts(o),"name");else{var _=s.getlocalProduct(n);c.push(_),s.getlocalProductAndCombos(n).forEach((function(t){u.push(t._id)}))}var p={docs:new Array,empty:!0,size:0,quantity:0,pay_btax:0,pay_atax:0};if(c.length>0){for(var b=void 0,f=new Array,h=0;h<i.length;h++)b="all"===n?"all"===a||void 0===a?{date:{$gte:t,$lte:e},ptype:{$in:d},bill_type:{$eq:i[h]}}:{date:{$gte:t,$lte:e},ptype:{$in:d},bill_type:{$eq:i[h]},id_branch:{$eq:a}}:"all"===a||void 0===a?{date:{$gte:t,$lte:e},id_product:{$in:u},bill_type:{$eq:i[h]}}:{date:{$gte:t,$lte:e},id_product:{$in:u},bill_type:{$eq:i[h]},id_branch:{$eq:a}},f[h]=s.vhmongo_firebase.database().getDocsByFields("vhbill_details",b,{},{date:1},0);Promise.all(f).then((function(t){for(var e=t.flat(),n=0;n<c.length;n++){for(var o={_id:c[n]._id,name:c[n].name,type:c[n].type,unit:c[n].unit,quantity:0,pay_btax:0,pay_atax:0},i=0;i<e.length;i++)if(1===e[i].ptype)e[i].id_product===c[n]._id&&(o.pay_btax=o.pay_btax+e[i].price*e[i].quantity,o.pay_atax=o.pay_atax+e[i].price*e[i].quantity*(1+e[i].tax/100),o.quantity=o.quantity+e[i].quantity,p.pay_btax=p.pay_btax+e[i].price*e[i].quantity,p.pay_atax=p.pay_atax+e[i].price*e[i].quantity*(1+e[i].tax/100),p.quantity=p.quantity+e[i].quantity);else if(5===e[i].ptype)for(var a=0;a<e[i].combos.length;a++)e[i].combos[a].id_product===o._id&&(o.pay_btax=o.pay_btax+e[i].combos[a].price*e[i].combos[a].quantity*e[i].quantity,o.pay_atax=o.pay_atax+e[i].combos[a].price*e[i].combos[a].quantity*e[i].quantity*(1+e[i].tax/100),o.quantity=o.quantity+e[i].combos[a].quantity*e[i].quantity,p.pay_btax=p.pay_btax+e[i].combos[a].price*e[i].combos[a].quantity*e[i].quantity,p.pay_atax=p.pay_atax+e[i].combos[a].price*e[i].combos[a].quantity*e[i].quantity*(1+e[i].tax/100),p.quantity=p.quantity+e[i].combos[a].quantity*e[i].quantity);o.pay_atax=Math.round(1e6*o.pay_atax)/1e6,p.pay_atax=Math.round(1e6*p.pay_atax)/1e6,p.docs.push(o),p.size++,p.empty=!1}r(p)}))}else console.log("server -> products khong ton tai trong CSDL: "),r(p)}))},t.prototype.getReportInputOutputReturns_Detail_byTime_byIDProduct_byBillTypeArray=function(t,e,n,o,i){var a=this;return new Promise((function(s,r){var l,c=a.getlocalProduct(n),u={docs:new Array,empty:!0,size:0,quantity:0,pay_btax:0,pay_atax:0},d=new Array,_=new Array;a.getlocalProductAndCombos(n).forEach((function(t){_.push(t._id)}));for(var p=0;p<_.length;p++)l="all"===i||void 0===i?{date:{$gte:t,$lte:e},id_product:{$eq:_[p]},bill_type:{$in:o}}:{date:{$gte:t,$lte:e},id_product:{$eq:_[p]},bill_type:{$in:o},id_branch:{$eq:i}},d[p]=a.vhmongo_firebase.database().getDocsByFields("vhbill_details",l,{},{date:1},0);a.vhmongo_firebase.database().getDocsByFields("vhbill_details",l,{},{date:1},0).then((function(t){for(var e,n,o,i,a,r,l,d,_,p,b,f,h=0;h<t.length;h++){var y={id_bill:null===(e=t[h])||void 0===e?void 0:e.id_bill,bill_code:null===(n=t[h])||void 0===n?void 0:n.bill_code,bill_type:null===(o=t[h])||void 0===o?void 0:o.bill_type,date:null===(i=t[h])||void 0===i?void 0:i.date,name:c.name,unit:c.unit};if((null===(a=t[h])||void 0===a?void 0:a.id_cashier)&&(y.id_cashier=null===(r=t[h])||void 0===r?void 0:r.id_cashier),(null===(l=t[h])||void 0===l?void 0:l.id_employee)&&(y.id_employee=null===(d=t[h])||void 0===d?void 0:d.id_employee),(null===(_=t[h])||void 0===_?void 0:_.id_customer)&&(y.id_customer=null===(p=t[h])||void 0===p?void 0:p.id_customer),(null===(b=t[h])||void 0===b?void 0:b.id_supplier)&&(y.id_supplier=null===(f=t[h])||void 0===f?void 0:f.id_supplier),1===t[h].ptype)y.price_btax=t[h].price,y.price_atax=t[h].price*(1+t[h].tax/100),y.pay_btax=t[h].price*t[h].quantity,y.pay_atax=t[h].price*t[h].quantity*(1+t[h].tax/100),y.quantity=t[h].quantity,u.quantity=u.quantity+t[h].quantity,u.pay_btax=u.pay_btax+t[h].price*t[h].quantity,u.pay_atax=u.pay_atax+t[h].price*t[h].quantity*(1+t[h].tax/100);else if(5===t[h].ptype)for(var m=0;m<t[h].combos.length;m++)t[h].combos[m].id_product===c._id&&(y.price_btax=t[h].combos[m].price,y.price_atax=t[h].combos[m].price*(1+t[h].tax/100),y.pay_btax=t[h].combos[m].price*t[h].combos[m].quantity*t[h].quantity,y.pay_atax=t[h].combos[m].price*t[h].combos[m].quantity*t[h].quantity*(1+t[h].tax/100),y.quantity=t[h].combos[m].quantity*t[h].quantity,u.quantity=u.quantity+t[h].combos[m].quantity*t[h].quantity,u.pay_btax=u.pay_btax+t[h].combos[m].price*t[h].combos[m].quantity*t[h].quantity,u.pay_atax=u.pay_atax+t[h].combos[m].price*t[h].combos[m].quantity*t[h].quantity*(1+t[h].tax/100));0==c.inquantity&&0==c.outquantity||(y.price_atax=Math.round(1e6*y.price_atax)/1e6,y.pay_atax=Math.round(1e6*y.pay_atax)/1e6,u.pay_atax=Math.round(1e6*u.pay_atax)/1e6,y.index=u.size+1,u.docs.push(y),u.size++,u.empty=!1)}console.log("getReportInputOutputInventory_byTime_byIDProduct"),s(u)}))}))},t.prototype.getReportInputOutputInventory_byTime_byIDProduct=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r={docs:new Array,empty:!0,size:0,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0,stock_first:0,stock_last:0,cost_stock_first_btax:0,cost_stock_first_atax:0,cost_stock_last_btax:0,cost_stock_last_atax:0},l=i.vhAuth.getStore(),c=new Array;if("all"===n)c=i.vhAlgorithm.sortVietnamesebyASC(i.getlocalProducts(1),"name");else{var u=i.getlocalProduct(n);c.push(u)}var d=null,_=null;if("all"===n)if("all"===o||void 0===o)console.log("trường hợp này chưa có hàm, liên hệ anh Huy viết");else{if(null!=c[0][o]&&null!=c[0][o].inventory){for(var p=0;p<c[0][o].inventory.length&&!(new Date(c[0][o].inventory[p].date).getTime()>t.getTime());p++)_=new Date(c[0][o].inventory[p].date),d=p,p;for(p=0;p<c[0][o].inventory.length&&!(new Date(c[0][o].inventory[p].date).getTime()>e.getTime());p++)p}if(_){for(var b=!1,f=0;f<c.length;f++)null!=c[f][o]&&null!=c[f][o].inventory||(b=!0);if(b)return console.log("Vui lòng đồng bộ kho để lấy về dữ liệu mới nhất"),a(r)}}else if("all"===o||void 0===o)console.log("trường hợp này chưa có hàm, liên hệ anh Huy viết");else if(null!=c[0][o]&&null!=c[0][o].inventory)for(p=0;p<c[0][o].inventory.length&&!(new Date(c[0][o].inventory[p].date).getTime()>t.getTime());p++)_=new Date(c[0][o].inventory[p].date),d=p;if(_||(_=new Date(l.registrationdate)),c.length>0){var h,y=new Array;if("all"===n)h="all"===o||void 0===o?{date:{$gte:_,$lte:e},bill_type:{$in:[1,10,15,30,2,3,9,31]}}:{date:{$gte:_,$lte:e},bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:o}},y[0]=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",h,{},{date:1},0);else{var m=i.getlocalProductAndCombos(n);for(f=0;f<m.length;f++)h="all"===o||void 0===o?{date:{$gte:_,$lte:e},id_product:{$eq:m[f]._id},bill_type:{$in:[1,10,15,30,2,3,9,31]}}:{date:{$gte:_,$lte:e},id_product:{$eq:m[f]._id},bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:o}},y[f]=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",h,{},{date:1},0)}Promise.all(y).then((function(e){for(var n=e.flat(),i=0;i<c.length;i++){for(var s={stock_first:0,cost_stock_first_btax:0,cost_stock_first_atax:0,unit_cost_stock_first_btax:0,unit_cost_stock_first_atax:0,inquantity_tofirst:0,outquantity_tofirst:0,pay_tofirst_btax:0,pay_tofirst_atax:0,profit_first_btax:0,profit_first_atax:0,sales_tofirst_btax:0,sales_tofirst_atax:0},l={_id:c[i]._id,name:c[i].name,type:c[i].type,unit:c[i].unit,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0,stock_first:0,stock_last:0,cost_stock_first_btax:0,cost_stock_first_atax:0,cost_stock_last_btax:0,cost_stock_last_atax:0},u=0,_=0,p=0,b=0,f=0,h=0,y=0,m=0;m<n.length;m++)if(1===n[m].ptype){if(n[m].id_product===c[i]._id){var v=new Date(n[m].date);1===n[m].bill_type||10===n[m].bill_type||15===n[m].bill_type||30===n[m].bill_type?v>=new Date(t)?(l.revenue_btax=l.revenue_btax+n[m].price*n[m].quantity,l.revenue_atax=l.revenue_atax+n[m].price*n[m].quantity*(1+n[m].tax/100),l.outquantity=l.outquantity+n[m].quantity,r.revenue_btax=r.revenue_btax+n[m].price*n[m].quantity,r.revenue_atax=r.revenue_atax+n[m].price*n[m].quantity*(1+n[m].tax/100),r.outquantity=r.outquantity+n[m].quantity):u+=n[m].quantity:2===n[m].bill_type||3===n[m].bill_type||31===n[m].bill_type?(v>=new Date(t)?(l.cost_btax=l.cost_btax+n[m].price*n[m].quantity,l.cost_atax=l.cost_atax+n[m].price*n[m].quantity*(1+n[m].tax/100),l.inquantity=l.inquantity+n[m].quantity,r.cost_btax=r.cost_btax+n[m].price*n[m].quantity,r.cost_atax=r.cost_atax+n[m].price*n[m].quantity*(1+n[m].tax/100),r.inquantity=r.inquantity+n[m].quantity):(_+=n[m].quantity,p+=n[m].price*n[m].quantity,b+=n[m].price*n[m].quantity*(1+n[m].tax/100)),f+=n[m].quantity,h+=n[m].price*n[m].quantity,y+=n[m].price*n[m].quantity*(1+n[m].tax/100)):9===n[m].bill_type&&(s.stock_first=s.stock_first+n[m].quantity,s.cost_stock_first_btax=s.cost_stock_first_btax+n[m].price*n[m].quantity,s.cost_stock_first_atax=s.cost_stock_first_atax+n[m].price*n[m].quantity*(1+n[m].tax/100))}}else if(5===n[m].ptype)for(var g=0;g<n[m].combos.length;g++)if(n[m].combos[g].id_product===c[i]._id){v=new Date(n[m].date);1===n[m].bill_type||10===n[m].bill_type||15===n[m].bill_type||30===n[m].bill_type?v>=new Date(t)?(l.revenue_btax=l.revenue_btax+n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity,l.revenue_atax=l.revenue_atax+n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity*(1+n[m].tax/100),l.outquantity=l.outquantity+n[m].combos[g].quantity*n[m].quantity,r.revenue_btax=r.revenue_btax+n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity,r.revenue_atax=r.revenue_atax+n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity*(1+n[m].tax/100),r.outquantity=r.outquantity+n[m].combos[g].quantity*n[m].quantity):u+=n[m].combos[g].quantity*n[m].quantity:2===n[m].bill_type||3===n[m].bill_type||31===n[m].bill_type?(v>=new Date(t)?(l.cost_btax=l.cost_btax+n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity,l.cost_atax=l.cost_atax+n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity*(1+n[m].tax/100),l.inquantity=l.inquantity+n[m].combos[g].quantity*n[m].quantity,r.cost_btax=r.cost_btax+n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity,r.cost_atax=r.cost_atax+n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity*(1+n[m].tax/100),r.inquantity=r.inquantity+n[m].combos[g].quantity*n[m].quantity):(p+=n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity,b+=n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity*(1+n[m].tax/100),_+=n[m].combos[g].quantity*n[m].quantity),f+=n[m].combos[g].quantity*n[m].quantity,h+=n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity,y+=n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity*(1+n[m].tax/100)):9===n[m].bill_type&&(s.stock_first=s.stock_first+n[m].combos[g].quantity*n[m].quantity,s.cost_stock_first_btax=s.cost_stock_first_btax+n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity,s.cost_stock_first_atax=s.cost_stock_first_atax+n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity*(1+n[m].tax/100));break}null!=d&&(s=Object.assign({},c[i][o].inventory[d])),l.stock_first=s.stock_first+_-u,l.stock_last=l.stock_first+l.inquantity-l.outquantity,s.stock_first+_!=0&&(l.cost_stock_first_btax=(s.cost_stock_first_btax+p)/(s.stock_first+_)*l.stock_first,l.cost_stock_first_atax=(s.cost_stock_first_atax+b)/(s.stock_first+_)*l.stock_first),s.stock_first+f!=0&&(l.cost_stock_last_btax=(s.cost_stock_first_btax+h)/(s.stock_first+f)*l.stock_last,l.cost_stock_last_atax=(s.cost_stock_first_atax+y)/(s.stock_first+f)*l.stock_last),r.stock_first=r.stock_first+l.stock_first,r.stock_last=r.stock_last+l.stock_last,r.cost_stock_first_btax=r.cost_stock_first_btax+l.cost_stock_first_btax,r.cost_stock_first_atax=r.cost_stock_first_atax+l.cost_stock_first_atax,r.cost_stock_last_btax=r.cost_stock_last_btax+l.cost_stock_last_btax,r.cost_stock_last_atax=r.cost_stock_last_atax+l.cost_stock_last_atax,0==l.stock_first&&0==l.stock_last&&0==l.inquantity&&0==l.outquantity||(l.revenue_atax=Math.round(1e6*l.revenue_atax)/1e6,l.cost_atax=Math.round(1e6*l.cost_atax)/1e6,l.cost_stock_first_atax=Math.round(1e6*l.cost_stock_first_atax)/1e6,l.cost_stock_last_atax=Math.round(1e6*l.cost_stock_last_atax)/1e6,l.index=r.size+1,r.docs.push(l),r.size++,r.empty=!1)}a(r),console.log("getReportInputOutputInventory_byTime_byIDProduct3",r)}))}else console.log("server -> products khong ton tai trong CSDL: "),a(r)}))},t.prototype.makeCorrectStock1stDayOfMonth=function(t,e,n,o,i){var a=this;return new Promise((function(s,r){for(var l=new Array,c=0;c<n.length;c++)if(null!=n[c][i]&&null!=n[c][i].inventory){for(var u=n[c][i].inventory[t],d=t+1;d<=e;d++)n[c][i].inventory[d].inquantity_tofirst=u.inquantity_tofirst,n[c][i].inventory[d].pay_tofirst_btax=u.pay_tofirst_btax,n[c][i].inventory[d].pay_tofirst_atax=u.pay_tofirst_atax,n[c][i].inventory[d].outquantity_tofirst=u.outquantity_tofirst,n[c][i].inventory[d].sales_tofirst_btax=u.sales_tofirst_btax,n[c][i].inventory[d].sales_tofirst_atax=u.sales_tofirst_atax,n[c][i].inventory[d].stock_first=0,n[c][i].inventory[d].unit_cost_stock_first_btax=0,n[c][i].inventory[d].unit_cost_stock_first_atax=0,n[c][i].inventory[d].cost_stock_first_btax=0,n[c][i].inventory[d].cost_stock_first_atax=0,n[c][i].inventory[d].profit_first_btax=0,n[c][i].inventory[d].profit_first_atax=0;if(o.length>0)for(var _=0;_<o.length;_++)if(1===o[_].ptype){if(o[_].id_product===n[c]._id)for(d=t+1;d<=e;d++)new Date(o[_].date).getTime()<new Date(n[c][i].inventory[d].date).getTime()&&(1===o[_].bill_type||10===o[_].bill_type||15===o[_].bill_type||30===o[_].bill_type?(n[c][i].inventory[d].outquantity_tofirst=n[c][i].inventory[d].outquantity_tofirst+o[_].quantity,n[c][i].inventory[d].sales_tofirst_btax=n[c][i].inventory[d].sales_tofirst_btax+o[_].price*o[_].quantity,n[c][i].inventory[d].sales_tofirst_atax=n[c][i].inventory[d].sales_tofirst_atax+o[_].price*o[_].quantity*(1+o[_].tax/100)):2!==o[_].bill_type&&3!==o[_].bill_type&&9!==o[_].bill_type&&31!==o[_].bill_type||(n[c][i].inventory[d].inquantity_tofirst=n[c][i].inventory[d].inquantity_tofirst+o[_].quantity,n[c][i].inventory[d].pay_tofirst_btax=n[c][i].inventory[d].pay_tofirst_btax+o[_].price*o[_].quantity,n[c][i].inventory[d].pay_tofirst_atax=n[c][i].inventory[d].pay_tofirst_atax+o[_].price*o[_].quantity*(1+o[_].tax/100)))}else if(5===o[_].ptype)for(var p=0;p<o[_].combos.length;p++)if(o[_].combos[p].id_product===n[c]._id)for(d=t+1;d<=e;d++)new Date(o[_].date).getTime()<new Date(n[c][i].inventory[d].date).getTime()&&(1===o[_].bill_type||10===o[_].bill_type||15===o[_].bill_type||30===o[_].bill_type?(n[c][i].inventory[d].outquantity_tofirst=n[c][i].inventory[d].outquantity_tofirst+o[_].combos[p].quantity*o[_].quantity,n[c][i].inventory[d].sales_tofirst_btax=n[c][i].inventory[d].sales_tofirst_btax+o[_].combos[p].price*o[_].combos[p].quantity*o[_].quantity,n[c][i].inventory[d].sales_tofirst_atax=n[c][i].inventory[d].sales_tofirst_atax+o[_].combos[p].price*o[_].combos[p].quantity*o[_].quantity*(1+o[_].tax/100)):2!==o[_].bill_type&&3!==o[_].bill_type&&9!==o[_].bill_type&&31!==o[_].bill_type||(n[c][i].inventory[d].inquantity_tofirst=n[c][i].inventory[d].inquantity_tofirst+o[_].combos[p].quantity*o[_].quantity,n[c][i].inventory[d].pay_tofirst_btax=n[c][i].inventory[d].pay_tofirst_btax+o[_].combos[p].price*o[_].combos[p].quantity*o[_].quantity,n[c][i].inventory[d].pay_tofirst_atax=n[c][i].inventory[d].pay_tofirst_atax+o[_].combos[p].price*o[_].combos[p].quantity*o[_].quantity*(1+o[_].tax/100)));for(d=t+1;d<=e;d++){var b=n[c][i].inventory[d].inquantity_tofirst-n[c][i].inventory[d-1].inquantity_tofirst,f=n[c][i].inventory[d].pay_tofirst_btax-n[c][i].inventory[d-1].pay_tofirst_btax,h=n[c][i].inventory[d].pay_tofirst_atax-n[c][i].inventory[d-1].pay_tofirst_atax;n[c][i].inventory[d].stock_first=n[c][i].inventory[d].inquantity_tofirst-n[c][i].inventory[d].outquantity_tofirst,n[c][i].inventory[d-1].stock_first+b!=0&&(n[c][i].inventory[d].unit_cost_stock_first_btax=(n[c][i].inventory[d-1].cost_stock_first_btax+f)/(n[c][i].inventory[d-1].stock_first+b),n[c][i].inventory[d].unit_cost_stock_first_atax=(n[c][i].inventory[d-1].cost_stock_first_atax+h)/(n[c][i].inventory[d-1].stock_first+b),n[c][i].inventory[d].cost_stock_first_btax=n[c][i].inventory[d].unit_cost_stock_first_btax*n[c][i].inventory[d].stock_first,n[c][i].inventory[d].cost_stock_first_atax=n[c][i].inventory[d].unit_cost_stock_first_atax*n[c][i].inventory[d].stock_first);var y=n[c][i].inventory[d].outquantity_tofirst-n[c][i].inventory[d-1].outquantity_tofirst,m=n[c][i].inventory[d].unit_cost_stock_first_btax*y,v=n[c][i].inventory[d].unit_cost_stock_first_atax*y,g=n[c][i].inventory[d].sales_tofirst_btax-n[c][i].inventory[d-1].sales_tofirst_btax,x=n[c][i].inventory[d].sales_tofirst_atax-n[c][i].inventory[d-1].sales_tofirst_atax;n[c][i].inventory[d].profit_first_btax=g-m,n[c][i].inventory[d].profit_first_atax=x-v}var q=a.getlocalProduct(n[c]._id);for(d=t+1;d<=e;d++)q[i].inventory[d].inquantity_tofirst!=n[c][i].inventory[d].inquantity_tofirst||q[i].inventory[d].pay_tofirst_btax!=n[c][i].inventory[d].pay_tofirst_btax||q[i].inventory[d].pay_tofirst_atax!=n[c][i].inventory[d].pay_tofirst_atax||q[i].inventory[d].outquantity_tofirst!=n[c][i].inventory[d].outquantity_tofirst||q[i].inventory[d].sales_tofirst_btax!=n[c][i].inventory[d].sales_tofirst_btax||q[i].inventory[d].sales_tofirst_atax!=n[c][i].inventory[d].sales_tofirst_atax||q[i].inventory[d].stock_first!=n[c][i].inventory[d].stock_first||q[i].inventory[d].unit_cost_stock_first_btax!=n[c][i].inventory[d].unit_cost_stock_first_btax||q[i].inventory[d].unit_cost_stock_first_atax!=n[c][i].inventory[d].unit_cost_stock_first_atax||q[i].inventory[d].cost_stock_first_btax!=n[c][i].inventory[d].cost_stock_first_btax||q[i].inventory[d].cost_stock_first_atax!=n[c][i].inventory[d].cost_stock_first_atax||q[i].inventory[d].profit_first_btax!=n[c][i].inventory[d].profit_first_btax||q[i].inventory[d].profit_first_atax!=n[c][i].inventory[d].profit_first_atax?(console.log("k",d),console.log("_product",q),console.log("products[i]",n[c]),l[l.length]=new Promise((function(t,e){t(null)}))):l[l.length]=new Promise((function(t,e){t(null)}))}Promise.all(l).then((function(){console.log("makeCorrectStock1stDayOfMonth"),s(!0)}))}))},t.prototype.getReportInputOutputInventory_byEndTime_byIDProduct_allRecords=function(t,e,n){var o=this;return new Promise((function(i,a){var s=new Array;if("all"===e)s=o.vhAlgorithm.sortVietnamesebyASC(o.getlocalProducts(1),"name");else{var r=o.getlocalProduct(e);s.push(r)}var l={docs:new Array,empty:!0,size:0,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0,stock_last:0,cost_stock_last_btax:0,cost_stock_last_atax:0};if(s.length>0){var c=void 0;c="all"===e?"all"===n||void 0===n?{date:{$lte:t},bill_type:{$in:[1,10,15,30,2,3,9,31]}}:{date:{$lte:t},bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:n}}:"all"===n||void 0===n?{date:{$lte:t},id_product:{$eq:e},bill_type:{$in:[1,10,15,30,2,3,9,31]}}:{date:{$lte:t},id_product:{$eq:e},bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:n}},o.vhmongo_firebase.database().getDocsByFields("vhbill_details",c,{},{date:1},0).then((function(t){for(var e=0;e<s.length;e++){for(var o={_id:s[e]._id,name:s[e].name,type:s[e].type,unit:s[e].unit,img:s[e].img,allow_sell:s[e].allow_sell,barcode:s[e].barcode,price:s[e].price,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0,stock_last:0,cost_stock_last_btax:0,cost_stock_last_atax:0,unit_cost_stock_last_btax:0,unit_cost_stock_last_atax:0},a=0;a<t.length;a++)if(1===t[a].ptype)t[a].id_product===s[e]._id&&(1===t[a].bill_type||10===t[a].bill_type||15===t[a].bill_type||30===t[a].bill_type?(o.revenue_btax=o.revenue_btax+t[a].price*t[a].quantity,o.revenue_atax=o.revenue_atax+t[a].price*t[a].quantity*(1+t[a].tax/100),o.outquantity=o.outquantity+t[a].quantity,l.revenue_btax=l.revenue_btax+t[a].price*t[a].quantity,l.revenue_atax=l.revenue_atax+t[a].price*t[a].quantity*(1+t[a].tax/100),l.outquantity=l.outquantity+t[a].quantity):2!==t[a].bill_type&&3!==t[a].bill_type&&9!==t[a].bill_type&&31!==t[a].bill_type||(o.cost_btax=o.cost_btax+t[a].price*t[a].quantity,o.cost_atax=o.cost_atax+t[a].price*t[a].quantity*(1+t[a].tax/100),o.inquantity=o.inquantity+t[a].quantity,l.cost_btax=l.cost_btax+t[a].price*t[a].quantity,l.cost_atax=l.cost_atax+t[a].price*t[a].quantity*(1+t[a].tax/100),l.inquantity=l.inquantity+t[a].quantity));else if(5===t[a].ptype)if("all"===n||void 0===n);else for(var r=0;r<t[a].combos.length;r++)t[a].combos[r].id_product===s[e]._id&&(1===t[a].bill_type||10===t[a].bill_type||15===t[a].bill_type||30===t[a].bill_type?(o.revenue_btax=o.revenue_btax+t[a].combos[r].price*t[a].combos[r].quantity*t[a].quantity,o.revenue_atax=o.revenue_atax+t[a].combos[r].price*t[a].combos[r].quantity*t[a].quantity*(1+t[a].tax/100),o.outquantity=o.outquantity+t[a].combos[r].quantity*t[a].quantity,l.revenue_btax=l.revenue_btax+t[a].combos[r].price*t[a].combos[r].quantity*t[a].quantity,l.revenue_atax=l.revenue_atax+t[a].combos[r].price*t[a].combos[r].quantity*t[a].quantity*(1+t[a].tax/100),l.outquantity=l.outquantity+t[a].combos[r].quantity*t[a].quantity):2!==t[a].bill_type&&3!==t[a].bill_type&&9!==t[a].bill_type&&31!==t[a].bill_type||(o.cost_btax=o.cost_btax+t[a].combos[r].price*t[a].combos[r].quantity*t[a].quantity,o.cost_atax=o.cost_atax+t[a].combos[r].price*t[a].combos[r].quantity*t[a].quantity*(1+t[a].tax/100),o.inquantity=o.inquantity+t[a].combos[r].quantity*t[a].quantity,l.cost_btax=l.cost_btax+t[a].combos[r].price*t[a].combos[r].quantity*t[a].quantity,l.cost_atax=l.cost_atax+t[a].combos[r].price*t[a].combos[r].quantity*t[a].quantity*(1+t[a].tax/100),l.inquantity=l.inquantity+t[a].combos[r].quantity*t[a].quantity));o.stock_last=o.inquantity-o.outquantity,0!=o.inquantity&&(o.unit_cost_stock_last_btax=o.cost_btax/o.inquantity),0!=o.inquantity&&(o.unit_cost_stock_last_atax=o.cost_atax/o.inquantity),o.cost_stock_last_btax=o.unit_cost_stock_last_btax*o.stock_last,o.cost_stock_last_atax=o.unit_cost_stock_last_atax*o.stock_last,l.stock_last=l.stock_last+o.stock_last,l.cost_stock_last_btax=l.cost_stock_last_btax+o.cost_stock_last_btax,l.cost_stock_last_atax=l.cost_stock_last_atax+o.cost_stock_last_atax,o.revenue_atax=Math.round(1e6*o.revenue_atax)/1e6,o.cost_atax=Math.round(1e6*o.cost_atax)/1e6,o.cost_stock_last_atax=Math.round(1e6*o.cost_stock_last_atax)/1e6,o.unit_cost_stock_last_atax=Math.round(1e6*o.unit_cost_stock_last_atax)/1e6,l.revenue_atax=Math.round(1e6*l.revenue_atax)/1e6,l.cost_atax=Math.round(1e6*l.cost_atax)/1e6,l.cost_stock_last_atax=Math.round(1e6*l.cost_stock_last_atax)/1e6,l.index=l.size+1,l.docs.push(o),l.size++,l.empty=!1}console.log("getReportInputOutputInventory_byEndTime_byIDProduct"),i(l)}))}else console.log("server -> products khong ton tai trong CSDL: "),i(l)}))},t.prototype.getReportInputOutputInventory_byEndTime_byIDProduct=function(t,e,n){var o=this;return new Promise((function(i,a){var s=o.getDefaultBranch()._id,r={docs:new Array,empty:!0,size:0},l=o.vhAuth.getStore(),c=new Array;if("all"===e)c=o.vhAlgorithm.sortVietnamesebyASC(o.getlocalProducts(1),"name");else{var u=o.getlocalProduct(e);c.push(u)}var d=null,_=null;if("all"===e)if("all"===n||void 0===n)console.log("trường hợp này chưa có hàm, liên hệ anh Huy viết");else{if(null!=c[0][n]&&null!=c[0][n].inventory)for(var p=0;p<c[0][n].inventory.length&&!(new Date(c[0][n].inventory[p].date).getTime()>t.getTime());p++)_=new Date(c[0][n].inventory[p].date),d=p;if(_){for(var b=!1,f=0;f<c.length;f++)null!=c[f][n]&&null!=c[f][n].inventory||(b=!0);if(b)return console.log("Vui lòng đồng bộ kho để lấy về dữ liệu mới nhất"),i(r)}}else if("all"===n||void 0===n)console.log("trường hợp này chưa có hàm, liên hệ anh Huy viết");else if(null!=c[0][n]&&null!=c[0][n].inventory)for(p=0;p<c[0][n].inventory.length&&!(new Date(c[0][n].inventory[p].date).getTime()>t.getTime());p++)_=new Date(c[0][n].inventory[p].date),d=p;if(_||(_=new Date(l.registrationdate)),c.length>0){var h,y=new Array;if("all"===e)h="all"===n||void 0===n?{date:{$gte:_,$lte:t},bill_type:{$in:[1,10,15,30,2,3,9,31]}}:{date:{$gte:_,$lte:t},bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:n}},y[0]=o.vhmongo_firebase.database().getDocsByFields("vhbill_details",h,{},{date:1},0);else{var m=o.getlocalProductAndCombos(e);for(f=0;f<m.length;f++)h="all"===n||void 0===n?{date:{$gte:_,$lte:t},id_product:{$eq:m[f]._id},bill_type:{$in:[1,10,15,30,2,3,9,31]}}:{date:{$gte:_,$lte:t},id_product:{$eq:m[f]._id},bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:n}},y[f]=o.vhmongo_firebase.database().getDocsByFields("vhbill_details",h,{},{date:1},0)}Promise.all(y).then((function(t){for(var e=t.flat(),n=0;n<c.length;n++){for(var o={stock_first:0,cost_stock_first_btax:0,cost_stock_first_atax:0,unit_cost_stock_first_btax:0,unit_cost_stock_first_atax:0,inquantity_tofirst:0,outquantity_tofirst:0,pay_tofirst_btax:0,pay_tofirst_atax:0,profit_first_btax:0,profit_first_atax:0,sales_tofirst_btax:0,sales_tofirst_atax:0},a={_id:c[n]._id,name:c[n].name,type:c[n].type,unit:c[n].unit,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0,unit_cost_stock_last_btax:0,unit_cost_stock_last_atax:0,stock_first:0,cost_stock_first_btax:0,cost_stock_first_atax:0,stock_last:0,cost_stock_last_btax:0,cost_stock_last_atax:0},l=0;l<e.length;l++)if(1===e[l].ptype){if(e[l].id_product===c[n]._id){new Date(e[l].date);1===e[l].bill_type||10===e[l].bill_type||15===e[l].bill_type||30===e[l].bill_type?a.outquantity=a.outquantity+e[l].quantity:2===e[l].bill_type||3===e[l].bill_type||31===e[l].bill_type?(a.cost_btax=a.cost_btax+e[l].price*e[l].quantity,a.cost_atax=a.cost_atax+e[l].price*e[l].quantity*(1+e[l].tax/100),a.inquantity=a.inquantity+e[l].quantity):9===e[l].bill_type&&(o.stock_first=o.stock_first+e[l].quantity,o.cost_stock_first_btax=o.cost_stock_first_btax+e[l].price*e[l].quantity,o.cost_stock_first_atax=o.cost_stock_first_atax+e[l].price*e[l].quantity*(1+e[l].tax/100))}}else if(5===e[l].ptype)for(var u=0;u<e[l].combos.length;u++)if(e[l].combos[u].id_product===c[n]._id){new Date(e[l].date);1===e[l].bill_type||10===e[l].bill_type||15===e[l].bill_type||30===e[l].bill_type?a.outquantity=a.outquantity+e[l].combos[u].quantity*e[l].quantity:2===e[l].bill_type||3===e[l].bill_type||31===e[l].bill_type?(a.cost_btax=a.cost_btax+e[l].combos[u].price*e[l].combos[u].quantity*e[l].quantity,a.cost_atax=a.cost_atax+e[l].combos[u].price*e[l].combos[u].quantity*e[l].quantity*(1+e[l].tax/100),a.inquantity=a.inquantity+e[l].combos[u].quantity*e[l].quantity):9===e[l].bill_type&&(o.stock_first=o.stock_first+e[l].combos[u].quantity*e[l].quantity,o.cost_stock_first_btax=o.cost_stock_first_btax+e[l].combos[u].price*e[l].combos[u].quantity*e[l].quantity,o.cost_stock_first_atax=o.cost_stock_first_atax+e[l].combos[u].price*e[l].combos[u].quantity*e[l].quantity*(1+e[l].tax/100));break}null!=d&&(o=Object.assign({},c[n][s].inventory[d])),a.stock_first=o.stock_first,a.cost_stock_first_btax=o.cost_stock_first_btax,a.cost_stock_first_atax=o.cost_stock_first_atax,a.stock_first+a.inquantity!=0&&(a.unit_cost_stock_last_btax=(a.cost_stock_first_btax+a.cost_btax)/(a.stock_first+a.inquantity),a.unit_cost_stock_last_atax=(a.cost_stock_first_atax+a.cost_atax)/(a.stock_first+a.inquantity)),a.stock_last=a.stock_first+a.inquantity-a.outquantity,a.cost_stock_last_btax=a.unit_cost_stock_last_btax*a.stock_last,a.cost_stock_last_atax=a.unit_cost_stock_last_atax*a.stock_last,0==a.stock_first&&0==a.stock_last&&0==a.inquantity&&0==a.outquantity||(a.cost_atax=Math.round(1e6*a.cost_atax)/1e6,a.cost_stock_first_atax=Math.round(1e6*a.cost_stock_first_atax)/1e6,a.cost_stock_last_atax=Math.round(1e6*a.cost_stock_last_atax)/1e6,a.index=r.size+1,r.docs.push(a),r.size++,r.empty=!1)}i(r),console.log("getReportInputOutputInventory_byEndTime_byIDProduct",r)}))}else console.log("server -> products khong ton tai trong CSDL: "),i(r)}))},t.prototype.getReportInputOutputInventory_Detail_byEndTime_byIDProduct=function(t,e,n){var o=this;return new Promise((function(i,a){var s,r=o.getlocalProduct(e),l={docs:new Array,empty:!0,size:0,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0},c=new Array,u=new Array;o.getlocalProductAndCombos(e).forEach((function(t){u.push(t._id)}));for(var d=0;d<u.length;d++)s="all"===n||void 0===n?{date:{$lte:t},id_product:{$eq:u[d]},bill_type:{$in:[1,10,15,30,2,3,9,31]}}:{date:{$lte:t},id_product:{$eq:u[d]},bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:n}},c[d]=o.vhmongo_firebase.database().getDocsByFields("vhbill_details",s,{},{date:1},0);Promise.all(c).then((function(t){for(var e,n,o,a,s,c,u,d,_,p,b,f,h,y,m=t.flat(),v=0;v<m.length;v++){var g={id_bill:null===(e=m[v])||void 0===e?void 0:e.id_bill,bill_code:null===(n=m[v])||void 0===n?void 0:n.bill_code,bill_type:null===(o=m[v])||void 0===o?void 0:o.bill_type,date:null===(a=m[v])||void 0===a?void 0:a.date,tax:null===(s=m[v])||void 0===s?void 0:s.tax,name:r.name,unit:r.unit};if((null===(c=m[v])||void 0===c?void 0:c.id_cashier)&&(g.id_cashier=null===(u=m[v])||void 0===u?void 0:u.id_cashier),(null===(d=m[v])||void 0===d?void 0:d.id_employee)&&(g.id_employee=null===(_=m[v])||void 0===_?void 0:_.id_employee),(null===(p=m[v])||void 0===p?void 0:p.id_customer)&&(g.id_customer=null===(b=m[v])||void 0===b?void 0:b.id_customer),(null===(f=m[v])||void 0===f?void 0:f.id_supplier)&&(g.id_supplier=null===(h=m[v])||void 0===h?void 0:h.id_supplier),1===m[v].ptype)g.price_btax=m[v].price,g.price_atax=m[v].price*(1+m[v].tax/100),g.payment_btax=m[v].price*m[v].quantity,g.payment_atax=m[v].price*m[v].quantity*(1+m[v].tax/100),g.quantity=null===(y=m[v])||void 0===y?void 0:y.quantity,1===m[v].bill_type||10===m[v].bill_type||15===m[v].bill_type||30===m[v].bill_type?(g.type="output",l.revenue_btax=l.revenue_btax+m[v].price*m[v].quantity,l.revenue_atax=l.revenue_atax+m[v].price*m[v].quantity*(1+m[v].tax/100),l.outquantity=l.outquantity+m[v].quantity):2===m[v].bill_type||3===m[v].bill_type||31===m[v].bill_type?(g.type="input",l.cost_btax=l.cost_btax+m[v].price*m[v].quantity,l.cost_atax=l.cost_atax+m[v].price*m[v].quantity*(1+m[v].tax/100),l.inquantity=l.inquantity+m[v].quantity):9===m[v].bill_type&&(g.type="beginning",l.cost_btax=l.cost_btax+m[v].price*m[v].quantity,l.cost_atax=l.cost_atax+m[v].price*m[v].quantity*(1+m[v].tax/100),l.inquantity=l.inquantity+m[v].quantity);else if(5===m[v].ptype)for(var x=0;x<m[v].combos.length;x++)m[v].combos[x].id_product===r._id&&(g.price_btax=m[v].combos[x].price,g.price_atax=m[v].combos[x].price*(1+m[v].tax/100),g.payment_btax=m[v].combos[x].price*m[v].combos[x].quantity*m[v].quantity,g.payment_atax=m[v].combos[x].price*m[v].combos[x].quantity*m[v].quantity*(1+m[v].tax/100),g.quantity=m[v].combos[x].quantity*m[v].quantity,1===m[v].bill_type||10===m[v].bill_type||15===m[v].bill_type||30===m[v].bill_type?(g.type="output",l.revenue_btax=l.revenue_btax+m[v].combos[x].price*m[v].combos[x].quantity*m[v].quantity,l.revenue_atax=l.revenue_atax+m[v].combos[x].price*m[v].combos[x].quantity*m[v].quantity*(1+m[v].tax/100),l.outquantity=l.outquantity+m[v].combos[x].quantity*m[v].quantity):2===m[v].bill_type||3===m[v].bill_type||31===m[v].bill_type?(g.type="input",l.cost_btax=l.cost_btax+m[v].combos[x].price*m[v].combos[x].quantity*m[v].quantity,l.cost_atax=l.cost_atax+m[v].combos[x].price*m[v].combos[x].quantity*m[v].quantity*(1+m[v].tax/100),l.inquantity=l.inquantity+m[v].combos[x].quantity*m[v].quantity):9===m[v].bill_type&&(g.type="beginning",l.cost_btax=l.cost_btax+m[v].combos[x].price*m[v].combos[x].quantity*m[v].quantity,l.cost_atax=l.cost_atax+m[v].combos[x].price*m[v].combos[x].quantity*m[v].quantity*(1+m[v].tax/100),l.inquantity=l.inquantity+m[v].combos[x].quantity*m[v].quantity));g.price_atax=Math.round(1e6*g.price_atax)/1e6,g.payment_atax=Math.round(1e6*g.payment_atax)/1e6,l.docs.push(g),l.size++,l.empty=!1}console.log("getReportInputOutputInventory_Detail_byEndTime_byIDProduct"),i(l)}))}))},t.prototype.getReportInputOutputInventory_Detail_byTime_byIDProduct=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l=i.getlocalProduct(n),c={docs:new Array,empty:!0,size:0,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0},u=new Array,d=new Array;i.getlocalProductAndCombos(n).forEach((function(t){d.push(t._id)}));for(var _=0;_<d.length;_++)r="all"===o||void 0===o?{date:{$gte:t,$lte:e},id_product:{$eq:d[_]},bill_type:{$in:[1,10,15,30,2,3,9,31]}}:{date:{$gte:t,$lte:e},id_product:{$eq:d[_]},bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:o}},u[_]=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",r,{},{date:1},0);Promise.all(u).then((function(t){for(var e,n,o,i,s,r,u,d,_,p,b,f,h,y,m,v,g,x,q,w=t.flat(),P=0;P<w.length;P++){var D={id_bill:null===(e=w[P])||void 0===e?void 0:e.id_bill,bill_code:null===(n=w[P])||void 0===n?void 0:n.bill_code,bill_type:null===(o=w[P])||void 0===o?void 0:o.bill_type,date:null===(i=w[P])||void 0===i?void 0:i.date,name:l.name,unit:l.unit};if((null===(s=w[P])||void 0===s?void 0:s.id_cashier)&&(D.id_cashier=null===(r=w[P])||void 0===r?void 0:r.id_cashier),(null===(u=w[P])||void 0===u?void 0:u.id_employee)&&(D.id_employee=null===(d=w[P])||void 0===d?void 0:d.id_employee),(null===(_=w[P])||void 0===_?void 0:_.id_customer)&&(D.id_customer=null===(p=w[P])||void 0===p?void 0:p.id_customer),(null===(b=w[P])||void 0===b?void 0:b.id_supplier)&&(D.id_supplier=null===(f=w[P])||void 0===f?void 0:f.id_supplier),1===w[P].ptype)D.price_btax=null===(h=w[P])||void 0===h?void 0:h.price,D.price_atax=(null===(y=w[P])||void 0===y?void 0:y.price)*(1+w[P].tax/100),D.payment_btax=(null===(m=w[P])||void 0===m?void 0:m.price)*(null===(v=w[P])||void 0===v?void 0:v.quantity),D.payment_atax=(null===(g=w[P])||void 0===g?void 0:g.price)*(null===(x=w[P])||void 0===x?void 0:x.quantity)*(1+w[P].tax/100),D.quantity=null===(q=w[P])||void 0===q?void 0:q.quantity,1===w[P].bill_type||10===w[P].bill_type||15===w[P].bill_type||30===w[P].bill_type?(D.type="output",c.revenue_btax=c.revenue_btax+w[P].price*w[P].quantity,c.revenue_atax=c.revenue_atax+w[P].price*w[P].quantity*(1+w[P].tax/100),c.outquantity=c.outquantity+w[P].quantity):2===w[P].bill_type||3===w[P].bill_type||31===w[P].bill_type?(D.type="input",c.cost_btax=c.cost_btax+w[P].price*w[P].quantity,c.cost_atax=c.cost_atax+w[P].price*w[P].quantity*(1+w[P].tax/100),c.inquantity=c.inquantity+w[P].quantity):9===w[P].bill_type&&(D.type="beginning",c.cost_btax=c.cost_btax+w[P].price*w[P].quantity,c.cost_atax=c.cost_atax+w[P].price*w[P].quantity*(1+w[P].tax/100),c.inquantity=c.inquantity+w[P].quantity);else if(5===w[P].ptype)for(var k=0;k<w[P].combos.length;k++)if(w[P].combos[k].id_product===l._id){D.price_btax=w[P].combos[k].price,D.price_atax=w[P].combos[k].price*(1+w[P].tax/100),D.payment_btax=w[P].combos[k].price*w[P].combos[k].quantity*w[P].quantity,D.payment_atax=w[P].combos[k].price*w[P].combos[k].quantity*w[P].quantity*(1+w[P].tax/100),D.quantity=w[P].combos[k].quantity*w[P].quantity,1===w[P].bill_type||10===w[P].bill_type||15===w[P].bill_type||30===w[P].bill_type?(D.type="output",c.revenue_btax=c.revenue_btax+w[P].combos[k].price*w[P].combos[k].quantity*w[P].quantity,c.revenue_atax=c.revenue_atax+w[P].combos[k].price*w[P].combos[k].quantity*w[P].quantity*(1+w[P].tax/100),c.outquantity=c.outquantity+w[P].combos[k].quantity*w[P].quantity):2===w[P].bill_type||3===w[P].bill_type||31===w[P].bill_type?(D.type="input",c.cost_btax=c.cost_btax+w[P].combos[k].price*w[P].combos[k].quantity*w[P].quantity,c.cost_atax=c.cost_atax+w[P].combos[k].price*w[P].combos[k].quantity*w[P].quantity*(1+w[P].tax/100),c.inquantity=c.inquantity+w[P].combos[k].quantity*w[P].quantity):9===w[P].bill_type&&(D.type="beginning",c.cost_btax=c.cost_btax+w[P].combos[k].price*w[P].combos[k].quantity*w[P].quantity,c.cost_atax=c.cost_atax+w[P].combos[k].price*w[P].combos[k].quantity*w[P].quantity*(1+w[P].tax/100),c.inquantity=c.inquantity+w[P].combos[k].quantity*w[P].quantity);break}D.price_atax=Math.round(1e6*D.price_atax)/1e6,D.payment_atax=Math.round(1e6*D.payment_atax)/1e6,c.docs.push(D),c.size++,c.empty=!1}console.log("getReportInputOutputInventory_Detail_byTime_byIDProduct"),a(c)}))}))},t.prototype.getReportInputOutput_byTime_byIDProduct=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Array;if("all"===n)r=i.vhAlgorithm.sortVietnamesebyASC(i.getlocalProducts(1),"name");else{var l=i.getlocalProduct(n);r.push(l)}var c={docs:new Array,empty:!0,size:0,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0};if(r.length>0){for(var u=void 0,d=new Array,_=[1,5],p=0;p<_.length;p++)u="all"===n?"all"===o||void 0===o?{date:{$gte:t,$lte:e},ptype:{$eq:_[p]},bill_type:{$in:[1,10,15,30,2,3,31]}}:{date:{$gte:t,$lte:e},ptype:{$eq:_[p]},bill_type:{$in:[1,10,15,30,2,3,31]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$gte:t,$lte:e},ptype:{$eq:_[p]},id_product:{$eq:n},bill_type:{$in:[1,10,15,30,2,3,31]}}:{date:{$gte:t,$lte:e},ptype:{$eq:_[p]},bill_type:{$in:[1,10,15,30,2,3,31]},id_branch:{$eq:o}},d[p]=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0);Promise.all(d).then((function(t){for(var e=t.flat(),n=0;n<r.length;n++){for(var o={_id:r[n]._id,name:r[n].name,type:r[n].type,unit:r[n].unit,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0},i=0;i<e.length;i++)if(1===e[i].ptype)e[i].id_product===r[n]._id&&(1===e[i].bill_type||10===e[i].bill_type||15===e[i].bill_type||30===e[i].bill_type?(o.revenue_btax=o.revenue_btax+e[i].price*e[i].quantity,o.revenue_atax=o.revenue_atax+e[i].price*e[i].quantity*(1+e[i].tax/100),o.outquantity=o.outquantity+e[i].quantity,c.revenue_btax=c.revenue_btax+e[i].price*e[i].quantity,c.revenue_atax=c.revenue_atax+e[i].price*e[i].quantity*(1+e[i].tax/100),c.outquantity=c.outquantity+e[i].quantity):2!==e[i].bill_type&&3!==e[i].bill_type&&31!==e[i].bill_type||(o.cost_btax=o.cost_btax+e[i].price*e[i].quantity,o.cost_atax=o.cost_atax+e[i].price*e[i].quantity*(1+e[i].tax/100),o.inquantity=o.inquantity+e[i].quantity,c.cost_btax=c.cost_btax+e[i].price*e[i].quantity,c.cost_atax=c.cost_atax+e[i].price*e[i].quantity*(1+e[i].tax/100),c.inquantity=c.inquantity+e[i].quantity));else if(5===e[i].ptype)for(var s=0;s<e[i].combos.length;s++)if(e[i].combos[s].id_product===r[n]._id){1===e[i].bill_type||10===e[i].bill_type||15===e[i].bill_type||30===e[i].bill_type?(o.revenue_btax=o.revenue_btax+e[i].combos[s].price*e[i].combos[s].quantity*e[i].quantity,o.revenue_atax=o.revenue_atax+e[i].combos[s].price*e[i].combos[s].quantity*e[i].quantity*(1+e[i].tax/100),o.outquantity=o.outquantity+e[i].combos[s].quantity*e[i].quantity,c.revenue_btax=c.revenue_btax+e[i].combos[s].price*e[i].combos[s].quantity*e[i].quantity,c.revenue_atax=c.revenue_atax+e[i].combos[s].price*e[i].combos[s].quantity*e[i].quantity*(1+e[i].tax/100),c.outquantity=c.outquantity+e[i].combos[s].quantity*e[i].quantity):2!==e[i].bill_type&&3!==e[i].bill_type&&31!==e[i].bill_type||(o.cost_btax=o.cost_btax+e[i].price*e[i].quantity,o.cost_atax=o.cost_atax+e[i].price*e[i].quantity*(1+e[i].tax/100),o.inquantity=o.inquantity+e[i].quantity,c.cost_btax=c.cost_btax+e[i].combos[s].price*e[i].combos[s].quantity*e[i].quantity,c.cost_atax=c.cost_atax+e[i].combos[s].price*e[i].combos[s].quantity*e[i].quantity*(1+e[i].tax/100),c.inquantity=c.inquantity+e[i].combos[s].quantity*e[i].quantity);break}0==o.inquantity&&0==o.outquantity||(o.revenue_atax=Math.round(1e6*o.revenue_atax)/1e6,o.cost_atax=Math.round(1e6*o.cost_atax)/1e6,o.index=c.size+1,c.docs.push(o),c.size++,c.empty=!1)}console.log("getReportInputOutput_byTime_byIDProduct"),a(c)}))}else console.log("server -> products khong ton tai trong CSDL: "),a(c)}))},t.prototype.getReportInputOutput_Detail_byTime_byIDProduct=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l=i.getlocalProduct(n),c={docs:new Array,empty:!0,size:0,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0},u=new Array,d=new Array;i.getlocalProductAndCombos(n).forEach((function(t){d.push(t._id)}));for(var _=0;_<d.length;_++)r="all"===o||void 0===o?{date:{$gte:t,$lte:e},id_product:{$eq:d[_]},bill_type:{$in:[1,10,15,30,2,3,31]}}:{date:{$gte:t,$lte:e},id_product:{$eq:d[_]},bill_type:{$in:[1,10,15,30,2,3,31]},id_branch:{$eq:o}},u[_]=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",r,{},{date:1},0);Promise.all(u).then((function(t){for(var e,n,o,i,s,r,u,d,_,p,b,f,h,y,m,v,g,x,q,w=t.flat(),P=0;P<w.length;P++){var D={id_bill:null===(e=w[P])||void 0===e?void 0:e.id_bill,bill_code:null===(n=w[P])||void 0===n?void 0:n.bill_code,bill_type:null===(o=w[P])||void 0===o?void 0:o.bill_type,date:null===(i=w[P])||void 0===i?void 0:i.date,name:l.name,unit:l.unit};if((null===(s=w[P])||void 0===s?void 0:s.id_cashier)&&(D.id_cashier=null===(r=w[P])||void 0===r?void 0:r.id_cashier),(null===(u=w[P])||void 0===u?void 0:u.id_employee)&&(D.id_employee=null===(d=w[P])||void 0===d?void 0:d.id_employee),(null===(_=w[P])||void 0===_?void 0:_.id_customer)&&(D.id_customer=null===(p=w[P])||void 0===p?void 0:p.id_customer),(null===(b=w[P])||void 0===b?void 0:b.id_supplier)&&(D.id_supplier=null===(f=w[P])||void 0===f?void 0:f.id_supplier),1===w[P].ptype)D.price_btax=null===(h=w[P])||void 0===h?void 0:h.price,D.price_atax=(null===(y=w[P])||void 0===y?void 0:y.price)*(1+w[P].tax/100),D.payment_btax=(null===(m=w[P])||void 0===m?void 0:m.price)*(null===(v=w[P])||void 0===v?void 0:v.quantity),D.payment_atax=(null===(g=w[P])||void 0===g?void 0:g.price)*(null===(x=w[P])||void 0===x?void 0:x.quantity)*(1+w[P].tax/100),D.quantity=null===(q=w[P])||void 0===q?void 0:q.quantity,1===w[P].bill_type||10===w[P].bill_type||15===w[P].bill_type||30===w[P].bill_type?(D.type="output",c.revenue_btax=c.revenue_btax+w[P].price*w[P].quantity,c.revenue_atax=c.revenue_atax+w[P].price*w[P].quantity*(1+w[P].tax/100),c.outquantity=c.outquantity+w[P].quantity):2!==w[P].bill_type&&3!==w[P].bill_type&&31!==w[P].bill_type||(D.type="input",c.cost_btax=c.cost_btax+w[P].price*w[P].quantity,c.cost_atax=c.cost_atax+w[P].price*w[P].quantity*(1+w[P].tax/100),c.inquantity=c.inquantity+w[P].quantity);else if(5===w[P].ptype)for(var k=0;k<w[P].combos.length;k++)w[P].combos[k].id_product===l._id&&(D.price_btax=w[P].combos[k].price,D.price_atax=w[P].combos[k].price*(1+w[P].tax/100),D.payment_btax=w[P].combos[k].price*w[P].combos[k].quantity*w[P].quantity,D.payment_atax=w[P].combos[k].price*w[P].combos[k].quantity*w[P].quantity*(1+w[P].tax/100),D.quantity=w[P].combos[k].quantity*w[P].quantity,1===w[P].bill_type||10===w[P].bill_type||15===w[P].bill_type||30===w[P].bill_type?(D.type="output",c.revenue_btax=c.revenue_btax+w[P].combos[k].price*w[P].combos[k].quantity*w[P].quantity,c.revenue_atax=c.revenue_atax+w[P].combos[k].price*w[P].combos[k].quantity*w[P].quantity*(1+w[P].tax/100),c.outquantity=c.outquantity+w[P].combos[k].quantity*w[P].quantity):2!==w[P].bill_type&&3!==w[P].bill_type&&31!==w[P].bill_type||(D.type="input",c.cost_btax=c.cost_btax+w[P].combos[k].price*w[P].combos[k].quantity*w[P].quantity,c.cost_atax=c.cost_atax+w[P].combos[k].price*w[P].combos[k].quantity*w[P].quantity*(1+w[P].tax/100),c.inquantity=c.inquantity+w[P].combos[k].quantity*w[P].quantity));D.price_atax=Math.round(1e6*D.price_atax)/1e6,D.payment_atax=Math.round(1e6*D.payment_atax)/1e6,c.docs.push(D),c.size++,c.empty=!1}a(c)}))}))},t.prototype.getReportProfit_byTime_byIDProduct=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r={docs:new Array,empty:!0,size:0,outquantity_sales:0,sales_btax:0,sales_atax:0,profit_sales_btax:0,profit_sales_atax:0,cost_outstock_sales_btax:0,cost_outstock_sales_atax:0,return_on_sales_btax:0,return_on_sales_atax:0},l=i.vhAuth.getStore(),c=new Array;if("all"===n)c=i.vhAlgorithm.sortVietnamesebyASC(i.getlocalProducts(1),"name");else{var u=i.getlocalProduct(n);c.push(u)}var d=null,_=null;if("all"===n)if("all"===o||void 0===o)console.log("trường hợp này chưa có hàm, liên hệ anh Huy viết");else{if(null!=c[0][o]&&null!=c[0][o].inventory)for(var p=0;p<c[0][o].inventory.length&&!(new Date(c[0][o].inventory[p].date).getTime()>t.getTime());p++)_=new Date(c[0][o].inventory[p].date),d=p;if(_){for(var b=!1,f=0;f<c.length;f++)null!=c[f][o]&&null!=c[f][o].inventory||(b=!0);if(b)return console.log("Vui lòng đồng bộ kho để lấy về dữ liệu mới nhất"),a(r)}}else if("all"===o||void 0===o)console.log("trường hợp này chưa có hàm, liên hệ anh Huy viết");else if(null!=c[0][o]&&null!=c[0][o].inventory)for(p=0;p<c[0][o].inventory.length&&!(new Date(c[0][o].inventory[p].date).getTime()>t.getTime());p++)_=new Date(c[0][o].inventory[p].date),d=p;if(_||(_=new Date(l.registrationdate)),c.length>0){var h,y=new Array;if("all"===n)h="all"===o||void 0===o?{date:{$gte:_,$lte:e},bill_type:{$in:[1,10,15,30,2,3,9,31]}}:{date:{$gte:_,$lte:e},bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:o}},y[0]=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",h,{},{date:1},0);else{var m=i.getlocalProductAndCombos(n);for(f=0;f<m.length;f++)h="all"===o||void 0===o?{date:{$gte:_,$lte:e},id_product:{$eq:m[f]._id},bill_type:{$in:[1,10,15,30,2,3,9,31]}}:{date:{$gte:_,$lte:e},id_product:{$eq:m[f]._id},bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:o}},y[f]=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",h,{},{date:1},0)}Promise.all(y).then((function(e){for(var n=e.flat(),i=0;i<c.length;i++){for(var s={stock_first:0,cost_stock_first_btax:0,cost_stock_first_atax:0},l={_id:c[i]._id,name:c[i].name,type:c[i].type,unit:c[i].unit,outquantity_sales:0,sales_btax:0,sales_atax:0,profit_sales_btax:0,profit_sales_atax:0,cost_outstock_sales_btax:0,cost_outstock_sales_atax:0,return_on_sales_btax:0,return_on_sales_atax:0,outquantity:0,inquantity:0,stock_first:0,stock_last:0,cost_stock_first_btax:0,cost_stock_first_atax:0,cost_stock_last_btax:0,cost_stock_last_atax:0,cost_stock_average_btax:0,cost_stock_average_atax:0},u=0,_=0,p=0,b=0,f=0,h=0,y=0,m=0;m<n.length;m++)if(1===n[m].ptype){if(n[m].id_product===c[i]._id){var v=new Date(n[m].date);1===n[m].bill_type||10===n[m].bill_type||15===n[m].bill_type||30===n[m].bill_type?v>=new Date(t)?(l.sales_btax=l.sales_btax+n[m].price*n[m].quantity,l.sales_atax=l.sales_atax+n[m].price*n[m].quantity*(1+n[m].tax/100),l.outquantity_sales=l.outquantity_sales+n[m].quantity,l.outquantity=l.outquantity+n[m].quantity,r.sales_btax=r.sales_btax+n[m].price*n[m].quantity,r.sales_atax=r.sales_atax+n[m].price*n[m].quantity*(1+n[m].tax/100),r.outquantity_sales=r.outquantity_sales+n[m].quantity):u+=n[m].quantity:3===n[m].bill_type?(v>=new Date(t)?(l.sales_btax=l.sales_btax-n[m].price*n[m].quantity,l.sales_atax=l.sales_atax-n[m].price*n[m].quantity*(1+n[m].tax/100),l.outquantity_sales=l.outquantity_sales-n[m].quantity,r.sales_btax=r.sales_btax-n[m].price*n[m].quantity,r.sales_atax=r.sales_atax-n[m].price*n[m].quantity*(1+n[m].tax/100),r.outquantity_sales=r.outquantity_sales-n[m].quantity,l.inquantity=l.inquantity+n[m].quantity):(_+=n[m].quantity,p+=n[m].price*n[m].quantity,b+=n[m].price*n[m].quantity*(1+n[m].tax/100)),f+=n[m].quantity,h+=n[m].price*n[m].quantity,y+=n[m].price*n[m].quantity*(1+n[m].tax/100)):2!==n[m].bill_type&&9!==n[m].bill_type&&31!==n[m].bill_type||(v>=new Date(t)?l.inquantity=l.inquantity+n[m].quantity:(_+=n[m].quantity,p+=n[m].price*n[m].quantity,b+=n[m].price*n[m].quantity*(1+n[m].tax/100)),f+=n[m].quantity,h+=n[m].price*n[m].quantity,y+=n[m].price*n[m].quantity*(1+n[m].tax/100))}}else if(5===n[m].ptype)for(var g=0;g<n[m].combos.length;g++)if(n[m].combos[g].id_product===c[i]._id){v=new Date(n[m].date);1===n[m].bill_type||10===n[m].bill_type||15===n[m].bill_type||30===n[m].bill_type?v>=new Date(t)?(l.sales_btax=l.sales_btax+n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity,l.sales_atax=l.sales_atax+n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity*(1+n[m].tax/100),l.outquantity=l.outquantity+n[m].combos[g].quantity*n[m].quantity,r.sales_btax=r.sales_btax+n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity,r.sales_atax=r.sales_atax+n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity*(1+n[m].tax/100),r.outquantity=r.outquantity+n[m].combos[g].quantity*n[m].quantity):u+=n[m].combos[g].quantity*n[m].quantity:3===n[m].bill_type?(v>=new Date(t)?(l.sales_btax=l.sales_btax-n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity,l.sales_atax=l.sales_atax-n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity*(1+n[m].tax/100),l.outquantity_sales=l.outquantity_sales-n[m].combos[g].quantity*n[m].quantity,r.sales_btax=r.sales_btax-n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity,r.sales_atax=r.sales_atax-n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity*(1+n[m].tax/100),r.outquantity_sales=r.outquantity_sales-n[m].combos[g].quantity*n[m].quantity,l.inquantity=l.inquantity+n[m].combos[g].quantity*n[m].quantity):(p+=n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity,b+=n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity*(1+n[m].tax/100),_+=n[m].combos[g].quantity*n[m].quantity),f+=n[m].combos[g].quantity*n[m].quantity,h+=n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity,y+=n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity*(1+n[m].tax/100)):2!==n[m].bill_type&&9!==n[m].bill_type&&31!==n[m].bill_type||(v>=new Date(t)?l.inquantity=l.inquantity+n[m].combos[g].quantity*n[m].quantity:(p+=n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity,b+=n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity*(1+n[m].tax/100),_+=n[m].combos[g].quantity*n[m].quantity),f+=n[m].combos[g].quantity*n[m].quantity,h+=n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity,y+=n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity*(1+n[m].tax/100));break}if(null!=d&&(s=Object.assign({},c[i][o].inventory[d])),l.stock_first=s.stock_first+_-u,l.stock_last=l.stock_first+l.inquantity-l.outquantity,s.stock_first+_!=0&&(l.cost_stock_first_btax=(s.cost_stock_first_btax+p)/(s.stock_first+_)*l.stock_first,l.cost_stock_first_atax=(s.cost_stock_first_atax+b)/(s.stock_first+_)*l.stock_first),s.stock_first+f!=0&&(l.cost_stock_last_btax=(s.cost_stock_first_btax+h)/(s.stock_first+f)*l.stock_last,l.cost_stock_last_atax=(s.cost_stock_first_atax+y)/(s.stock_first+f)*l.stock_last),s.stock_first>0?(l.cost_stock_average_btax=(s.cost_stock_first_btax+h)/(s.stock_first+f),l.cost_stock_average_atax=(s.cost_stock_first_atax+y)/(s.stock_first+f)):0!=f&&(l.cost_stock_average_btax=h/f,l.cost_stock_average_atax=y/f),l.cost_outstock_sales_btax=l.cost_stock_average_btax*l.outquantity_sales,l.cost_outstock_sales_atax=l.cost_stock_average_atax*l.outquantity_sales,l.profit_sales_btax=l.sales_btax-l.cost_stock_average_btax*l.outquantity_sales,l.profit_sales_atax=l.sales_atax-l.cost_stock_average_atax*l.outquantity_sales,0!=l.sales_btax?l.return_on_sales_btax=l.profit_sales_btax/l.sales_btax:l.profit_sales_btax>0?l.return_on_sales_btax=1/0:l.profit_sales_btax<0?l.return_on_sales_btax=-1/0:0===l.profit_sales_btax&&(l.return_on_sales_btax=0),0!=l.sales_atax?l.return_on_sales_atax=l.profit_sales_atax/l.sales_atax:l.profit_sales_atax>0?l.return_on_sales_atax=1/0:l.profit_sales_atax<0?l.return_on_sales_atax=-1/0:0==l.profit_sales_atax&&(l.return_on_sales_atax=0),r.profit_sales_btax=r.profit_sales_btax+l.profit_sales_btax,r.profit_sales_atax=r.profit_sales_atax+l.profit_sales_atax,r.cost_outstock_sales_btax=r.cost_outstock_sales_btax+l.cost_outstock_sales_btax,r.cost_outstock_sales_atax=r.cost_outstock_sales_atax+l.cost_outstock_sales_atax,0!=r.sales_btax&&(r.return_on_sales_btax=r.profit_sales_btax/r.sales_btax),0!=r.sales_atax&&(r.return_on_sales_atax=r.profit_sales_atax/r.sales_atax),l.sales_atax=Math.round(1e6*l.sales_atax)/1e6,l.profit_sales_atax=Math.round(1e6*l.profit_sales_atax)/1e6,l.return_on_sales_atax=Math.round(1e6*l.return_on_sales_atax)/1e6,l.index=r.size+1,l.outquantity>0){var x={_id:l._id,name:l.name,type:l.type,unit:l.unit,outquantity_sales:l.outquantity_sales,sales_btax:l.sales_btax,sales_atax:l.sales_atax,profit_sales_btax:l.profit_sales_btax,profit_sales_atax:l.profit_sales_atax,cost_outstock_sales_btax:l.cost_outstock_sales_btax,cost_outstock_sales_atax:l.cost_outstock_sales_atax,return_on_sales_btax:l.return_on_sales_btax,return_on_sales_atax:l.return_on_sales_atax};r.docs.push(x),r.size++,r.empty=!1}}a(r),console.log("getReportProfit_byTime_byIDProduct",r)}))}else console.log("server -> products khong ton tai trong CSDL: "),a(r)}))},t.prototype.getReportInputOutputInventory_byTime_byIDProduct1=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Array;if("all"===n)r=i.vhAlgorithm.sortVietnamesebyASC(i.getlocalProducts(1),"name");else{var l=i.getlocalProduct(n);r.push(l)}var c={docs:new Array,empty:!0,size:0,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0,stock_first:0,stock_last:0,cost_stock_first_btax:0,cost_stock_first_atax:0,cost_stock_last_btax:0,cost_stock_last_atax:0};if(r.length>0){for(var u=void 0,d=new Array,_=[1,5],p=0;p<_.length;p++)u="all"===o||void 0===o?{date:{$lte:e},ptype:{$eq:_[p]},bill_type:{$in:[1,10,15,30,2,3,9,31]}}:{date:{$lte:e},ptype:{$eq:_[p]},bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:o}},d[p]=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0);Promise.all(d).then((function(e){for(var n=e.flat(),o=0;o<r.length;o++){for(var i={_id:r[o]._id,name:r[o].name,type:r[o].type,unit:r[o].unit,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0,stock_first:0,stock_last:0,cost_stock_first_btax:0,cost_stock_first_atax:0,cost_stock_last_btax:0,cost_stock_last_atax:0},s=0,l=0,u=0,d=0,_=0,p=0,b=0,f=0;f<n.length;f++)if(1===n[f].ptype){if(n[f].id_product===r[o]._id){var h=new Date(n[f].date);1===n[f].bill_type||10===n[f].bill_type||15===n[f].bill_type||30===n[f].bill_type?h>=new Date(t)?(i.revenue_btax=i.revenue_btax+n[f].price*n[f].quantity,i.revenue_atax=i.revenue_atax+n[f].price*n[f].quantity*(1+n[f].tax/100),i.outquantity=i.outquantity+n[f].quantity,c.revenue_btax=c.revenue_btax+n[f].price*n[f].quantity,c.revenue_atax=c.revenue_atax+n[f].price*n[f].quantity*(1+n[f].tax/100),c.outquantity=c.outquantity+n[f].quantity):s+=n[f].quantity:2!==n[f].bill_type&&3!==n[f].bill_type&&9!==n[f].bill_type&&31!==n[f].bill_type||(h>=new Date(t)?(i.cost_btax=i.cost_btax+n[f].price*n[f].quantity,i.cost_atax=i.cost_atax+n[f].price*n[f].quantity*(1+n[f].tax/100),i.inquantity=i.inquantity+n[f].quantity,c.cost_btax=c.cost_btax+n[f].price*n[f].quantity,c.cost_atax=c.cost_atax+n[f].price*n[f].quantity*(1+n[f].tax/100),c.inquantity=c.inquantity+n[f].quantity):(l+=n[f].quantity,u+=n[f].price*n[f].quantity,d+=n[f].price*n[f].quantity*(1+n[f].tax/100)),_+=n[f].quantity,p+=n[f].price*n[f].quantity,b+=n[f].price*n[f].quantity*(1+n[f].tax/100))}}else if(5===n[f].ptype)for(var y=0;y<n[f].combos.length;y++)if(n[f].combos[y].id_product===r[o]._id){h=new Date(n[f].date);1===n[f].bill_type||10===n[f].bill_type||15===n[f].bill_type||30===n[f].bill_type?h>=new Date(t)?(i.revenue_btax=i.revenue_btax+n[f].combos[y].price*n[f].combos[y].quantity*n[f].quantity,i.revenue_atax=i.revenue_atax+n[f].combos[y].price*n[f].combos[y].quantity*n[f].quantity*(1+n[f].tax/100),i.outquantity=i.outquantity+n[f].combos[y].quantity*n[f].quantity,c.revenue_btax=c.revenue_btax+n[f].combos[y].price*n[f].combos[y].quantity*n[f].quantity,c.revenue_atax=c.revenue_atax+n[f].combos[y].price*n[f].combos[y].quantity*n[f].quantity*(1+n[f].tax/100),c.outquantity=c.outquantity+n[f].combos[y].quantity*n[f].quantity):s+=n[f].combos[y].quantity*n[f].quantity:2!==n[f].bill_type&&3!==n[f].bill_type&&9!==n[f].bill_type&&31!==n[f].bill_type||(h>=new Date(t)?(i.cost_btax=i.cost_btax+n[f].combos[y].price*n[f].combos[y].quantity*n[f].quantity,i.cost_atax=i.cost_atax+n[f].combos[y].price*n[f].combos[y].quantity*n[f].quantity*(1+n[f].tax/100),i.inquantity=i.inquantity+n[f].combos[y].quantity*n[f].quantity,c.cost_btax=c.cost_btax+n[f].combos[y].price*n[f].combos[y].quantity*n[f].quantity,c.cost_atax=c.cost_atax+n[f].combos[y].price*n[f].combos[y].quantity*n[f].quantity*(1+n[f].tax/100),c.inquantity=c.inquantity+n[f].combos[y].quantity*n[f].quantity):(u+=n[f].combos[y].price*n[f].combos[y].quantity*n[f].quantity,d+=n[f].combos[y].price*n[f].combos[y].quantity*n[f].quantity*(1+n[f].tax/100),l+=n[f].combos[y].quantity*n[f].quantity),_+=n[f].combos[y].quantity*n[f].quantity,p+=n[f].combos[y].price*n[f].combos[y].quantity*n[f].quantity,b+=n[f].combos[y].price*n[f].combos[y].quantity*n[f].quantity*(1+n[f].tax/100));break}i.stock_first=l-s,i.stock_last=i.stock_first+i.inquantity-i.outquantity,0!=l&&(i.cost_stock_first_btax=u/l*i.stock_first),0!=l&&(i.cost_stock_first_atax=d/l*i.stock_first),0!=_&&(i.cost_stock_last_btax=p/_*i.stock_last),0!=_&&(i.cost_stock_last_atax=b/_*i.stock_last),c.stock_first=c.stock_first+i.stock_first,c.stock_last=c.stock_last+i.stock_last,c.cost_stock_first_btax=c.cost_stock_first_btax+i.cost_stock_first_btax,c.cost_stock_first_atax=c.cost_stock_first_atax+i.cost_stock_first_atax,c.cost_stock_last_btax=c.cost_stock_last_btax+i.cost_stock_last_btax,c.cost_stock_last_atax=c.cost_stock_last_atax+i.cost_stock_last_atax,i.revenue_atax=Math.round(1e6*i.revenue_atax)/1e6,i.cost_atax=Math.round(1e6*i.cost_atax)/1e6,i.cost_stock_first_atax=Math.round(1e6*i.cost_stock_first_atax)/1e6,i.cost_stock_last_atax=Math.round(1e6*i.cost_stock_last_atax)/1e6,i.index=c.size+1,c.docs.push(i),c.size++,c.empty=!1}a(c),console.log("getReportInputOutputInventory_byTime_byIDProduct")}))}else console.log("server -> products khong ton tai trong CSDL: "),a(c)}))},t.prototype.syncInventoryEveryDay_StockBeginning=function(){var t=this;return new Promise((function(e,n){for(var o=t.getlocalProducts(1),i=t.getlocalBranchs(),a=new Array,s=function(e){a[e]=new Promise((function(n){var a=i[e]._id,s={bill_type:{$eq:9},id_branch:{$eq:a}};t.vhmongo_firebase.database().getDocsByFields("vhbill_details",s,{},{date:1},0).then((function(e){var i=new Array;if(e.length>0)for(var s=0;s<o.length;s++){for(var r=0,l=0,c=0,u=0,d=0,_=0;_<e.length;_++)1===e[_].ptype&&e[_].id_product===o[s]._id&&(r+=e[_].quantity,l+=e[_].price*e[_].quantity,c+=e[_].price*e[_].quantity*(1+e[_].tax/100));if(0!=r){u=l/r,d=c/r;var p={};null!=o[s][a]?p[a]=o[s][a]:p[a]={},p[a].stock_beginning=r,p[a].unit_cost_stock_beginning_btax=u,p[a].unit_cost_stock_beginning_atax=d,p[a].cost_stock_beginning_btax=l,p[a].cost_stock_beginning_atax=c,i.push(t.vhmongo_firebase.database().updateDoc("products",o[s]._id,Object.assign({},p)))}}Promise.all(i).then((function(){n(null)}))}))}))},r=0;r<i.length;r++)s(r);Promise.all(a).then((function(){e(null)}))}))},t.prototype.syncInventoryEveryDay_Stock1stDayOfMonth=function(){var t=this;return new Promise((function(e,n){var o=t.vhAuth.getStore(),i=[Object.assign({},t.getDefaultBranch())];t.vhmongo_firebase.auth().getServerDate().then((function(n){var a=t.get1stDayOfMonthArray(o.registrationdate,n);if(a.length>0){for(var s=new Array,r=function(e){s[e]=new Promise((function(n){for(var o=i[e]._id,s=t.getlocalProducts(1),r=s.length,l=new Array,c=0;c<s.length;c++)l.push(c);var u=!0,d=l.splice(0,10),_=setInterval((function(){if(u){u=!1;for(var i=new Array,c=function(e){i[i.length]=new Promise((function(n){if(null!=s[e][o]&&null!=s[e][o].inventory){var i=s[e][o].inventory[s[e][o].inventory.length-1],l=s[e][o].inventory.length;if(new Date(i.date).getTime()<new Date(a[a.length-1]).getTime()){for(var c=l;c<a.length;c++)s[e][o].inventory[c]={},s[e][o].inventory[c].date=a[c],s[e][o].inventory[c].inquantity_tofirst=i.inquantity_tofirst,s[e][o].inventory[c].pay_tofirst_btax=i.pay_tofirst_btax,s[e][o].inventory[c].pay_tofirst_atax=i.pay_tofirst_atax,s[e][o].inventory[c].outquantity_tofirst=i.outquantity_tofirst,s[e][o].inventory[c].sales_tofirst_btax=i.sales_tofirst_btax,s[e][o].inventory[c].sales_tofirst_atax=i.sales_tofirst_atax,s[e][o].inventory[c].stock_first=0,s[e][o].inventory[c].unit_cost_stock_first_btax=0,s[e][o].inventory[c].unit_cost_stock_first_atax=0,s[e][o].inventory[c].cost_stock_first_btax=0,s[e][o].inventory[c].cost_stock_first_atax=0,s[e][o].inventory[c].profit_first_btax=0,s[e][o].inventory[c].profit_first_atax=0;var u=new Array,d=new Array;t.getlocalProductAndCombos(s[e]._id).forEach((function(t){d.push(t._id)}));for(var _=0;_<d.length;_++){var p={date:{$gte:new Date(i.date),$lte:new Date(a[a.length-1])},bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:o},id_product:{$eq:d[_]}};u[_]=t.vhmongo_firebase.database().getDocsByFields("vhbill_details",p,{},{date:1},0)}Promise.all(u).then((function(i){var c=i.flat();if(c.length>0)for(var u=0;u<c.length;u++)if(1===c[u].ptype){if(c[u].id_product===s[e]._id)for(var d=l;d<a.length;d++)new Date(c[u].date).getTime()<new Date(s[e][o].inventory[d].date).getTime()&&(1===c[u].bill_type||10===c[u].bill_type||15===c[u].bill_type||30===c[u].bill_type?(s[e][o].inventory[d].outquantity_tofirst=s[e][o].inventory[d].outquantity_tofirst+c[u].quantity,s[e][o].inventory[d].sales_tofirst_btax=s[e][o].inventory[d].sales_tofirst_btax+c[u].price*c[u].quantity,s[e][o].inventory[d].sales_tofirst_atax=s[e][o].inventory[d].sales_tofirst_atax+c[u].price*c[u].quantity*(1+c[u].tax/100)):2!==c[u].bill_type&&3!==c[u].bill_type&&9!==c[u].bill_type&&31!==c[u].bill_type||(s[e][o].inventory[d].inquantity_tofirst=s[e][o].inventory[d].inquantity_tofirst+c[u].quantity,s[e][o].inventory[d].pay_tofirst_btax=s[e][o].inventory[d].pay_tofirst_btax+c[u].price*c[u].quantity,s[e][o].inventory[d].pay_tofirst_atax=s[e][o].inventory[d].pay_tofirst_atax+c[u].price*c[u].quantity*(1+c[u].tax/100)))}else if(5===c[u].ptype)for(var _=0;_<c[u].combos.length;_++)if(c[u].combos[_].id_product===s[e]._id)for(d=l;d<a.length;d++)new Date(c[u].date).getTime()<new Date(s[e][o].inventory[d].date).getTime()&&(1===c[u].bill_type||10===c[u].bill_type||15===c[u].bill_type||30===c[u].bill_type?(s[e][o].inventory[d].outquantity_tofirst=s[e][o].inventory[d].outquantity_tofirst+c[u].combos[_].quantity*c[u].quantity,s[e][o].inventory[d].sales_tofirst_btax=s[e][o].inventory[d].sales_tofirst_btax+c[u].combos[_].price*c[u].combos[_].quantity*c[u].quantity,s[e][o].inventory[d].sales_tofirst_atax=s[e][o].inventory[d].sales_tofirst_atax+c[u].combos[_].price*c[u].combos[_].quantity*c[u].quantity*(1+c[u].tax/100)):2!==c[u].bill_type&&3!==c[u].bill_type&&9!==c[u].bill_type&&31!==c[u].bill_type||(s[e][o].inventory[d].inquantity_tofirst=s[e][o].inventory[d].inquantity_tofirst+c[u].combos[_].quantity*c[u].quantity,s[e][o].inventory[d].pay_tofirst_btax=s[e][o].inventory[d].pay_tofirst_btax+c[u].combos[_].price*c[u].combos[_].quantity*c[u].quantity,s[e][o].inventory[d].pay_tofirst_atax=s[e][o].inventory[d].pay_tofirst_atax+c[u].combos[_].price*c[u].combos[_].quantity*c[u].quantity*(1+c[u].tax/100)));for(d=l;d<a.length;d++){var p=s[e][o].inventory[d].inquantity_tofirst-s[e][o].inventory[d-1].inquantity_tofirst,b=s[e][o].inventory[d].pay_tofirst_btax-s[e][o].inventory[d-1].pay_tofirst_btax,f=s[e][o].inventory[d].pay_tofirst_atax-s[e][o].inventory[d-1].pay_tofirst_atax;s[e][o].inventory[d].stock_first=s[e][o].inventory[d].inquantity_tofirst-s[e][o].inventory[d].outquantity_tofirst,s[e][o].inventory[d-1].stock_first+p!=0&&(s[e][o].inventory[d].unit_cost_stock_first_btax=(s[e][o].inventory[d-1].cost_stock_first_btax+b)/(s[e][o].inventory[d-1].stock_first+p),s[e][o].inventory[d].unit_cost_stock_first_atax=(s[e][o].inventory[d-1].cost_stock_first_atax+f)/(s[e][o].inventory[d-1].stock_first+p),s[e][o].inventory[d].cost_stock_first_btax=s[e][o].inventory[d].unit_cost_stock_first_btax*s[e][o].inventory[d].stock_first,s[e][o].inventory[d].cost_stock_first_atax=s[e][o].inventory[d].unit_cost_stock_first_atax*s[e][o].inventory[d].stock_first);var h=s[e][o].inventory[d].outquantity_tofirst-s[e][o].inventory[d-1].outquantity_tofirst,y=s[e][o].inventory[d].unit_cost_stock_first_btax*h,m=s[e][o].inventory[d].unit_cost_stock_first_atax*h,v=s[e][o].inventory[d].sales_tofirst_btax-s[e][o].inventory[d-1].sales_tofirst_btax,g=s[e][o].inventory[d].sales_tofirst_atax-s[e][o].inventory[d-1].sales_tofirst_atax;s[e][o].inventory[d].profit_first_btax=v-y,s[e][o].inventory[d].profit_first_atax=g-m}r--;var x=t.getlocalProduct(s[e]._id),q={};null!=x[o]?(q[o]=x[o],q[o].inventory=s[e][o].inventory):q[o]=s[e][o],t.vhmongo_firebase.database().updateDoc("products",s[e]._id,Object.assign({},q)).then((function(){console.log(e,s[e]),n(!0)}))}))}else n(null)}else{u=new Array;var b=new Array;t.getlocalProductAndCombos(s[e]._id).forEach((function(t){b.push(t._id)}));for(_=0;_<b.length;_++){p={bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:o},id_product:{$eq:b[_]}};u[_]=t.vhmongo_firebase.database().getDocsByFields("vhbill_details",p,{},{date:1},0)}Promise.all(u).then((function(i){var l=i.flat();s[e][o]={},s[e][o].inventory=new Array;for(var c=0;c<a.length;c++)s[e][o].inventory[c]={},s[e][o].inventory[c].date=a[c],s[e][o].inventory[c].inquantity_tofirst=0,s[e][o].inventory[c].pay_tofirst_btax=0,s[e][o].inventory[c].pay_tofirst_atax=0,s[e][o].inventory[c].outquantity_tofirst=0,s[e][o].inventory[c].sales_tofirst_btax=0,s[e][o].inventory[c].sales_tofirst_atax=0,s[e][o].inventory[c].stock_first=0,s[e][o].inventory[c].unit_cost_stock_first_btax=0,s[e][o].inventory[c].unit_cost_stock_first_atax=0,s[e][o].inventory[c].cost_stock_first_btax=0,s[e][o].inventory[c].cost_stock_first_atax=0,s[e][o].inventory[c].profit_first_btax=0,s[e][o].inventory[c].profit_first_atax=0;if(l.length>0){for(var u=0;u<l.length;u++)if(1===l[u].ptype){if(l[u].id_product===s[e]._id)for(c=0;c<s[e][o].inventory.length;c++)new Date(l[u].date).getTime()<new Date(s[e][o].inventory[c].date).getTime()&&(1===l[u].bill_type||10===l[u].bill_type||15===l[u].bill_type||30===l[u].bill_type?(s[e][o].inventory[c].outquantity_tofirst=s[e][o].inventory[c].outquantity_tofirst+l[u].quantity,s[e][o].inventory[c].sales_tofirst_btax=s[e][o].inventory[c].sales_tofirst_btax+l[u].price*l[u].quantity,s[e][o].inventory[c].sales_tofirst_atax=s[e][o].inventory[c].sales_tofirst_atax+l[u].price*l[u].quantity*(1+l[u].tax/100)):2!==l[u].bill_type&&3!==l[u].bill_type&&9!==l[u].bill_type&&31!==l[u].bill_type||(s[e][o].inventory[c].inquantity_tofirst=s[e][o].inventory[c].inquantity_tofirst+l[u].quantity,s[e][o].inventory[c].pay_tofirst_btax=s[e][o].inventory[c].pay_tofirst_btax+l[u].price*l[u].quantity,s[e][o].inventory[c].pay_tofirst_atax=s[e][o].inventory[c].pay_tofirst_atax+l[u].price*l[u].quantity*(1+l[u].tax/100)))}else if(5===l[u].ptype)for(var d=0;d<l[u].combos.length;d++)if(l[u].combos[d].id_product===s[e]._id)for(c=0;c<s[e][o].inventory.length;c++)new Date(l[u].date).getTime()<new Date(s[e][o].inventory[c].date).getTime()&&(1===l[u].bill_type||10===l[u].bill_type||15===l[u].bill_type||30===l[u].bill_type?(s[e][o].inventory[c].outquantity_tofirst=s[e][o].inventory[c].outquantity_tofirst+l[u].combos[d].quantity*l[u].quantity,s[e][o].inventory[c].sales_tofirst_btax=s[e][o].inventory[c].sales_tofirst_btax+l[u].combos[d].price*l[u].combos[d].quantity*l[u].quantity,s[e][o].inventory[c].sales_tofirst_atax=s[e][o].inventory[c].sales_tofirst_atax+l[u].combos[d].price*l[u].combos[d].quantity*l[u].quantity*(1+l[u].tax/100)):2!==l[u].bill_type&&3!==l[u].bill_type&&9!==l[u].bill_type&&31!==l[u].bill_type||(s[e][o].inventory[c].inquantity_tofirst=s[e][o].inventory[c].inquantity_tofirst+l[u].combos[d].quantity*l[u].quantity,s[e][o].inventory[c].pay_tofirst_btax=s[e][o].inventory[c].pay_tofirst_btax+l[u].combos[d].price*l[u].combos[d].quantity*l[u].quantity,s[e][o].inventory[c].pay_tofirst_atax=s[e][o].inventory[c].pay_tofirst_atax+l[u].combos[d].price*l[u].combos[d].quantity*l[u].quantity*(1+l[u].tax/100)));for(c=0;c<s[e][o].inventory.length;c++)if(0===c){var _=s[e][o].inventory[0].inquantity_tofirst,p=s[e][o].inventory[0].pay_tofirst_btax,b=s[e][o].inventory[0].pay_tofirst_atax;s[e][o].inventory[0].stock_first=s[e][o].inventory[0].inquantity_tofirst-s[e][o].inventory[0].outquantity_tofirst,0!=_&&(s[e][o].inventory[0].unit_cost_stock_first_btax=p/_,s[e][o].inventory[0].unit_cost_stock_first_atax=b/_,s[e][o].inventory[0].cost_stock_first_btax=s[e][o].inventory[0].unit_cost_stock_first_btax*s[e][o].inventory[0].stock_first,s[e][o].inventory[0].cost_stock_first_atax=s[e][o].inventory[0].unit_cost_stock_first_atax*s[e][o].inventory[0].stock_first);var f=s[e][o].inventory[0].outquantity_tofirst,h=s[e][o].inventory[0].unit_cost_stock_first_btax*f,y=s[e][o].inventory[0].unit_cost_stock_first_atax*f,m=s[e][o].inventory[0].sales_tofirst_btax,v=s[e][o].inventory[0].sales_tofirst_atax;s[e][o].inventory[0].profit_first_btax=m-h,s[e][o].inventory[0].profit_first_atax=v-y}else{_=s[e][o].inventory[c].inquantity_tofirst-s[e][o].inventory[c-1].inquantity_tofirst,p=s[e][o].inventory[c].pay_tofirst_btax-s[e][o].inventory[c-1].pay_tofirst_btax,b=s[e][o].inventory[c].pay_tofirst_atax-s[e][o].inventory[c-1].pay_tofirst_atax;s[e][o].inventory[c].stock_first=s[e][o].inventory[c].inquantity_tofirst-s[e][o].inventory[c].outquantity_tofirst,s[e][o].inventory[c-1].stock_first+_!=0&&(s[e][o].inventory[c].unit_cost_stock_first_btax=(s[e][o].inventory[c-1].cost_stock_first_btax+p)/(s[e][o].inventory[c-1].stock_first+_),s[e][o].inventory[c].unit_cost_stock_first_atax=(s[e][o].inventory[c-1].cost_stock_first_atax+b)/(s[e][o].inventory[c-1].stock_first+_),s[e][o].inventory[c].cost_stock_first_btax=s[e][o].inventory[c].unit_cost_stock_first_btax*s[e][o].inventory[c].stock_first,s[e][o].inventory[c].cost_stock_first_atax=s[e][o].inventory[c].unit_cost_stock_first_atax*s[e][o].inventory[c].stock_first);f=s[e][o].inventory[c].outquantity_tofirst-s[e][o].inventory[c-1].outquantity_tofirst,h=s[e][o].inventory[c].unit_cost_stock_first_btax*f,y=s[e][o].inventory[c].unit_cost_stock_first_atax*f,m=s[e][o].inventory[c].sales_tofirst_btax-s[e][o].inventory[c-1].sales_tofirst_btax,v=s[e][o].inventory[c].sales_tofirst_atax-s[e][o].inventory[c-1].sales_tofirst_atax;s[e][o].inventory[c].profit_first_btax=m-h,s[e][o].inventory[c].profit_first_atax=v-y}}r--;var g=t.getlocalProduct(s[e]._id),x={};null!=g[o]?(x[o]=g[o],x[o].inventory=s[e][o].inventory):x[o]=s[e][o],t.vhmongo_firebase.database().updateDoc("products",s[e]._id,Object.assign({},x)).then((function(){console.log(e,s[e]),n(!0)}))}))}}))},p=d[0];p<=d[d.length-1];p++)c(p);Promise.all(i).then((function(t){r<=0&&(n(e),clearInterval(_)),l.length>0?(u=!0,d=l.splice(0,10)):(n(e),clearInterval(_))}))}}),10)}))},l=0;l<i.length;l++)r(l);Promise.all(s).then((function(t){console.log("syncInventoryEveryDay_Stock1stDayOfMonth",t),e(null)}))}else console.log("syncInventoryEveryDay_Stock1stDayOfMonth"),e(null)}))}))},t.prototype.syncInventoryEveryDay1=function(){var t=this;return new Promise((function(e,n){var o=t.getlocalProducts(1);console.log(o,o);for(var i=new Array,a=0;a<o.length;a++)i.push(a);var s=t.vhAuth.getStore(),r=t.getlocalBranchs();t.vhmongo_firebase.auth().getServerDate().then((function(n){var a=t.get1stDayOfMonthArray(s.registrationdate,n);if(a.length>0){for(var l=new Array,c=function(e){l[e]=new Promise((function(n){var s=r[e]._id,l=!0,c=i.splice(0,1),u=setInterval((function(){if(l){l=!1;for(var r=new Array,d=function(e){r[e]=new Promise((function(n){if(null!=o[e][s]&&null!=o[e][s].inventory){var i=o[e][s].inventory[o[e][s].inventory.length-1];if(new Date(i.date).getTime()!=new Date(a[a.length-1]).getTime()){for(var r=o[e][s].inventory.length;r<a.length;r++)o[e][s].inventory[r]={},o[e][s].inventory[r].date=a[r],o[e][s].inventory[r].inquantity_tofirst=i.inquantity_tofirst,o[e][s].inventory[r].pay_tofirst_btax=i.pay_tofirst_btax,o[e][s].inventory[r].pay_tofirst_atax=i.pay_tofirst_atax,o[e][s].inventory[r].outquantity_tofirst=i.outquantity_tofirst,o[e][s].inventory[r].sales_tofirst_btax=i.sales_tofirst_btax,o[e][s].inventory[r].sales_tofirst_atax=i.sales_tofirst_atax,o[e][s].inventory[r].stock_first=0,o[e][s].inventory[r].unit_cost_stock_first_btax=0,o[e][s].inventory[r].unit_cost_stock_first_atax=0,o[e][s].inventory[r].cost_stock_first_btax=0,o[e][s].inventory[r].cost_stock_first_atax=0,o[e][s].inventory[r].profit_first_btax=0,o[e][s].inventory[r].profit_first_atax=0;var l=new Array,c=new Array;t.getlocalProductAndCombos(o[e]._id).forEach((function(t){c.push(t._id)}));for(var u=0;u<c.length;u++){var d={date:{$gte:new Date(i.date)},bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:s},id_product:{$eq:c[u]}};l[u]=t.vhmongo_firebase.database().getDocsByFields("vhbill_details",d,{},{date:1},0)}Promise.all(l).then((function(t){var i=t.flat();if(i.length>0){for(var a=0;a<i.length;a++)if(1===i[a].ptype){if(i[a].id_product===o[e]._id)for(var r=0;r<o[e][s].inventory.length;r++)new Date(i[a].date).getTime()<new Date(o[e][s].inventory[r].date).getTime()&&(1===i[a].bill_type||10===i[a].bill_type||15===i[a].bill_type||30===i[a].bill_type?(o[e][s].inventory[r].outquantity_tofirst=o[e][s].inventory[r].outquantity_tofirst+i[a].quantity,o[e][s].inventory[r].sales_tofirst_btax=o[e][s].inventory[r].sales_tofirst_btax+i[a].price*i[a].quantity,o[e][s].inventory[r].sales_tofirst_atax=o[e][s].inventory[r].sales_tofirst_atax+i[a].price*i[a].quantity*(1+i[a].tax/100)):2!==i[a].bill_type&&3!==i[a].bill_type&&9!==i[a].bill_type&&31!==i[a].bill_type||(o[e][s].inventory[r].inquantity_tofirst=o[e][s].inventory[r].inquantity_tofirst+i[a].quantity,o[e][s].inventory[r].pay_tofirst_btax=o[e][s].inventory[r].pay_tofirst_btax+i[a].price*i[a].quantity,o[e][s].inventory[r].pay_tofirst_atax=o[e][s].inventory[r].pay_tofirst_atax+i[a].price*i[a].quantity*(1+i[a].tax/100)))}else if(5===i[a].ptype)for(var l=0;l<i[a].combos.length;l++)if(i[a].combos[l].id_product===o[e]._id)for(r=0;r<o[e][s].inventory.length;r++)new Date(i[a].date).getTime()<new Date(o[e][s].inventory[r].date).getTime()&&(1===i[a].bill_type||10===i[a].bill_type||15===i[a].bill_type||30===i[a].bill_type?(o[e][s].inventory[r].outquantity_tofirst=o[e][s].inventory[r].outquantity_tofirst+i[a].combos[l].quantity*i[a].quantity,o[e][s].inventory[r].sales_tofirst_btax=o[e][s].inventory[r].sales_tofirst_btax+i[a].combos[l].price*i[a].combos[l].quantity*i[a].quantity,o[e][s].inventory[r].sales_tofirst_atax=o[e][s].inventory[r].sales_tofirst_atax+i[a].combos[l].price*i[a].combos[l].quantity*i[a].quantity*(1+i[a].tax/100)):2!==i[a].bill_type&&3!==i[a].bill_type&&9!==i[a].bill_type&&31!==i[a].bill_type||(o[e][s].inventory[r].inquantity_tofirst=o[e][s].inventory[r].inquantity_tofirst+i[a].combos[l].quantity*i[a].quantity,o[e][s].inventory[r].pay_tofirst_btax=o[e][s].inventory[r].pay_tofirst_btax+i[a].combos[l].price*i[a].combos[l].quantity*i[a].quantity,o[e][s].inventory[r].pay_tofirst_atax=o[e][s].inventory[r].pay_tofirst_atax+i[a].combos[l].price*i[a].combos[l].quantity*i[a].quantity*(1+i[a].tax/100)));for(r=0;r<o[e][s].inventory.length;r++)if(0===r){var c=o[e][s].inventory[0].inquantity_tofirst,u=o[e][s].inventory[0].pay_tofirst_btax,d=o[e][s].inventory[0].pay_tofirst_atax;o[e][s].inventory[0].stock_first=o[e][s].inventory[0].inquantity_tofirst-o[e][s].inventory[0].outquantity_tofirst,0!=c&&(o[e][s].inventory[0].unit_cost_stock_first_btax=u/c,o[e][s].inventory[0].unit_cost_stock_first_atax=d/c,o[e][s].inventory[0].cost_stock_first_btax=o[e][s].inventory[0].unit_cost_stock_first_btax*o[e][s].inventory[0].stock_first,o[e][s].inventory[0].cost_stock_first_atax=o[e][s].inventory[0].unit_cost_stock_first_atax*o[e][s].inventory[0].stock_first);var _=o[e][s].inventory[0].outquantity_tofirst,p=o[e][s].inventory[0].unit_cost_stock_first_btax*_,b=o[e][s].inventory[0].unit_cost_stock_first_atax*_,f=o[e][s].inventory[0].sales_tofirst_btax,h=o[e][s].inventory[0].sales_tofirst_atax;o[e][s].inventory[0].profit_first_btax=f-p,o[e][s].inventory[0].profit_first_atax=h-b}else{c=o[e][s].inventory[r].inquantity_tofirst-o[e][s].inventory[r-1].inquantity_tofirst,u=o[e][s].inventory[r].pay_tofirst_btax-o[e][s].inventory[r-1].pay_tofirst_btax,d=o[e][s].inventory[r].pay_tofirst_atax-o[e][s].inventory[r-1].pay_tofirst_atax;o[e][s].inventory[r].stock_first=o[e][s].inventory[r].inquantity_tofirst-o[e][s].inventory[r].outquantity_tofirst,o[e][s].inventory[r-1].stock_first+c!=0&&(o[e][s].inventory[r].unit_cost_stock_first_btax=(o[e][s].inventory[r-1].cost_stock_first_btax+u)/(o[e][s].inventory[r-1].stock_first+c),o[e][s].inventory[r].unit_cost_stock_first_atax=(o[e][s].inventory[r-1].cost_stock_first_atax+d)/(o[e][s].inventory[r-1].stock_first+c),o[e][s].inventory[r].cost_stock_first_btax=o[e][s].inventory[r].unit_cost_stock_first_btax*o[e][s].inventory[r].stock_first,o[e][s].inventory[r].cost_stock_first_atax=o[e][s].inventory[r].unit_cost_stock_first_atax*o[e][s].inventory[r].stock_first);_=o[e][s].inventory[r].outquantity_tofirst-o[e][s].inventory[r-1].outquantity_tofirst,p=o[e][s].inventory[r].unit_cost_stock_first_btax*_,b=o[e][s].inventory[r].unit_cost_stock_first_atax*_,f=o[e][s].inventory[r].sales_tofirst_btax-o[e][s].inventory[r-1].sales_tofirst_btax,h=o[e][s].inventory[r].sales_tofirst_atax-o[e][s].inventory[r-1].sales_tofirst_atax;o[e][s].inventory[r].profit_first_btax=f-p,o[e][s].inventory[r].profit_first_atax=h-b}}console.log(e,o[e]),n(o[e])}))}else console.log(e,null),n(null)}else{l=new Array;var _=new Array;t.getlocalProductAndCombos(o[e]._id).forEach((function(t){_.push(t._id)}));for(u=0;u<_.length;u++){d={bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:s},id_product:{$eq:_[u]}};l[u]=t.vhmongo_firebase.database().getDocsByFields("vhbill_details",d,{},{date:1},0)}Promise.all(l).then((function(t){var i=t.flat();o[e][s]={},o[e][s].inventory=new Array;for(var r=0;r<a.length;r++)o[e][s].inventory[r]={},o[e][s].inventory[r].date=a[r],o[e][s].inventory[r].inquantity_tofirst=0,o[e][s].inventory[r].pay_tofirst_btax=0,o[e][s].inventory[r].pay_tofirst_atax=0,o[e][s].inventory[r].outquantity_tofirst=0,o[e][s].inventory[r].sales_tofirst_btax=0,o[e][s].inventory[r].sales_tofirst_atax=0,o[e][s].inventory[r].stock_first=0,o[e][s].inventory[r].unit_cost_stock_first_btax=0,o[e][s].inventory[r].unit_cost_stock_first_atax=0,o[e][s].inventory[r].cost_stock_first_btax=0,o[e][s].inventory[r].cost_stock_first_atax=0,o[e][s].inventory[r].profit_first_btax=0,o[e][s].inventory[r].profit_first_atax=0;if(i.length>0){for(var l=0;l<i.length;l++)if(1===i[l].ptype){if(i[l].id_product===o[e]._id)for(r=0;r<o[e][s].inventory.length;r++)new Date(i[l].date).getTime()<new Date(o[e][s].inventory[r].date).getTime()&&(1===i[l].bill_type||10===i[l].bill_type||15===i[l].bill_type||30===i[l].bill_type?(o[e][s].inventory[r].outquantity_tofirst=o[e][s].inventory[r].outquantity_tofirst+i[l].quantity,o[e][s].inventory[r].sales_tofirst_btax=o[e][s].inventory[r].sales_tofirst_btax+i[l].price*i[l].quantity,o[e][s].inventory[r].sales_tofirst_atax=o[e][s].inventory[r].sales_tofirst_atax+i[l].price*i[l].quantity*(1+i[l].tax/100)):2!==i[l].bill_type&&3!==i[l].bill_type&&9!==i[l].bill_type&&31!==i[l].bill_type||(o[e][s].inventory[r].inquantity_tofirst=o[e][s].inventory[r].inquantity_tofirst+i[l].quantity,o[e][s].inventory[r].pay_tofirst_btax=o[e][s].inventory[r].pay_tofirst_btax+i[l].price*i[l].quantity,o[e][s].inventory[r].pay_tofirst_atax=o[e][s].inventory[r].pay_tofirst_atax+i[l].price*i[l].quantity*(1+i[l].tax/100)))}else if(5===i[l].ptype)for(var c=0;c<i[l].combos.length;c++)if(i[l].combos[c].id_product===o[e]._id)for(r=0;r<o[e][s].inventory.length;r++)new Date(i[l].date).getTime()<new Date(o[e][s].inventory[r].date).getTime()&&(1===i[l].bill_type||10===i[l].bill_type||15===i[l].bill_type||30===i[l].bill_type?(o[e][s].inventory[r].outquantity_tofirst=o[e][s].inventory[r].outquantity_tofirst+i[l].combos[c].quantity*i[l].quantity,o[e][s].inventory[r].sales_tofirst_btax=o[e][s].inventory[r].sales_tofirst_btax+i[l].combos[c].price*i[l].combos[c].quantity*i[l].quantity,o[e][s].inventory[r].sales_tofirst_atax=o[e][s].inventory[r].sales_tofirst_atax+i[l].combos[c].price*i[l].combos[c].quantity*i[l].quantity*(1+i[l].tax/100)):2!==i[l].bill_type&&3!==i[l].bill_type&&9!==i[l].bill_type&&31!==i[l].bill_type||(o[e][s].inventory[r].inquantity_tofirst=o[e][s].inventory[r].inquantity_tofirst+i[l].combos[c].quantity*i[l].quantity,o[e][s].inventory[r].pay_tofirst_btax=o[e][s].inventory[r].pay_tofirst_btax+i[l].combos[c].price*i[l].combos[c].quantity*i[l].quantity,o[e][s].inventory[r].pay_tofirst_atax=o[e][s].inventory[r].pay_tofirst_atax+i[l].combos[c].price*i[l].combos[c].quantity*i[l].quantity*(1+i[l].tax/100)));for(r=0;r<o[e][s].inventory.length;r++)if(0===r){var u=o[e][s].inventory[0].inquantity_tofirst,d=o[e][s].inventory[0].pay_tofirst_btax,_=o[e][s].inventory[0].pay_tofirst_atax;o[e][s].inventory[0].stock_first=o[e][s].inventory[0].inquantity_tofirst-o[e][s].inventory[0].outquantity_tofirst,0!=u&&(o[e][s].inventory[0].unit_cost_stock_first_btax=d/u,o[e][s].inventory[0].unit_cost_stock_first_atax=_/u,o[e][s].inventory[0].cost_stock_first_btax=o[e][s].inventory[0].unit_cost_stock_first_btax*o[e][s].inventory[0].stock_first,o[e][s].inventory[0].cost_stock_first_atax=o[e][s].inventory[0].unit_cost_stock_first_atax*o[e][s].inventory[0].stock_first);var p=o[e][s].inventory[0].outquantity_tofirst,b=o[e][s].inventory[0].unit_cost_stock_first_btax*p,f=o[e][s].inventory[0].unit_cost_stock_first_atax*p,h=o[e][s].inventory[0].sales_tofirst_btax,y=o[e][s].inventory[0].sales_tofirst_atax;o[e][s].inventory[0].profit_first_btax=h-b,o[e][s].inventory[0].profit_first_atax=y-f}else{u=o[e][s].inventory[r].inquantity_tofirst-o[e][s].inventory[r-1].inquantity_tofirst,d=o[e][s].inventory[r].pay_tofirst_btax-o[e][s].inventory[r-1].pay_tofirst_btax,_=o[e][s].inventory[r].pay_tofirst_atax-o[e][s].inventory[r-1].pay_tofirst_atax;o[e][s].inventory[r].stock_first=o[e][s].inventory[r].inquantity_tofirst-o[e][s].inventory[r].outquantity_tofirst,o[e][s].inventory[r-1].stock_first+u!=0&&(o[e][s].inventory[r].unit_cost_stock_first_btax=(o[e][s].inventory[r-1].cost_stock_first_btax+d)/(o[e][s].inventory[r-1].stock_first+u),o[e][s].inventory[r].unit_cost_stock_first_atax=(o[e][s].inventory[r-1].cost_stock_first_atax+_)/(o[e][s].inventory[r-1].stock_first+u),o[e][s].inventory[r].cost_stock_first_btax=o[e][s].inventory[r].unit_cost_stock_first_btax*o[e][s].inventory[r].stock_first,o[e][s].inventory[r].cost_stock_first_atax=o[e][s].inventory[r].unit_cost_stock_first_atax*o[e][s].inventory[r].stock_first);p=o[e][s].inventory[r].outquantity_tofirst-o[e][s].inventory[r-1].outquantity_tofirst,b=o[e][s].inventory[r].unit_cost_stock_first_btax*p,f=o[e][s].inventory[r].unit_cost_stock_first_atax*p,h=o[e][s].inventory[r].sales_tofirst_btax-o[e][s].inventory[r-1].sales_tofirst_btax,y=o[e][s].inventory[r].sales_tofirst_atax-o[e][s].inventory[r-1].sales_tofirst_atax;o[e][s].inventory[r].profit_first_btax=h-b,o[e][s].inventory[r].profit_first_atax=y-f}}console.log(e,o[e]),n(o[e])}))}}))},_=c[0];_<=c[c.length-1];_++)d(_);Promise.all(r).then((function(o){for(var a=0;a<o.length;a++)if(o[a]){var r={};r[s]=o[a][s],t.vhmongo_firebase.database().updateDoc("products",o[a]._id,Object.assign({},r))}i.length>0?(l=!0,c=i.splice(0,1)):(n(e),clearInterval(u))}))}}),100)}))},u=0;u<r.length;u++)c(u);Promise.all(l).then((function(t){console.log("syncInventoryEveryDay",t),e(null)}))}}))}))},t.prototype.makeCorrectQuantityProducts_byShop=function(){var t=this;return new Promise((function(e,n){var o=t.getDefaultBranch()._id,i=(t.vhAuth.getStore(),new Array);i=t.vhAlgorithm.sortVietnamesebyASC(t.getlocalProducts(1),"name");var a=!1,s=new Date;s.setHours(0),s.setMinutes(0),s.setSeconds(0),s.setMilliseconds(0);var r=t.vhAuth.localStorageGET(o+"_date_make_correct_quantity_products_byshop");if(null!=r?r!=s.getTime()&&(a=!0,t.vhAuth.localStorageSET(o+"_date_make_correct_quantity_products_byshop",s.getTime())):(a=!0,t.vhAuth.localStorageSET(o+"_date_make_correct_quantity_products_byshop",s.getTime())),a)if(i.length>0){var l,c=new Array;l={bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:o}},c[0]=t.vhmongo_firebase.database().getDocsByFields("vhbill_details",l,{},{date:1},0),Promise.all(c).then((function(n){for(var a=n.flat(),s=(new Array,0);s<i.length;s++){for(var r={stock_first:0},l={_id:i[s]._id,name:i[s].name,type:i[s].type,unit:i[s].unit,outquantity:0,inquantity:0,stock_first:0,stock_last:0},u=0;u<a.length;u++)if(1===a[u].ptype){if(a[u].id_product===i[s]._id){new Date(a[u].date);1===a[u].bill_type||10===a[u].bill_type||15===a[u].bill_type||30===a[u].bill_type?l.outquantity=l.outquantity+a[u].quantity:2===a[u].bill_type||3===a[u].bill_type||31===a[u].bill_type?(l.cost_btax=l.cost_btax+a[u].price*a[u].quantity,l.cost_atax=l.cost_atax+a[u].price*a[u].quantity*(1+a[u].tax/100),l.inquantity=l.inquantity+a[u].quantity):9===a[u].bill_type&&(r.stock_first=r.stock_first+a[u].quantity)}}else if(5===a[u].ptype)for(var d=0;d<a[u].combos.length;d++)if(a[u].combos[d].id_product===i[s]._id){new Date(a[u].date);1===a[u].bill_type||10===a[u].bill_type||15===a[u].bill_type||30===a[u].bill_type?l.outquantity=l.outquantity+a[u].combos[d].quantity*a[u].quantity:2===a[u].bill_type||3===a[u].bill_type||31===a[u].bill_type?(l.cost_btax=l.cost_btax+a[u].combos[d].price*a[u].combos[d].quantity*a[u].quantity,l.cost_atax=l.cost_atax+a[u].combos[d].price*a[u].combos[d].quantity*a[u].quantity*(1+a[u].tax/100),l.inquantity=l.inquantity+a[u].combos[d].quantity*a[u].quantity):9===a[u].bill_type&&(r.stock_first=r.stock_first+a[u].combos[d].quantity*a[u].quantity);break}if(l.stock_first=r.stock_first,l.stock_last=l.stock_first+l.inquantity-l.outquantity,null!=i[s].quantity_branch[o]){if(i[s].quantity_branch[o]!=l.stock_last){console.log("wrong quality product",i[s]),console.log("products[i].quantity_branch[id_branch]",i[s].quantity_branch[o]),console.log("product.stock_last",l.stock_last),console.log("-----------------------------------------------------------------------");var _={};_[o]=Object.assign({},i[s][o]),_[o].inventory=null;var p={};(p=Object.assign({},i[s].quantity_branch))[o]=l.stock_last;var b=0;for(var f in p)b+=p[f];c.push(t.updateProduct(i[s]._id,Object.assign({quantity:b,quantity_branch:p},_))),c.push(null)}}else if(console.log("undefined quantity product",i[s]),null!=i[s].quantity_branch){p={};(p=Object.assign({},i[s].quantity_branch))[o]=0;b=0;for(var f in p)b+=p[f];c.push(t.updateProduct(i[s]._id,{quantity:b,quantity_branch:p}))}}Promise.all(c).then((function(){console.log("finished"),e(!0)}))}))}else console.log("server -> products khong ton tai trong CSDL: "),e(null);else e(!0)}))},t.prototype.makeCorrectQuantityProducts_60days=function(){var t=this;return new Promise((function(e,n){var o=t.getDefaultBranch()._id,i={docs:new Array,empty:!0,size:0},a=t.vhAuth.getStore(),s=new Array;s=t.vhAlgorithm.sortVietnamesebyASC(t.getlocalProducts(1),"name");var r=null,l=null;if(null!=s[0][o]&&null!=s[0][o].inventory&&(r=s[0][o].inventory.length-1,l=new Date(s[0][o].inventory[r].date)),l||(l=new Date(a.registrationdate)),s.length>0){var c,u=new Array;c={date:{$gte:l},bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:o}},u[0]=t.vhmongo_firebase.database().getDocsByFields("vhbill_details",c,{},{date:1},0),Promise.all(u).then((function(n){for(var a=n.flat(),l=(new Array,0);l<s.length;l++){for(var c={stock_first:0,cost_stock_first_btax:0,cost_stock_first_atax:0,unit_cost_stock_first_btax:0,unit_cost_stock_first_atax:0,inquantity_tofirst:0,outquantity_tofirst:0,pay_tofirst_btax:0,pay_tofirst_atax:0,profit_first_btax:0,profit_first_atax:0,sales_tofirst_btax:0,sales_tofirst_atax:0},d={_id:s[l]._id,name:s[l].name,type:s[l].type,unit:s[l].unit,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0,stock_first:0,stock_last:0,cost_stock_first_btax:0,cost_stock_first_atax:0,cost_stock_last_btax:0,cost_stock_last_atax:0},_=0;_<a.length;_++)if(1===a[_].ptype){if(a[_].id_product===s[l]._id){new Date(a[_].date);1===a[_].bill_type||10===a[_].bill_type||15===a[_].bill_type||30===a[_].bill_type?d.outquantity=d.outquantity+a[_].quantity:2===a[_].bill_type||3===a[_].bill_type||31===a[_].bill_type?(d.cost_btax=d.cost_btax+a[_].price*a[_].quantity,d.cost_atax=d.cost_atax+a[_].price*a[_].quantity*(1+a[_].tax/100),d.inquantity=d.inquantity+a[_].quantity):9===a[_].bill_type&&(c.stock_first=c.stock_first+a[_].quantity,c.cost_stock_first_btax=c.cost_stock_first_btax+a[_].price*a[_].quantity,c.cost_stock_first_atax=c.cost_stock_first_atax+a[_].price*a[_].quantity*(1+a[_].tax/100))}}else if(5===a[_].ptype)for(var p=0;p<a[_].combos.length;p++)if(a[_].combos[p].id_product===s[l]._id){new Date(a[_].date);1===a[_].bill_type||10===a[_].bill_type||15===a[_].bill_type||30===a[_].bill_type?d.outquantity=d.outquantity+a[_].combos[p].quantity*a[_].quantity:2===a[_].bill_type||3===a[_].bill_type||31===a[_].bill_type?(d.cost_btax=d.cost_btax+a[_].combos[p].price*a[_].combos[p].quantity*a[_].quantity,d.cost_atax=d.cost_atax+a[_].combos[p].price*a[_].combos[p].quantity*a[_].quantity*(1+a[_].tax/100),d.inquantity=d.inquantity+a[_].combos[p].quantity*a[_].quantity):9===a[_].bill_type&&(c.stock_first=c.stock_first+a[_].combos[p].quantity*a[_].quantity,c.cost_stock_first_btax=c.cost_stock_first_btax+a[_].combos[p].price*a[_].combos[p].quantity*a[_].quantity,c.cost_stock_first_atax=c.cost_stock_first_atax+a[_].combos[p].price*a[_].combos[p].quantity*a[_].quantity*(1+a[_].tax/100));break}if(null!=r&&(c=Object.assign({},s[l][o].inventory[r])),d.stock_first=c.stock_first,d.stock_last=d.stock_first+d.inquantity-d.outquantity,null!=s[l].quantity_branch[o]&&s[l].quantity_branch[o]!=d.stock_last){console.log("khác products[i]",s[l]),console.log("products[i].quantity_branch[id_branch]",s[l].quantity_branch[o]),console.log("product.stock_last",d.stock_last),console.log("-----------------------------------------------------------------------");var b={};(b=Object.assign({},s[l].quantity_branch))[o]=d.stock_last,u.push(t.updateProduct(s[l]._id,{quantity_branch:b}))}0!=c.stock_first&&(d.cost_stock_first_btax=c.cost_stock_first_btax/c.stock_first*d.stock_first,d.cost_stock_first_atax=c.cost_stock_first_atax/c.stock_first*d.stock_first),0!=c.stock_first&&(d.cost_stock_last_btax=c.cost_stock_first_btax/c.stock_first*d.stock_last,d.cost_stock_last_atax=c.cost_stock_first_atax/c.stock_first*d.stock_last),0==d.stock_first&&0==d.stock_last&&0==d.inquantity&&0==d.outquantity||(d.cost_atax=Math.round(1e6*d.cost_atax)/1e6,d.cost_stock_first_atax=Math.round(1e6*d.cost_stock_first_atax)/1e6,d.cost_stock_last_atax=Math.round(1e6*d.cost_stock_last_atax)/1e6,d.index=i.size+1,i.docs.push(d),i.size++,i.empty=!1)}Promise.all(u).then((function(){console.log("finished"),e(i),console.log("makeCorrectQuantityProducts_60days",i)}))}))}else console.log("server -> products khong ton tai trong CSDL: "),e(i)}))},t.prototype.makeCorrectQuantityProducts=function(){var t=this;return new Promise((function(e,n){var o=t.getlocalProducts(1),i=t.getDefaultBranch()._id,a={ptype:{$eq:1},id_branch:{$eq:i},bill_type:{$in:[1,10,15,30,2,3,9,31]}};t.vhmongo_firebase.database().getDocsByFields("vhbill_details",a,{},{date:1},0).then((function(t){if(o.length>0&&t.length>0){for(var n=new Array,a=0;a<o.length;a++){var s={};s[i]=0;for(var r=0;r<t.length;r++){var l=t[r];o[a]._id===l.id_product&&(1===l.bill_type||10===l.bill_type||15===l.bill_type||30===t[r].bill_type?(l.quantity,s[i]=s[i]-l.quantity):2!==l.bill_type&&3!==l.bill_type&&9!==l.bill_type&&31!==t[r].bill_type||(l.quantity,s[i]=s[i]+l.quantity))}null!=o[a].quantity_branch[i]?o[a].quantity_branch[i]!=s[i]&&(console.log("khác 1 quantity_branch",o[a]),console.log("products[i].quantity_branch[id_branch]",o[a].quantity_branch[i]),console.log("quantity_branch[id_branch]",s[i])):console.log("khác quantity",o[a])}Promise.all(n).then((function(){console.log("finished"),e(null)}))}else e(null)}))}))},t.prototype.makeCorrectQuantityProductsManyBranch=function(){var t=this;return new Promise((function(e,n){var o=t.getlocalProducts(1),i=t.getlocalBranchs();t.vhmongo_firebase.database().getDocsByFields("vhbill_details",{ptype:{$eq:1},bill_type:{$in:[1,10,15,30,2,3,9,31]}},{},{date:1},0).then((function(t){if(o.length>0&&t.length>0){for(var n=new Array,a=0;a<o.length;a++){for(var s=0,r={},l=0;l<i.length;l++)r[i[l]._id]=0;for(var c=0;c<t.length;c++){var u=t[c];o[a]._id===u.id_product&&(1===u.bill_type||10===u.bill_type||15===u.bill_type||30===t[c].bill_type?(s-=u.quantity,null!=r[u.id_branch]?r[u.id_branch]=r[u.id_branch]-u.quantity:r[u.id_branch]=-u.quantity):2!==u.bill_type&&3!==u.bill_type&&9!==u.bill_type&&31!==t[c].bill_type||(s+=u.quantity,null!=r[u.id_branch]?r[u.id_branch]=r[u.id_branch]+u.quantity:r[u.id_branch]=u.quantity))}var d=!1;for(var _ in o[a].quantity!=s&&(d=!0),o[a].quantity_branch)for(var p in r)_===p&&o[a].quantity_branch[_]===r[p]&&(d=!0);d&&(console.log("products[i]",o[a]),n.push(new Promise((function(t){t(null)}))))}Promise.all(n).then((function(){e(null)}))}else e(null)}))}))},t.prototype.getReportProducts_byLowInStock=function(t){var e=this;return new Promise((function(n,o){var i=e.getlocalProducts(1),a=e.getlocalBranchs(),s=new Array;if("all"===t||void 0===t){for(var r=0;r<i.length;r++){i[r].quantity=0,i[r].branchs=new Array;for(var l=0;l<a.length;l++)if(void 0===i[r].quantity_branch[a[l]._id]&&(i[r].quantity_branch[a[l]._id]=0),i[r].quantity_branch[a[l]._id]<=i[r].warning_number){i[r].quantity=i[r].quantity+i[r].quantity_branch[a[l]._id];var c={id_branch:a[l]._id,name:a[l].name,quantity:i[r].quantity_branch[a[l]._id]};i[r].branchs.push(c)}delete i[r].quantity_branch}s=i.filter((function(t){return t.branchs.length>0}))}else{for(r=0;r<i.length;r++){i[r].quantity=0,i[r].branchs=new Array,void 0===i[r].quantity_branch[t]&&(i[r].quantity_branch[t]=0),i[r].quantity=i[r].quantity_branch[t];c={id_branch:t,name:e.getlocalBranch(t).name,quantity:i[r].quantity_branch[t]};i[r].branchs.push(c),delete i[r].quantity_branch}s=i.filter((function(t){if(t.quantity<=t.warning_number)return!0}))}n(s)}))},t.prototype.getReportProducts_byOutOfStock=function(t){var e=this;return new Promise((function(n,o){var i=e.getlocalProducts(1),a=e.getlocalBranchs(),s=new Array;if("all"===t||void 0===t){for(var r=0;r<i.length;r++)for(var l=0;l<a.length;l++);for(r=0;r<i.length;r++){i[r].quantity=0,i[r].branchs=new Array;for(l=0;l<a.length;l++)if(void 0===i[r].quantity_branch[a[l]._id]&&(i[r].quantity_branch[a[l]._id]=0),i[r].quantity_branch[a[l]._id]<=0){i[r].quantity=i[r].quantity+i[r].quantity_branch[a[l]._id];var c={id_branch:a[l]._id,name:a[l].name,quantity:i[r].quantity_branch[a[l]._id]};i[r].branchs.push(c)}delete i[r].quantity_branch}s=i.filter((function(t){return t.branchs.length>0}))}else{for(r=0;r<i.length;r++){i[r].quantity=0,i[r].branchs=new Array,void 0===i[r].quantity_branch[t]&&(i[r].quantity_branch[t]=0),i[r].quantity=i[r].quantity_branch[t];c={id_branch:t,name:e.getlocalBranch(t).name,quantity:i[r].quantity_branch[t]};i[r].branchs.push(c),delete i[r].quantity_branch}s=i.filter((function(t){if(t.quantity<=0)return!0}))}n(s)}))},t.prototype.getReportRevenue_byHoursOut_hourArray=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l={docs:new Array,empty:!0,size:0,revenue:0};r="all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1,7,10,11,15]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1,7,10,11,15]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("bills",r,{},{date:1},0).then((function(t){if(t.length>0){for(var e=new Array,o=0;o<n.length;o++)e[o]={},e[o].revenue=0;for(var i=0;i<t.length;i++){var s=Object.assign({},t[i]);if(s.date){var r=new Date(s.date).getHours();for(o=0;o<n.length;o++)n[o]===r&&(e[o].revenue=e[o].revenue+Number(s.payment),l.revenue=l.revenue+Number(s.payment))}}l.docs=e,l.size=n.length,l.empty=!1}a(l)}))}))},t.prototype.getReportRevenue_byDaysOut_dayArray=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l={docs:new Array,empty:!0,size:0,revenue:0};r="all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1,7,10,11,15]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1,7,10,11,15]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("bills",r,{},{date:1},0).then((function(t){if(t.length>0){for(var e=new Array,o=0;o<n.length;o++)e[o]={},e[o].revenue=0;for(var i=0;i<t.length;i++){var s=t[i];if(s.date){var r=new Date(s.date).getDate();for(o=0;o<n.length;o++)n[o]===r&&(e[o].revenue=e[o].revenue+Number(s.payment),l.revenue=l.revenue+Number(s.payment))}}l.docs=e,l.size=n.length,l.empty=!1}a(l)}))}))},t.prototype.getReportRevenue_byMonthsOut_monthArray=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l={docs:new Array,empty:!0,size:0,revenue:0};r="all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1,7,10,11,15]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1,7,10,11,15]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("bills",r,{},{date:1},0).then((function(t){if(t.length>0){for(var e=new Array,o=0;o<n.length;o++)e[o]={},e[o].revenue=0;for(var i=0;i<t.length;i++){var s=t[i];if(s.date){var r=new Date(s.date).getMonth();for(o=0;o<n.length;o++)n[o]===r&&(e[o].revenue=e[o].revenue+Number(s.payment),l.revenue=l.revenue+Number(s.payment))}}l.docs=e,l.size=n.length,l.empty=!1}a(l)}))}))},t.prototype.getReportRevenue_byIDbranch=function(t,e,n){var o=this;return new Promise((function(i,a){var s,r={docs:new Array,empty:!0,size:0,revenue:0},l=new Array;if("all"===n||void 0===n)l=o.vhAlgorithm.sortVietnamesebyASC(o.getlocalBranchs(),"name"),s={date:{$gte:t,$lte:e},bill_type:{$in:[1,7,10,11,15]}};else{var c=o.getlocalBranch(n);l.push(c),s={date:{$gte:t,$lte:e},bill_type:{$in:[1,7,10,11,15]},id_branch:{$eq:n}}}o.vhmongo_firebase.database().getDocsByFields("bills",s,{},{date:1},0).then((function(t){if(t.length>0){for(var e=new Array,n=0;n<l.length;n++)e[n]={},e[n].id_branch=l[n]._id,e[n].name=l[n].name,e[n].revenue=0;for(var o=0;o<t.length;o++)for(n=0;n<l.length;n++)l[n]._id===t[o].id_branch&&(e[n].revenue=e[n].revenue+Number(t[o].payment),r.revenue=r.revenue+Number(t[o].payment));r.docs=e,r.size=l.length,r.empty=!1}i(r)}))}))},t.prototype.getReportSales_byHoursOut_hourArray=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0};r="all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1,3,15]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1,3,15]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("vhbill_details",r,{},{date:1},0).then((function(t){if(t.length>0){for(var e=new Array,o=0;o<n.length;o++)e[o]={},e[o].sales_btax=0,e[o].sales_atax=0;for(var i=0;i<t.length;i++){var s=Object.assign({},t[i]);if(s.date){var r=new Date(s.date).getHours();for(o=0;o<n.length;o++)n[o]===r&&(3===s.bill_type?(e[o].sales_btax=e[o].sales_btax-Number(s.price)*s.quantity,e[o].sales_atax=e[o].sales_atax-Number(s.price)*s.quantity*(1+s.tax/100),l.sales_btax=l.sales_btax-Number(s.price)*s.quantity,l.sales_atax=l.sales_atax-Number(s.price)*s.quantity*(1+s.tax/100)):(e[o].sales_btax=e[o].sales_btax+Number(s.price)*s.quantity,e[o].sales_atax=e[o].sales_atax+Number(s.price)*s.quantity*(1+s.tax/100),l.sales_btax=l.sales_btax+Number(s.price)*s.quantity,l.sales_atax=l.sales_atax+Number(s.price)*s.quantity*(1+s.tax/100)))}}l.docs=e,l.size=n.length,l.empty=!1}a(l)}))}))},t.prototype.getReportSales_byDaysOut_dayArray=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0};r="all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1,3,15]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1,3,15]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("vhbill_details",r,{},{date:1},0).then((function(t){if(t.length>0){for(var e=new Array,o=0;o<n.length;o++)e[o]={},e[o].sales_btax=0,e[o].sales_atax=0;for(var i=0;i<t.length;i++){var s=Object.assign({},t[i]);if(s.date){var r=new Date(s.date).getDate();for(o=0;o<n.length;o++)n[o]===r&&(3===s.bill_type?(e[o].sales_btax=e[o].sales_btax-Number(s.price)*s.quantity,e[o].sales_atax=e[o].sales_atax-Number(s.price)*s.quantity*(1+s.tax/100),l.sales_btax=l.sales_btax-Number(s.price)*s.quantity,l.sales_atax=l.sales_atax-Number(s.price)*s.quantity*(1+s.tax/100)):(e[o].sales_btax=e[o].sales_btax+Number(s.price)*s.quantity,e[o].sales_atax=e[o].sales_atax+Number(s.price)*s.quantity*(1+s.tax/100),l.sales_btax=l.sales_btax+Number(s.price)*s.quantity,l.sales_atax=l.sales_atax+Number(s.price)*s.quantity*(1+s.tax/100)))}}l.docs=e,l.size=n.length,l.empty=!1}a(l)}))}))},t.prototype.getReportSales_byMonthsOut_monthArray=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0};r="all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1,15]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1,15]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("vhbill_details",r,{},{date:1},0).then((function(t){if(t.length>0){for(var e=new Array,o=0;o<n.length;o++)e[o]={},e[o].sales_btax=0,e[o].sales_atax=0;for(var i=0;i<t.length;i++){var s=t[i];if(s.date){var r=new Date(s.date).getMonth();for(o=0;o<n.length;o++)n[o]===r&&(3===s.bill_type?(e[o].sales_btax=e[o].sales_btax-Number(s.price)*s.quantity,e[o].sales_atax=e[o].sales_atax-Number(s.price)*s.quantity*(1+s.tax/100),l.sales_btax=l.sales_btax-Number(s.price)*s.quantity,l.sales_atax=l.sales_atax-Number(s.price)*s.quantity*(1+s.tax/100)):(e[o].sales_btax=e[o].sales_btax+Number(s.price)*s.quantity,e[o].sales_atax=e[o].sales_atax+Number(s.price)*s.quantity*(1+s.tax/100),l.sales_btax=l.sales_btax+Number(s.price)*s.quantity,l.sales_atax=l.sales_atax+Number(s.price)*s.quantity*(1+s.tax/100)))}}l.docs=e,l.size=n.length,l.empty=!1}a(l)}))}))},t.prototype.getReportSales_byIDbranch=function(t,e,n){var o=this;return new Promise((function(i,a){var s,r={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0},l=new Array;if("all"===n||void 0===n)l=o.vhAlgorithm.sortVietnamesebyASC(o.getlocalBranchs(),"name"),s={date:{$gte:t,$lte:e},bill_type:{$in:[1,15,3]}};else{var c=o.getlocalBranch(n);l.push(c),s={date:{$gte:t,$lte:e},bill_type:{$in:[1,15,3]},id_branch:{$eq:n}}}o.vhmongo_firebase.database().getDocsByFields("vhbill_details",s,{},{date:1},0).then((function(t){if(t.length>0){for(var e=new Array,n=0;n<l.length;n++)e[n]={},e[n].id_branch=l[n]._id,e[n].name=l[n].name,e[n].sales_btax=0,e[n].sales_atax=0;for(var o=0;o<t.length;o++){var a=t[o];for(n=0;n<l.length;n++)l[n]._id===a.id_branch&&(3===a.bill_type?(e[n].sales_btax=e[n].sales_btax-Number(a.price)*a.quantity,e[n].sales_atax=e[n].sales_atax-Number(a.price)*a.quantity*(1+a.tax/100),r.sales_btax=r.sales_btax-Number(a.price)*a.quantity,r.sales_atax=r.sales_atax-Number(a.price)*a.quantity*(1+a.tax/100)):(e[n].sales_btax=e[n].sales_btax+Number(a.price)*a.quantity,e[n].sales_atax=e[n].sales_atax+Number(a.price)*a.quantity*(1+a.tax/100),r.sales_btax=r.sales_btax+Number(a.price)*a.quantity,r.sales_atax=r.sales_atax+Number(a.price)*a.quantity*(1+a.tax/100)))}r.docs=e,r.size=l.length,r.empty=!1}i(r)}))}))},t.prototype.getReportCashBook=function(t,e,n,o){var i=this;t=new Date(t),e=new Date(e);var a=[1,7,10,11,15,34,2,3,8,12,33],s=this.vhAuth.getStore();return new Promise((function(r,l){var c,u=0,d=null;if("all"===n)if("all"===o||void 0===o){for(var _=i.getlocalWallets(),p=i.getDefaultBranch()._id,b=null,f=0;f<_.length;f++)if("id_cash"===_[f]._id&&null!=_[f][o]&&null!=_[f][o].cashbook)for(var h=0;h<_[f][p].cashbook.length&&!(new Date(_[f][p].cashbook[h].date).getTime()>t.getTime());h++)d=new Date(_[f][p].cashbook[h].date),b=h;if(d)for(f=0;f<_.length;f++)if("id_cash"===_[f]._id)for(var y=i.getlocalBranchs(),m=0;m<y.length;m++)u+=_[f][y[m]._id].cashbook[b].cashbook_first;else u+=_[f].cashbook[b].cashbook_first}else{for(_=i.getlocalWallets().filter((function(t){return t.id_branch===o||"id_cash"===t._id})),b=null,f=0;f<_.length;f++)if("id_cash"===_[f]._id&&null!=_[f][o]&&null!=_[f][o].cashbook)for(h=0;h<_[f][o].cashbook.length&&!(new Date(_[f][o].cashbook[h].date).getTime()>t.getTime());h++)d=new Date(_[f][o].cashbook[h].date),b=h;if(d)for(f=0;f<_.length;f++)"id_cash"===_[f]._id?u+=_[f][o].cashbook[b].cashbook_first:u+=_[f].cashbook[b].cashbook_first}else if("all"===o||void 0===o)console.log("trường hợp này chưa có hàm, liên hệ anh Huy viết");else{var v=i.getlocalWallet(n);if("id_cash"===v._id){if(null!=v[o]&&null!=v[o].cashbook)for(h=0;h<v[o].cashbook.length&&!(new Date(v[o].cashbook[h].date).getTime()>t.getTime());h++)d=new Date(v[o].cashbook[h].date),u=v[o].cashbook[h].cashbook_first}else if(null!=v.cashbook)for(h=0;h<v.cashbook.length&&!(new Date(v.cashbook[h].date).getTime()>t.getTime());h++)d=new Date(v.cashbook[h].date),u=v.cashbook[h].cashbook_first}d||(d=new Date(s.registrationdate));for(var g=new Array;a.length;){var x=a.splice(0,10);if("all"===n)if("all"===o||void 0===o){var q={date:{$gte:d,$lte:e},bill_type:{$in:x},payment_type:{$eq:1}},w={date:{$gte:d,$lte:e},bill_type:{$in:x},payment_type:{$eq:3}};g.push(i.vhmongo_firebase.database().getDocsByFields("bills",q,{},{date:1},0)),g.push(i.vhmongo_firebase.database().getDocsByFields("bills",w,{},{date:1},0))}else{q={date:{$gte:d,$lte:e},id_branch:{$eq:o},bill_type:{$in:x},payment_type:{$eq:1}},w={date:{$gte:d,$lte:e},id_branch:{$eq:o},bill_type:{$in:x},payment_type:{$eq:3}};g.push(i.vhmongo_firebase.database().getDocsByFields("bills",q,{},{date:1},0)),g.push(i.vhmongo_firebase.database().getDocsByFields("bills",w,{},{date:1},0))}else"all"===o||void 0===o||(c={date:{$gte:d,$lte:e},id_wallet:{$eq:n},id_branch:{$eq:o},bill_type:{$in:x}},g.push(i.vhmongo_firebase.database().getDocsByFields("bills",c,{},{date:1},0)))}Promise.all(g).then((function(e){var n=e.flat();n=i.vhAlgorithm.sortDatebyASC(n,"date");var o={docs:new Array,empty:!0,size:0,cashbook_first:u,income:0,expenditure:0,cashbook_last:0};if(n.length>0)for(var a=0;a<n.length;a++){var s=Object.assign({},n[a]);if(2!=(null==s?void 0:s.payment_type)){delete s.fee,delete s.discount,delete s.note,delete s.total,delete s.tax;var l=new Date(s.date);1===s.bill_type||7===s.bill_type||10===s.bill_type||11===s.bill_type||15===s.bill_type||34===s.bill_type?l>=t?(o.income=o.income+s.payment,s.index=o.size+1,o.docs.push(s),o.size++,o.empty=!1):o.cashbook_first=o.cashbook_first+s.payment:2!==s.bill_type&&3!==s.bill_type&&8!==s.bill_type&&12!==s.bill_type&&33!==s.bill_type||(l>=t?(o.expenditure=o.expenditure+s.payment,s.index=o.size+1,o.docs.push(s),o.size++,o.empty=!1):o.cashbook_first=o.cashbook_first-s.payment)}}o.cashbook_last=o.cashbook_first+o.income-o.expenditure,r(o)}))}))},t.prototype.getReportCashBook_old=function(t,e,n,o){var i=this;return t=new Date(t),e=new Date(e),new Promise((function(a,s){var r;r="all"===n?"all"===o||void 0===o?{date:{$lte:e}}:{date:{$lte:e},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$lte:e},id_wallet:{$eq:n}}:{date:{$lte:e},id_wallet:{$eq:n},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("bills",r,{},{date:1},0).then((function(e){var n={docs:new Array,empty:!0,size:0,cashbook_first:0,income:0,expenditure:0,cashbook_last:0};if(e.length>0)for(var o=0;o<e.length;o++){var i=Object.assign({},e[o]);if(2!=(null==i?void 0:i.payment_type)){delete i.fee,delete i.discount,delete i.note,delete i.total,delete i.tax;var s=new Date(i.date);1!==i.bill_type&&7!==i.bill_type&&10!==i.bill_type&&11!==i.bill_type&&15!==i.bill_type&&34!==i.bill_type||(s>=t?(n.income=n.income+i.payment,i.index=n.size+1,n.docs.push(i),n.size++,n.empty=!1):n.cashbook_first=n.cashbook_first+i.payment),2!==i.bill_type&&3!==i.bill_type&&8!==i.bill_type&&12!==i.bill_type&&33!==i.bill_type||(s>=t?(n.expenditure=n.expenditure+i.payment,i.index=n.size+1,n.docs.push(i),n.size++,n.empty=!1):n.cashbook_first=n.cashbook_first-i.payment)}}n.cashbook_last=n.cashbook_first+n.income-n.expenditure,a(n)}))}))},t.prototype.syncCashBook=function(t){var e=this;return new Promise((function(n,o){var i={id_branch:{$eq:t},bill_type:{$in:[1,7,10,11,15,2,3,8,12]}},a=e.getlocalWallets().filter((function(e){return e.id_branch===t||"id_cash"===e._id}));e.vhmongo_firebase.database().getDocsByFields("bills",i,{},{date:1},0).then((function(n){if(n.length>=2){for(var o=e.get1stDayOfMonthArray(n[0].date,n[n.length-1].date),i=0;i<a.length;i++)if("id_cash"===a[i]._id){a[i][t]={},a[i][t].cashbook=new Array;for(var s=0;s<o.length;s++)a[i][t].cashbook[s]={},a[i][t].cashbook[s].date=o[s],a[i][t].cashbook[s].cashbook_first=0;for(var r=0;r<n.length;r++)if(a[i]._id===n[r].id_wallet)for(s=0;s<a[i][t].cashbook.length;s++)new Date(n[r].date)<new Date(a[i][t].cashbook[s].date)&&(1===n[r].bill_type||7===n[r].bill_type||10===n[r].bill_type||11===n[r].bill_type||15===n[r].bill_type||34===n[r].bill_type?a[i][t].cashbook[s].cashbook_first=a[i][t].cashbook[s].cashbook_first+n[r].payment:2!==n[r].bill_type&&3!==n[r].bill_type&&8!==n[r].bill_type&&12!==n[r].bill_type&&33!==n[r].bill_type||(a[i][t].cashbook[s].cashbook_first=a[i][t].cashbook[s].cashbook_first-n[r].payment))}else{a[i].cashbook=new Array;for(s=0;s<o.length;s++)a[i].cashbook[s]={},a[i].cashbook[s].date=o[s],a[i].cashbook[s].cashbook_first=0;for(r=0;r<n.length;r++)if(a[i]._id===n[r].id_wallet)for(s=0;s<a[i].cashbook.length;s++)new Date(n[r].date)<new Date(a[i].cashbook[s].date)&&(1===n[r].bill_type||7===n[r].bill_type||10===n[r].bill_type||11===n[r].bill_type||15===n[r].bill_type||34===n[r].bill_type?a[i].cashbook[s].cashbook_first=a[i].cashbook[s].cashbook_first+n[r].payment:2!==n[r].bill_type&&3!==n[r].bill_type&&8!==n[r].bill_type&&12!==n[r].bill_type&&33!==n[r].bill_type||(a[i].cashbook[s].cashbook_first=a[i].cashbook[s].cashbook_first-n[r].payment))}console.log("wallets",a)}}))}))},t.prototype.syncCashBookEveryDay_Stock1stDayOfMonth=function(){var t=this;return new Promise((function(e,n){var o=t.vhAuth.getStore(),i=[Object.assign({},t.getDefaultBranch())];t.vhmongo_firebase.auth().getServerDate().then((function(n){var a=t.get1stDayOfMonthArray(o.registrationdate,n);if(a.length>0){for(var s=new Array,r=function(n){for(var o=i[n]._id,r=t.getlocalWallets().filter((function(t){return t.id_branch===o||"id_cash"===t._id})),l=new Array,c=function(n){if("id_cash"===r[n]._id)if(null!=r[n][o]&&null!=r[n][o].cashbook){var i=r[n][o].cashbook[r[n][o].cashbook.length-1];if(new Date(i.date).getTime()!=new Date(a[a.length-1]).getTime()){for(var s=r[n][o].cashbook.length;s<a.length;s++)r[n][o].cashbook[s]={},r[n][o].cashbook[s].date=a[s],r[n][o].cashbook[s].cashbook_first=i.cashbook_first;l[n]=new Promise((function(e){for(var a=[],s=[1,7,10,11,15,34,2,3,8,12,33];s.length;){var l=s.splice(0,10),c={date:{$gte:new Date(i.date)},id_branch:{$eq:o},id_wallet:{$eq:"id_cash"},bill_type:{$in:l}};a.push(t.vhmongo_firebase.database().getDocsByFields("bills",c,{},{date:1},0))}Promise.all(a).then((function(t){var i=t.flat();if(i.length>0)for(var a=0;a<i.length;a++)if("id_cash"===i[a].id_wallet)for(var s=0;s<r[n][o].cashbook.length;s++)new Date(i[a].date)<new Date(r[n][o].cashbook[s].date)&&(1===i[a].bill_type||7===i[a].bill_type||10===i[a].bill_type||11===i[a].bill_type||15===i[a].bill_type||34===i[a].bill_type?r[n][o].cashbook[s].cashbook_first=r[n][o].cashbook[s].cashbook_first+i[a].payment:2!==i[a].bill_type&&3!==i[a].bill_type&&8!==i[a].bill_type&&12!==i[a].bill_type&&33!==i[a].bill_type||(r[n][o].cashbook[s].cashbook_first=r[n][o].cashbook[s].cashbook_first-i[a].payment));e(r[n])}))}))}else e(null)}else l[n]=new Promise((function(e){for(var i=[],s=[1,7,10,11,15,34,2,3,8,12,33];s.length;){var l=s.splice(0,10),c={id_branch:{$eq:o},id_wallet:{$eq:"id_cash"},bill_type:{$in:l}};i.push(t.vhmongo_firebase.database().getDocsByFields("bills",c,{},{date:1},0))}Promise.all(i).then((function(t){var i=t.flat();r[n][o]={},r[n][o].cashbook=new Array;for(var s=0;s<a.length;s++)r[n][o].cashbook[s]={},r[n][o].cashbook[s].date=a[s],r[n][o].cashbook[s].cashbook_first=0;if(i.length>0)for(var l=0;l<i.length;l++)if("id_cash"===i[l].id_wallet)for(s=0;s<r[n][o].cashbook.length;s++)new Date(i[l].date)<new Date(r[n][o].cashbook[s].date)&&(1===i[l].bill_type||7===i[l].bill_type||10===i[l].bill_type||11===i[l].bill_type||15===i[l].bill_type||34===i[l].bill_type?r[n][o].cashbook[s].cashbook_first=r[n][o].cashbook[s].cashbook_first+i[l].payment:2!==i[l].bill_type&&3!==i[l].bill_type&&8!==i[l].bill_type&&12!==i[l].bill_type&&33!==i[l].bill_type||(r[n][o].cashbook[s].cashbook_first=r[n][o].cashbook[s].cashbook_first-i[l].payment));e(r[n])}))}));else if("id_cash"!=r[n]._id)if(null!=r[n].cashbook){var c=r[n].cashbook[r[n].cashbook.length-1];if(new Date(c.date).getTime()!=new Date(a[a.length-1]).getTime()){for(s=r[n].cashbook.length;s<a.length;s++)r[n].cashbook[s]={},r[n].cashbook[s].date=a[s],r[n].cashbook[s].cashbook_first=c.cashbook_first;l[n]=new Promise((function(e){for(var i=[],a=[1,7,10,11,15,34,2,3,8,12,33];a.length;){var s=a.splice(0,10),l={date:{$gte:new Date(c.date)},id_branch:{$eq:o},id_wallet:{$eq:r[n]._id},bill_type:{$in:s}};i.push(t.vhmongo_firebase.database().getDocsByFields("bills",l,{},{date:1},0))}Promise.all(i).then((function(t){var o=t.flat();if(o.length>0)for(var i=0;i<o.length;i++)if(o[i].id_wallet===r[n]._id)for(var a=0;a<r[n].cashbook.length;a++)new Date(o[i].date)<new Date(r[n].cashbook[a].date)&&(1===o[i].bill_type||7===o[i].bill_type||10===o[i].bill_type||11===o[i].bill_type||15===o[i].bill_type||34===o[i].bill_type?r[n].cashbook[a].cashbook_first=r[n].cashbook[a].cashbook_first+o[i].payment:2!==o[i].bill_type&&3!==o[i].bill_type&&8!==o[i].bill_type&&12!==o[i].bill_type&&33!==o[i].bill_type||(r[n].cashbook[a].cashbook_first=r[n].cashbook[a].cashbook_first-o[i].payment));e(r[n])}))}))}else e(null)}else l[n]=new Promise((function(e){for(var i=[],s=[1,7,10,11,15,34,2,3,8,12,33];s.length;){var l=s.splice(0,10),c={id_branch:{$eq:o},id_wallet:{$eq:r[n]._id},bill_type:{$in:l}};i.push(t.vhmongo_firebase.database().getDocsByFields("bills",c,{},{date:1},0))}Promise.all(i).then((function(t){var o=t.flat();r[n].cashbook=new Array;for(var i=0;i<a.length;i++)r[n].cashbook[i]={},r[n].cashbook[i].date=a[i],r[n].cashbook[i].cashbook_first=0;if(o.length>0)for(var s=0;s<o.length;s++)if(o[s].id_wallet===r[n]._id)for(i=0;i<r[n].cashbook.length;i++)new Date(o[s].date)<new Date(r[n].cashbook[i].date)&&(1===o[s].bill_type||7===o[s].bill_type||10===o[s].bill_type||11===o[s].bill_type||15===o[s].bill_type||34===o[s].bill_type?r[n].cashbook[i].cashbook_first=r[n].cashbook[i].cashbook_first+o[s].payment:2!==o[s].bill_type&&3!==o[s].bill_type&&8!==o[s].bill_type&&12!==o[s].bill_type&&33!==o[s].bill_type||(r[n].cashbook[i].cashbook_first=r[n].cashbook[i].cashbook_first-o[s].payment));e(r[n])}))}))},u=0;u<r.length;u++)c(u);s[n]=new Promise((function(e){Promise.all(l).then((function(n){for(var i=0;i<n.length;i++)if(n[i])if("id_cash"===n[i]._id){var a={};a[o]=n[i][o],t.vhmongo_firebase.database().updateDoc("wallets",n[i]._id,Object.assign({},a))}else t.vhmongo_firebase.database().updateDoc("wallets",n[i]._id,{cashbook:n[i].cashbook});e(n)}))}))},l=0;l<i.length;l++)r(l);Promise.all(s).then((function(t){console.log("syncCashBookEveryDay",t),e(null)}))}else console.log("syncCashBookEveryDay"),e(null)}),(function(t){console.log("syncCashBookEveryDay",t)}))}))},t.prototype.get1stDayOfMonthArray=function(t,e){var n=new Array;for(e=new Date(e),(t=new Date(t)).setDate(1),t.setHours(0),t.setMinutes(0),t.setSeconds(0),t.setMilliseconds(0),t.setMonth(t.getMonth()+1),e.setDate(1),e.setHours(0),e.setMinutes(0),e.setSeconds(0),e.setMilliseconds(0),e.setMonth(e.getMonth()-1);t.getTime()<=e.getTime();)n.push(new Date(t)),t.setMonth(t.getMonth()+1);return n},t.prototype.getValidityDate=function(t){var e=this;return new Promise((function(n,o){t=new Date(t),e.vhmongo_firebase.auth().getServerDate().then((function(o){(o=new Date(o)).setMonth(o.getMonth()-1),o.setDate(1),o.setHours(0),o.setMinutes(0),o.setSeconds(0),t.getTime()>o.getTime()?t.getTime()<new Date(e.vhAuth.getStore().registrationdate).getTime()?n(new Date(e.vhAuth.getStore().registrationdate)):n(null):o.getTime()<new Date(e.vhAuth.getStore().registrationdate).getTime()?n(new Date(e.vhAuth.getStore().registrationdate)):n(o)}))}))},t.prototype.getReportIncomeExpenditureDiary=function(t,e,n,o,i,a){var s=this;return new Promise((function(r,l){for(var c=[];i.length;){var u=i.splice(0,10);"all"===a||void 0===a?("all"===n&&"all"===o&&c.push(s.vhmongo_firebase.database().getDocsByFields("bills",{date:{$gte:t,$lte:e},bill_type:{$in:u}},{},{date:1},0)),"all"===n&&"all"!=o&&c.push(s.vhmongo_firebase.database().getDocsByFields("bills",{date:{$gte:t,$lte:e},id_employee:{$eq:o},bill_type:{$in:u}},{},{date:1},0)),"all"!=n&&"all"===o&&c.push(s.vhmongo_firebase.database().getDocsByFields("bills",{date:{$gte:t,$lte:e},id_wallet:{$eq:n},bill_type:{$in:u}},{},{date:1},0)),"all"!=n&&"all"!=o&&c.push(s.vhmongo_firebase.database().getDocsByFields("bills",{date:{$gte:t,$lte:e},id_wallet:{$eq:n},id_employee:{$eq:o},bill_type:{$in:u}},{},{date:1},0))):("all"===n&&"all"===o&&c.push(s.vhmongo_firebase.database().getDocsByFields("bills",{date:{$gte:t,$lte:e},bill_type:{$in:u},id_branch:{$eq:a}},{},{date:1},0)),"all"===n&&"all"!=o&&c.push(s.vhmongo_firebase.database().getDocsByFields("bills",{date:{$gte:t,$lte:e},id_employee:{$eq:o},bill_type:{$in:u},id_branch:{$eq:a}},{},{date:1},0)),"all"!=n&&"all"===o&&c.push(s.vhmongo_firebase.database().getDocsByFields("bills",{date:{$gte:t,$lte:e},id_wallet:{$eq:n},bill_type:{$in:u},id_branch:{$eq:a}},{},{date:1},0)),"all"!=n&&"all"!=o&&c.push(s.vhmongo_firebase.database().getDocsByFields("bills",{date:{$gte:t,$lte:e},id_wallet:{$eq:n},id_employee:{$eq:o},bill_type:{$in:u},id_branch:{$eq:a}},{},{date:1},0)))}Promise.all(c).then((function(t){var e=t.flat(),n={docs:new Array,empty:!0,size:0,income:0,expenditure:0};if(e.length>0)for(var o=0;o<e.length;o++){var i=Object.assign({},e[o]);2!=(null==i?void 0:i.payment_type)&&(1!==i.bill_type&&7!==i.bill_type&&10!==i.bill_type&&11!==i.bill_type&&15!==i.bill_type&&34!==i.bill_type||(n.income=n.income+i.payment,n.docs.push(i),n.size++,n.empty=!1),2!==i.bill_type&&3!==i.bill_type&&8!==i.bill_type&&12!==i.bill_type&&33!==i.bill_type||(n.expenditure=n.expenditure+i.payment,n.docs.push(i),n.size++,n.empty=!1))}console.log("json",n),r(n)}))}))},t.prototype.getDebtSuppliers=function(t,e,n,o){var i=this;t=new Date(t),e=new Date(e);var a=this.vhAuth.getStore();return new Promise((function(s,r){var l=new Array;if("all"===n)l=i.vhAlgorithm.sortVietnamesebyASC(i.getlocalSuppliers(),"name");else{var c=i.getlocalSupplier(n);l.push(c)}var u,d=i.getlocalBranchs(),_=i.getDefaultBranch()._id,p=null,b=null;if(null!=l[0][_]&&null!=l[0][_].debt)for(var f=0;f<l[0][_].debt.length&&!(new Date(l[0][_].debt[f].date).getTime()>t.getTime());f++)b=new Date(l[0][_].debt[f].date),p=f;b||(b=new Date(a.registrationdate)),u="all"===n?"all"===o||void 0===o?{date:{$gte:b,$lte:e},bill_type:{$in:[2,10,12]}}:{date:{$gte:b,$lte:e},bill_type:{$in:[2,10,12]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$gte:b,$lte:e},id_supplier:{$eq:n},bill_type:{$in:[2,10,12]}}:{date:{$gte:b,$lte:e},id_supplier:{$eq:n},bill_type:{$in:[2,10,12]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("bills",u,{},{date:1},0).then((function(e){for(var n,i,a={docs:new Array,debt_beginning:0,payment:0,debt:0,rest:0},r=0;r<l.length;r++){var c={_id:l[r]._id,name:l[r].name};a.docs.push(c);for(var u=0,_=0,b=0,f=0,h=0;h<e.length;h++)e[h].id_supplier===l[r]._id&&(new Date(e[h].date).getTime()>=t.getTime()?2===e[h].bill_type?(u+=e[h].total*(1+e[h].tax/100),_+=e[h].payment):12===e[h].bill_type?_+=e[h].payment:10===e[h].bill_type&&(_+=e[h].total*(1+e[h].tax/100),u+=e[h].payment):2===e[h].bill_type?f=f+e[h].total*(1+e[h].tax/100)-e[h].payment:10===e[h].bill_type?f=f+e[h].payment-e[h].total*(1+e[h].tax/100):12===e[h].bill_type&&(f-=e[h].payment));if("all"===o||void 0===o)for(h=0;h<d.length;h++)null!=l[r][d[h]._id]&&null!=l[r][d[h]._id].debt_beginning&&(b+=l[r][d[h]._id].debt_beginning);else null!=l[r][o]&&null!=l[r][o].debt_beginning&&(b=l[r][o].debt_beginning),null!=l[r][o]&&null!=l[r][o].debt&&(p||null!=l[r][o].debt[p]&&(f+=l[r][o].debt[p].debt_first));u=b+f+u,a.docs[a.docs.length-1].index=a.docs.length,a.docs[a.docs.length-1].debt=u,a.docs[a.docs.length-1].payment=_,a.docs[a.docs.length-1].rest=u-_,a.debt_beginning=a.debt_beginning+b,a.debt=a.debt+u,a.payment=a.payment+_,a.rest=a.rest+u-_;var y={docs:new Array,empty:!0,size:0,debt_beginning:b+f,debt:b+f,payment:0,rest:b+f};for(h=0;h<e.length;h++)if(l[r]._id===e[h].id_supplier&&new Date(e[h].date).getTime()>=t.getTime()){var m=Object.assign({},e[h]);null==m||delete m.discount,null==m||delete m.fee,null==m||delete m.id_supplier,null==m||delete m.note,null==m||delete m.payment_type,null==m||delete m.tax,y.docs.push(m),y.docs[y.docs.length-1].debt=0,y.docs[y.docs.length-1].payment=0,2===e[h].bill_type?(y.docs[y.docs.length-1].debt=e[h].total*(1+(null===(n=e[h])||void 0===n?void 0:n.tax)/100),y.docs[y.docs.length-1].payment=e[h].payment,y.docs[y.docs.length-1].rest=y.docs[y.docs.length-1].debt-y.docs[y.docs.length-1].payment):10===e[h].bill_type?(y.docs[y.docs.length-1].payment=e[h].total*(1+(null===(i=e[h])||void 0===i?void 0:i.tax)/100),y.docs[y.docs.length-1].debt=e[h].payment,y.docs[y.docs.length-1].rest=y.docs[y.docs.length-1].debt-y.docs[y.docs.length-1].payment):12===e[h].bill_type&&(y.docs[y.docs.length-1].payment=e[h].payment,y.docs[y.docs.length-1].rest=-e[h].payment),y.debt=y.debt+y.docs[y.docs.length-1].debt,y.payment=y.payment+y.docs[y.docs.length-1].payment,y.rest=y.rest+y.docs[y.docs.length-1].debt-y.docs[y.docs.length-1].payment,y.size++,y.empty=!1,y.docs[y.docs.length-1].index=y.docs.length}a.docs[a.docs.length-1].json=y}console.log("json",a),s(a)}))}))},t.prototype.getDebtCustomers=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=i.vhAuth.getStore(),l=new Array;if("all"===n)l=i.vhAlgorithm.sortVietnamesebyASC(i.getlocalCustomers().filter((function(t){return"id_retail"!=t._id})),"name");else{var c=i.getlocalCustomer(n);l.push(c)}var u,d=i.getlocalBranchs(),_=i.getDefaultBranch()._id,p=null,b=null;if(null!=l[0][_]&&null!=l[0][_].debt)for(var f=0;f<l[0][_].debt.length&&!(new Date(l[0][_].debt[f].date).getTime()>t.getTime());f++)b=new Date(l[0][_].debt[f].date),p=f;b||(b=new Date(r.registrationdate)),u="all"===n?"all"===o||void 0===o?{date:{$gte:b,$lte:e},bill_type:{$in:[1,3,11,15]}}:{date:{$gte:b,$lte:e},bill_type:{$in:[1,3,11,15]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$gte:b,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1,3,11,15]}}:{date:{$gte:b,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1,3,11,15]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("bills",u,{},{date:1},0).then((function(e){for(var n,i,s={docs:new Array,debt_beginning:0,payment:0,debt:0,rest:0},r=0;r<l.length;r++){var c={_id:l[r]._id,name:l[r].name};s.docs.push(c);for(var u=0,_=0,b=0,f=0,h=0;h<e.length;h++)e[h].id_customer===l[r]._id&&(new Date(e[h].date).getTime()>=t.getTime()?1===e[h].bill_type||15===e[h].bill_type?(u+=e[h].total*(1+e[h].tax/100),_+=e[h].payment):11===e[h].bill_type?_+=e[h].payment:3===e[h].bill_type&&(_+=e[h].total*(1+e[h].tax/100),u+=e[h].payment):1===e[h].bill_type||15===e[h].bill_type?f=f+e[h].total*(1+e[h].tax/100)-e[h].payment:11===e[h].bill_type?f-=e[h].payment:3===e[h].bill_type&&(f=f+e[h].payment-e[h].total*(1+e[h].tax/100)));if("all"===o||void 0===o)for(h=0;h<d.length;h++)null!=l[r][d[h]._id]&&null!=l[r][d[h]._id].debt_beginning&&(b+=l[r][d[h]._id].debt_beginning);else null!=l[r][o]&&null!=l[r][o].debt_beginning&&(b=l[r][o].debt_beginning),null!=l[r][o]&&null!=l[r][o].debt&&(p||null!=l[r][o].debt[p]&&(f+=l[r][o].debt[p].debt_first));u=b+f+u,s.docs[s.docs.length-1].index=s.docs.length,s.docs[s.docs.length-1].debt=u,s.docs[s.docs.length-1].payment=_,s.docs[s.docs.length-1].rest=u-_,s.debt_beginning=s.debt_beginning+b,s.debt=s.debt+u,s.payment=s.payment+_,s.rest=s.rest+u-_;var y={docs:new Array,empty:!0,size:0,debt_beginning:b+f,debt:b+f,payment:0,rest:b+f};for(h=0;h<e.length;h++)if(l[r]._id===e[h].id_customer&&new Date(e[h].date).getTime()>=t.getTime()){var m=Object.assign({},e[h]);null==m||delete m.discount,null==m||delete m.fee,null==m||delete m.id_customer,null==m||delete m.note,null==m||delete m.payment_type,null==m||delete m.tax,y.docs.push(m),y.docs[y.docs.length-1].debt=0,y.docs[y.docs.length-1].payment=0,1===e[h].bill_type||15===e[h].bill_type?(y.docs[y.docs.length-1].debt=e[h].total*(1+(null===(n=e[h])||void 0===n?void 0:n.tax)/100),y.docs[y.docs.length-1].payment=e[h].payment,y.docs[y.docs.length-1].rest=y.docs[y.docs.length-1].debt-y.docs[y.docs.length-1].payment):3===e[h].bill_type?(y.docs[y.docs.length-1].payment=e[h].total*(1+(null===(i=e[h])||void 0===i?void 0:i.tax)/100),y.docs[y.docs.length-1].debt=e[h].payment,y.docs[y.docs.length-1].rest=y.docs[y.docs.length-1].debt-y.docs[y.docs.length-1].payment):11===e[h].bill_type&&(y.docs[y.docs.length-1].payment=e[h].payment,y.docs[y.docs.length-1].rest=-e[h].payment),y.debt=y.debt+y.docs[y.docs.length-1].debt,y.payment=y.payment+y.docs[y.docs.length-1].payment,y.rest=y.rest+y.docs[y.docs.length-1].debt-y.docs[y.docs.length-1].payment,y.size++,y.empty=!1,y.docs[y.docs.length-1].index=y.docs.length}s.docs[s.docs.length-1].json=y}console.log("json",s),a(s)}))}))},t.prototype.getReportInventoryTime_byTimes=function(t){var e=this;return new Promise((function(n,o){var i=e.getlocalInventorytime(t),a=e.vhAlgorithm.sortVietnamesebyASC(e.getlocalProducts(1),"name"),s=e.getDefaultBranch()._id,r={docs:new Array,empty:!0,size:0};if(a.length>0){r={docs:new Array,empty:!0,size:0,total_stock:0,total_realstock:0,total_inventorynotes:new Array};var l=new Array,c=new Array,u=new Array,d=new Array,_={date:{$gte:new Date(a[0][s].inventory[a[0][s].inventory.length-1].date),$lte:new Date(i.date)},bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:s}};d[0]=new Promise((function(t,n){e.vhmongo_firebase.database().getDocsByFields("vhbill_details",_,{},{date:1},0).then((function(e){l=E(e),t(null)}))}));var p={id_inventorytime:{$eq:t},bill_type:{$in:[13]}};d[1]=new Promise((function(t,n){e.vhmongo_firebase.database().getDocsByFields("vhbill_details",p,{},{date:1},0).then((function(e){c=E(e),t(null)}))}));var b={id_inventorytime:{$eq:t},bill_type:{$in:[13]}};d[2]=new Promise((function(t,n){e.vhmongo_firebase.database().getDocsByFields("bills",b,{},{date:1},0).then((function(e){u=E(e),t(null)}))})),Promise.all(d).then((function(){for(var t=0,e=0,o=new Array,i=0;i<u.length;i++){var d={bill_code:u[i].bill_code,quantity:0};o.push(d)}for(var _=function(n){if(c.filter((function(t){return t.id_product===a[n]._id})).length>0){for(var i=a[n][s].inventory[a[n][s].inventory.length-1].stock_first,d=0;d<l.length;d++)if(1===l[d].ptype){if(l[d].id_product===a[n]._id){new Date(l[d].date);1===l[d].bill_type||10===l[d].bill_type||15===l[d].bill_type||30===l[d].bill_type?i-=l[d].quantity:2!==l[d].bill_type&&3!==l[d].bill_type&&31!==l[d].bill_type||(i+=l[d].quantity)}}else if(5===l[d].ptype)for(var _=0;_<l[d].combos.length;_++)l[d].combos[_].id_product===a[n]._id&&(i+=l[d].combos[_].quantity*l[d].quantity);var p=new Array,b=0;for(d=0;d<u.length;d++){var f={bill_code:u[d].bill_code,quantity:0};p.push(f)}for(d=0;d<c.length;d++)for(var h=0;h<p.length;h++)a[n]._id===c[d].id_product&&p[h].bill_code===c[d].bill_code&&(p[h].quantity=c[d].quantity,b+=c[d].quantity,o[h].quantity=o[h].quantity+c[d].quantity);t+=i,e+=b;var y={_id:a[n]._id,data:function(){var t=a[n];return delete a[n]._id,t},stock:i,realstock:b,inventorynotes:p};r.docs.push(y),r.empty=!1,r.size++}},p=0;p<a.length;p++)_(p);r.total_stock=t,r.total_realstock=e,r.total_inventorynotes=E(o),console.log("getReportInventoryTime_byTimes",r),n(r)}))}}))},t.prototype.getReportProducts_by3Time=function(t,e){var n=this;return new Promise((function(o,i){var a=n.getlocalProducts(),s={docs:new Array,empty:!0,size:0};a.length>0?(s={docs:new Array,empty:!0,size:0,outstock:0,instock:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0,profit_btax:0,profit_atax:0},n.vhmongo_firebase.database().getDocsByFields("vhbill_details",{bill_type:{$in:[1,10,15,2,3,9]}},{},{date:1},0).then((function(n){for(var i=function(o){for(var i=Object.assign({},a[o]),r={id:i._id,data:function(){return delete i._id,i},outstock:0,instock:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0,profit_btax:0,profit_atax:0,stock_first:0,stock_last:0,cost_stock_first_btax:0,cost_stock_first_atax:0,cost_stock_last_btax:0,cost_stock_last_atax:0},l=0,c=0,u=0,d=0,_=0;_<n.length;_++)if(n[_].id_product===a[o]._id&&n[_].date<=e){var p=n[_].date;1===n[_].bill_type||10===n[_].bill_type||15===n[_].bill_type?p>=t?(r.outstock=r.outstock+n[_].quantity,r.revenue_btax=r.revenue_btax+n[_].price,r.revenue_atax=r.revenue_atax+n[_].price*(1+n[_].tax/100)):(l+=n[_].quantity,n[_].price,n[_].price*(1+n[_].tax/100)):2!==n[_].bill_type&&3!==n[_].bill_type&&9!==n[_].bill_type||(p>=t?(r.instock=r.instock+n[_].quantity,r.cost_btax=r.cost_btax+n[_].price,r.cost_atax=r.cost_atax+n[_].price*(1+n[_].tax/100)):(c+=n[_].quantity,d+=n[_].price,u+=n[_].price*(1+n[_].tax/100)))}r.stock_first=c-l,r.stock_last=r.stock_first+r.instock-r.outstock,r.cost_stock_first_btax=r.stock_first*u/c,0!=c&&(r.cost_stock_first_atax=r.stock_first*r.cost_atax_0/c),c+r.instock!=0&&(r.cost_stock_last_btax=r.stock_last*(u+r.cost_btax)/(c+r.instock)),c+r.instock!=0&&(r.cost_stock_last_atax=r.stock_last*(r.cost_atax_0+r.cost_atax)/(c+r.instock)),l+r.outstock!=0&&c+r.instock!=0&&(r.profit_btax=r.outstock*((r.revenue_btax_0+r.revenue_btax)/(l+r.outstock)-(u+r.cost_btax)/(c+r.instock))),l+r.outstock!=0&&c+r.instock!=0&&(r.profit_atax=r.outstock*((r.revenue_atax_0+r.revenue_atax)/(l+r.outstock)-(d+r.cost_btax)/(c+r.instock))),s.outstock=s.outstock+r.outstock,s.revenue_btax=s.revenue_btax+r.revenue_btax,s.revenue_atax=s.revenue_atax+r.revenue_atax,s.instock=s.instock+r.instock,s.cost_btax=s.cost_btax+r.cost_btax,s.cost_atax=s.cost_atax+r.cost_atax,s.profit_btax=s.profit_btax+r.profit_btax,s.profit_atax=s.profit_atax+r.profit_atax,s.docs.push(r),s.size++,s.empty=!1},r=0;r<a.length;r++)i(r);o(s)}))):(console.log("server -> products khong ton tai trong CSDL: "),o(s))}))},t.prototype.getReportProduct_byID=function(t,e,n){var o=this;return new Promise((function(i,a){var s={docs:new Array,empty:!0,size:0},r={date:{$gte:t,$lte:e},id_product:{$eq:n},bill_type:{$in:[1,2,3,9,10,15]}};o.vhmongo_firebase.database().getDocsByFields("vhbill_details",r,{},{date:1},0).then((function(t){if(t.length>0)for(var e=function(e){var n={_id:t[e]._id,data:function(){var n=Object.assign({},t[e]);return n.date&&delete n.date,"number"==typeof n.tax&&delete n.tax,"number"==typeof n.bill_type&&delete n.bill_type,n.id_cashier&&delete n.id_cashier,n.id_employee&&delete n.id_employee,n.id_supplier&&delete n.id_supplier,n.id_customer&&delete n.id_customer,n},bill_type:t[e].bill_type,tax:t[e].tax,date:t[e].date};s.docs.push(n),s.size++,s.empty=!1},n=0;n<t.length;n++)e(n);i(s)}))}))},t.prototype.addEarningPointsBill=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("earning_points_bills",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateEarningPointsBill=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("earning_points_bills",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteEarningPointsBill=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("earning_points_bills",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getEarningPointsBill=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("earning_points_bills",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getEarningPointsBills=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("earning_points_bills").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.addEarningPointsProduct=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("earning_points_products",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateEarningPointsProduct=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("earning_points_products",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteEarningPointsProduct=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("earning_points_products",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getEarningPointsProduct=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("earning_points_products",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getEarningPointsProducts=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("earning_points_products").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.addEmployeeClass=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("employee_classs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateEmployeeClass=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("employee_classs",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteEmployeeClass=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("employee_classs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getEmployeeClass=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("employee_classs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getEmployeeClasss=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("employee_classs").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.getlocalEmployeeClasss=function(){},t.prototype.getlocalEmployeeClass=function(t){},t.prototype.addCoupon=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("coupons",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateCoupon=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("coupons",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteCoupon=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("coupons",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getCoupon=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("coupons",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getCoupons=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("coupons").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.addCouponRelease=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("coupon_releases",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateCouponRelease=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("coupon_releases",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteCouponRelease=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("coupon_releases",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getCouponRelease=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("coupon_releases",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getCouponReleases=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("coupon_releases").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.addCouponReleaseDetail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("coupon_release_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.deleteCouponReleaseDetail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("coupon_release_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getCouponReleaseDetail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("coupon_release_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getCouponRelaseDetail_byIdCouponRelease=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("coupon_release_details",{id_coupon_release:{$eq:t}},{}).then((function(t){n(t)})).catch((function(t){o(t)}))}))},t.prototype.createCouponCode=function(t){var e=this;return new Promise((function(n,o){var i=e.vhAlgorithm.createCardCode();e.vhmongo_firebase.database().getDoc("coupon_codes",i).then((function(a){a?(i=e.vhAlgorithm.createCardCode(),e.vhmongo_firebase.database().addDocbyID("coupon_codes",i,t).then((function(t){n(t)}),(function(t){o(t)}))):e.vhmongo_firebase.database().addDocbyID("coupon_codes",i,t).then((function(t){n(t)}),(function(t){o(t)}))}),(function(t){o(t)}))}))},t.prototype.createCouponCodes=function(t,e){var n=this;return new Promise((function(o,i){for(var a=new Array,s=0;s<e;s++)a[s]=n.createCouponCode(t);Promise.all(a).then((function(a){a=a.flat(),n.vhmongo_firebase.database().getDoc("coupon_release_details",t.id_coupon_release_detail).then((function(t){if(t)if(null!=t.quantity_released){var s={quantity_released:t.quantity_released+e};n.vhmongo_firebase.database().updateDoc("coupon_release_details",t._id,s).then((function(){o(a)}),(function(t){i(t)}))}else{s={quantity_released:e};n.vhmongo_firebase.database().updateDoc("coupon_release_details",t._id,s).then((function(){o(a)}),(function(t){i(t)}))}}),(function(t){i(t)}))})).catch((function(t){i(t)}))}))},t.prototype.updateCouponCode=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("coupon_codes",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteCouponCode=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().deleteDoc("coupon_codes",t).then((function(t){t?n.vhmongo_firebase.database().getDoc("coupon_release_details",e).then((function(t){if(t)if(null!=t.quantity_released){var e={quantity_released:t.quantity_released-1};n.vhmongo_firebase.database().updateDoc("coupon_release_details",t._id,e).then((function(){o(!0)}),(function(t){i(t)}))}else{e={quantity_released:0};n.vhmongo_firebase.database().updateDoc("coupon_release_details",t._id,e).then((function(){console.log("Báo anh Huy kiểm tra lại trường hợp này"),o(!0)}),(function(t){i(t)}))}}),(function(t){i(t)})):o(!1)}),(function(t){i(t)}))}))},t.prototype.getCouponCodes_byIdCouponReleaseDetail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("coupon_codes",{id_coupon_release_detail:{$eq:t}},{}).then((function(t){n(t)})).catch((function(t){o(t)}))}))},t.prototype.getCouponCodes_byFields=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.database().getDocsByFields("coupon_codes",t,{},n,o).then((function(t){e(t)})).catch((function(t){a(t)}))}))},t.prototype.getCouponCode=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("coupon_codes",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getCoupon_Code_Name_Release=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("coupon_codes",t).then((function(t){if(t){var i=JSON.parse(JSON.stringify(t));e.vhmongo_firebase.database().getDoc("coupon_release_details",t.id_coupon_release_detail).then((function(t){t?Promise.all([e.vhmongo_firebase.database().getDoc("coupons",t.id_coupon),e.vhmongo_firebase.database().getDoc("coupon_releases",t.id_coupon_release)]).then((function(t){i.name_coupon=t[0].name,i.name_coupon_release=t[1].name,n(i)})):n(null)}),(function(t){o(t)}))}else n(null)}),(function(t){o(t)}))}))},t.prototype.exchangeCouponCode_byEarningPoints=function(t,e,n){var o=this;return new Promise((function(i,a){for(var s=new Array,r=0;r<t.length;r++)s[r]=o.vhmongo_firebase.database().getDoc("coupon_codes",t[r]);s[s.length]=o.vhmongo_firebase.database().getDoc("customers",e),Promise.all(s).then((function(t){for(var a=new Array,s=0;s<t.length-1;s++){var r={status:3,id_customer:e,date_points_exchanged:new Date};a[s]=o.vhmongo_firebase.database().updateDoc("coupon_codes",t[s]._id,r)}var l=t[t.length-1];null!=l.earned_points?l.earned_points=l.earned_points-n:l.earned_points=0;var c=o.getDefaultBranch();null!=l.branch_earned_points?null!=l.branch_earned_points[c._id]?l.branch_earned_points[c._id]=l.branch_earned_points[c._id]-n:l.branch_earned_points[c._id]=0:l.branch_earned_points={};var u={earned_points:l.earned_points,branch_earned_points:l.branch_earned_points};a[a.length]=o.vhmongo_firebase.database().updateDoc("customers",l._id,u),Promise.all(a).then((function(){i(!0)}))}))}))},t.prototype.addVoucher=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("vouchers",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateVoucher=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("vouchers",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteVoucher=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("vouchers",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getVoucher=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("vouchers",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getVouchers=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("vouchers").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.addVoucherRelease=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("voucher_releases",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateVoucherRelease=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("voucher_releases",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteVoucherRelease=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("voucher_releases",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getVoucherRelease=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("voucher_releases",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getVoucherRelases=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("voucher_releases").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.addVoucherReleaseDetail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("voucher_release_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.deleteVoucherReleaseDetail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("voucher_release_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getVoucherReleaseDetail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("voucher_release_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getVoucherRelaseDetail_byFields=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.database().getDocsByFields("voucher_release_details",t,{},n,o).then((function(t){e(t)}),(function(t){a(t)}))}))},t.prototype.createVoucherCode=function(t){var e=this;return new Promise((function(n,o){var i=e.vhAlgorithm.createCardCode();e.vhmongo_firebase.database().getDoc("voucher_codes",i).then((function(a){a?(i=e.vhAlgorithm.createCardCode(),e.vhmongo_firebase.database().addDocbyID("voucher_codes",i,t).then((function(t){n(t)}),(function(t){o(t)}))):e.vhmongo_firebase.database().addDocbyID("voucher_codes",i,t).then((function(t){n(t)}),(function(t){o(t)}))}),(function(t){o(t)}))}))},t.prototype.createVoucherCodes=function(t,e){var n=this;return new Promise((function(o,i){for(var a=new Array,s=0;s<e;s++)a[s]=n.createVoucherCode(t);Promise.all(a).then((function(a){a=a.flat(),n.vhmongo_firebase.database().getDoc("voucher_release_details",t.id_voucher_release_detail).then((function(t){if(t)if(null!=t.quantity_released){var s={quantity_released:t.quantity_released+e};n.vhmongo_firebase.database().updateDoc("voucher_release_details",t._id,s).then((function(){o(a)}),(function(t){i(t)}))}else{s={quantity_released:e};n.vhmongo_firebase.database().updateDoc("voucher_release_details",t._id,s).then((function(){o(a)}),(function(t){i(t)}))}}),(function(t){i(t)}))})).catch((function(t){i(t)}))}))},t.prototype.updateVoucherCode=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("voucher_codes",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteVoucherCode=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().deleteDoc("voucher_codes",t).then((function(t){t?n.vhmongo_firebase.database().getDoc("voucher_release_details",e).then((function(t){if(t)if(null!=t.quantity_released){var e={quantity_released:t.quantity_released-1};n.vhmongo_firebase.database().updateDoc("voucher_release_details",t._id,e).then((function(){o(!0)}),(function(t){i(t)}))}else{e={quantity_released:0};n.vhmongo_firebase.database().updateDoc("voucher_release_details",t._id,e).then((function(){console.log("Báo anh Huy kiểm tra lại trường hợp này"),o(!0)}),(function(t){i(t)}))}}),(function(t){i(t)})):o(!1)}),(function(t){i(t)}))}))},t.prototype.getVoucherCodes_byIdCouponReleaseDetail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("voucher_codes",{id_voucher_release_detail:{$eq:t}},{}).then((function(t){n(t)})).catch((function(t){o(t)}))}))},t.prototype.getVoucherCodes_byFields=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.database().getDocsByFields("voucher_codes",t,{},n,o).then((function(t){e(t)})).catch((function(t){a(t)}))}))},t.prototype.getVoucherCode=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("voucher_codes",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getVoucher_Code_Name_Release=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("voucher_codes",t).then((function(t){if(t){var i=JSON.parse(JSON.stringify(t));e.vhmongo_firebase.database().getDoc("voucher_release_details",t.id_voucher_release_detail).then((function(t){t?Promise.all([e.vhmongo_firebase.database().getDoc("vouchers",t.id_voucher),e.vhmongo_firebase.database().getDoc("voucher_releases",t.id_voucher_release)]).then((function(t){i.name_voucher=t[0].name,i.name_voucher_release=t[1].name,n(i)})):n(null)}),(function(t){o(t)}))}else n(null)}),(function(t){o(t)}))}))},t.prototype.exchangeVoucherCode_byEarningPoints=function(t,e,n){var o=this;return new Promise((function(i,a){for(var s=new Array,r=0;r<t.length;r++)s[r]=o.vhmongo_firebase.database().getDoc("voucher_codes",t[r]);s[s.length]=o.vhmongo_firebase.database().getDoc("customers",e),Promise.all(s).then((function(t){for(var a=new Array,s=0;s<t.length-1;s++){var r={status:3,id_customer:e,date_points_exchanged:new Date};a[s]=o.vhmongo_firebase.database().updateDoc("voucher_codes",t[s]._id,r)}var l=t[t.length-1];null!=l.earned_points?l.earned_points=l.earned_points-n:l.earned_points=0;var c=o.getDefaultBranch();null!=l.branch_earned_points?null!=l.branch_earned_points[c._id]?l.branch_earned_points[c._id]=l.branch_earned_points[c._id]-n:l.branch_earned_points[c._id]=0:l.branch_earned_points={};var u={earned_points:l.earned_points,branch_earned_points:l.branch_earned_points};a[a.length]=o.vhmongo_firebase.database().updateDoc("customers",l._id,u),Promise.all(a).then((function(){i(!0)}))}))}))},t.prototype.addPaymentCard=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("payment_cards",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updatePaymentCard=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("payment_cards",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deletePaymentCard=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("payment_cards",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPaymentCard=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("payment_cards",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPaymentCards=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("payment_cards").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.addPaymentCardRelease=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("payment_card_releases",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updatePaymentCardRelease=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("payment_card_releases",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deletePaymentCardRelease=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("payment_card_releases",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPaymentCardRelease=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("payment_card_releases",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPaymentCardReleases=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("payment_card_releases").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.addPaymentCardReleaseDetail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("payment_card_release_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.deletePaymentCardReleaseDetail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("payment_card_release_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPaymentCardReleaseDetail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("payment_card_release_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPaymentCardRelaseDetail_byFields=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.database().getDocsByFields("payment_card_release_details",t,{},n,o).then((function(t){e(t)}),(function(t){a(t)}))}))},t.prototype.createPaymentCardCode=function(t){var e=this;return new Promise((function(n,o){var i=e.vhAlgorithm.createCardCode();e.vhmongo_firebase.database().getDoc("payment_card_codes",i).then((function(a){a?(i=e.vhAlgorithm.createCardCode(),e.vhmongo_firebase.database().addDocbyID("payment_card_codes",i,t).then((function(t){n(t)}),(function(t){o(t)}))):e.vhmongo_firebase.database().addDocbyID("payment_card_codes",i,t).then((function(t){n(t)}),(function(t){o(t)}))}),(function(t){o(t)}))}))},t.prototype.createPaymentCardCodes=function(t,e){var n=this;return new Promise((function(o,i){for(var a=new Array,s=0;s<e;s++)a[s]=n.createPaymentCardCode(t);Promise.all(a).then((function(a){a=a.flat(),n.vhmongo_firebase.database().getDoc("payment_card_release_details",t.id_payment_card_release_detail).then((function(t){if(t)if(null!=t.quantity_released){var s={quantity_released:t.quantity_released+e};n.vhmongo_firebase.database().updateDoc("payment_card_release_details",t._id,s).then((function(){o(a)}),(function(t){i(t)}))}else{s={quantity_released:e};n.vhmongo_firebase.database().updateDoc("payment_card_release_details",t._id,s).then((function(){o(a)}),(function(t){i(t)}))}}),(function(t){i(t)}))})).catch((function(t){i(t)}))}))},t.prototype.updatePaymentCardCode=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("payment_card_codes",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deletePaymentCardCode=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().deleteDoc("payment_card_codes",t).then((function(t){t?n.vhmongo_firebase.database().getDoc("payment_card_release_details",e).then((function(t){if(t)if(null!=t.quantity_released){var e={quantity_released:t.quantity_released-1};n.vhmongo_firebase.database().updateDoc("payment_card_release_details",t._id,e).then((function(){o(!0)}),(function(t){i(t)}))}else{e={quantity_released:0};n.vhmongo_firebase.database().updateDoc("payment_card_release_details",t._id,e).then((function(){console.log("Báo anh Huy kiểm tra lại trường hợp này"),o(!0)}),(function(t){i(t)}))}}),(function(t){i(t)})):o(!1)}),(function(t){i(t)}))}))},t.prototype.getPaymentCardCodes_byIdPaymentCardReleaseDetail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("payment_card_codes",{id_payment_card_release_detail:{$eq:t}},{}).then((function(t){n(t)})).catch((function(t){o(t)}))}))},t.prototype.getPaymentCardCodes_byFields=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.database().getDocsByFields("payment_card_codes",t,{},n,o).then((function(t){e(t)})).catch((function(t){a(t)}))}))},t.prototype.getPaymentCardCode=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("payment_card_codes",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPaymentCard_Code_Name_Release=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("payment_cards",t).then((function(t){if(t){var i=JSON.parse(JSON.stringify(t));e.vhmongo_firebase.database().getDoc("payment_card_release_details",t.id_payment_card_release_detail).then((function(t){t?Promise.all([e.vhmongo_firebase.database().getDoc("payment_cards",t.id_payment_card),e.vhmongo_firebase.database().getDoc("payment_card_releases",t.id_payment_card_release)]).then((function(t){i.name_payment_card=t[0].name,i.name_payment_card_release=t[1].name,n(i)})):n(null)}),(function(t){o(t)}))}else n(null)}),(function(t){o(t)}))}))},t.prototype.updateComboPaymentCard=function(t,e,n){},t}();Y.decorators=[{type:e.Injectable}],Y.ctorParameters=function(){return[{type:o.Vhmongo_firebase},{type:V},{type:F},{type:L},{type:u.InAppPurchase2},{type:d.Platform}]};var Z=function(){function t(t,e,n,o){var i=this;this.vhmongo_firebase=t,this.vhQuery=e,this.vhAuth=n,this.vhAlgorithm=o,this.cloudcams=new Array,this.mainboards=new Array,this.functions=new Array,this.components=new Array,this.icons=new Array,this.zones=new Array,this.appsettingstations=new Array,this.scripts=new Array,this.script_details=new Array,this.logs=new Array,this.hwinfo={},r.Device.getId().then((function(t){var e=i.vhAuth.localStorageGET("hwinfo");null!=e&&null!=e?i.hwinfo=e:(i.hwinfo=Object.assign({},t),i.vhAuth.localStorageSET("hwinfo",i.hwinfo))}))}return t.prototype.startLocalStorage=function(){var t=this;return new Promise((function(e){t.getEUtokenfromDatabase().then((function(){var n=new Array;n[0]=t.vhAuth.refreshLocalMyPermission(),n[1]=t.refreshLocalComponents(),n[2]=t.refreshLocalFunctions(),n[3]=t.refreshLocalIcons(),n[4]=t.refreshLocalMainboards(),n[5]=t.refreshLocalZones(),n[6]=t.refreshLocalCloudCams(),Promise.all(n).then((function(){e(null)}))}))}))},t.prototype.getEUtokenfromDatabase=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.f3rdclouds().getEUtokenfromDatabase().then((function(){e(null)}))}))},t.prototype.getPlaybackListCamByEndUser=function(t,e,n,o){var i=this;return new Promise((function(a,s){i.vhmongo_firebase.f3rdclouds().getPlaybackListCambyEndUser(t,e,n,o).then((function(t){0===t.vcode?a(t.data):(console.log(t),a([]))}),(function(t){s(t)}))}))},t.prototype.getlocalCloudCam=function(t){for(var e=0;e<this.cloudcams.length;e++)if(this.cloudcams[e].licensecam===t)return Object.assign({},this.cloudcams[e]);return null},t.prototype.getlocalCloudCams=function(){return E(this.cloudcams)},t.prototype.refreshLocalCloudCams=function(){var t=this;return new Promise((function(e){t.getCloudCams().then((function(){e(null)}))}))},t.prototype.changeCloudCamEnableDetector=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().changeCloudCamEnableDetectorByEndUser(t,e).then((function(i){if(0===i.vcode){for(var a=0;a<n.cloudcams.length;a++)if(n.cloudcams[a].licensecam===t){n.cloudcams[a].detector_enable=e;break}o(!0)}else console.log(i.message),o(!1)}))}))},t.prototype.changeCloudCamEnableRecord=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().changeCloudCamEnableRecordByEndUser(t,e).then((function(i){if(0===i.vcode){for(var a=0;a<n.cloudcams.length;a++)if(n.cloudcams[a].licensecam===t){n.cloudcams[a].record_enable=e;break}o(!0)}else console.log(i.message),o(!1)}))}))},t.prototype.changeCloudCamEnableActive=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().changeCloudCamEnableActiveByEndUser(t,e).then((function(i){if(0===i.vcode){for(var a=0;a<n.cloudcams.length;a++)if(n.cloudcams[a].licensecam===t){n.cloudcams[a].active=e;break}o(!0)}else console.log(i.message),o(!1)}))}))},t.prototype.changeCloudCamURL=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().changeCloudCamURLbyEndUser(t,e).then((function(i){if(0===i.vcode){for(var a=0;a<n.cloudcams.length;a++)if(n.cloudcams[a].licensecam===t){n.cloudcams[a].url=e;break}o(!0)}else console.log(i.message),o(!1)}))}))},t.prototype.deleteCloudCam=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.f3rdclouds().deleteCloudCamByEndUser(t).then((function(o){if(0===o.vcode){for(var i=0;i<e.cloudcams.length;i++)if(e.cloudcams[i].licensecam===t){e.cloudcams[i].splice(i,1);break}n(!0)}else console.log(o.message),n(!1)}))}))},t.prototype.updateCloudCam=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().updateCloudCamDataByEndUser(t,e).then((function(i){if(0===i.vcode){for(var a=0;a<n.cloudcams.length;a++)if(n.cloudcams[a].licensecam===t)for(var s in e)n.cloudcams[a].data[s]=e[s];o(!0)}else console.log(i.message),o(!1)}))}))},t.prototype.addCloudCam=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().addCloudCamByEndUser(t,e).then((function(t){0===t.vcode?(n.cloudcams.push(t.data),o(t.data)):(console.log(t.message),o(null))}))}))},t.prototype.getCloudCams=function(){var t=this;return new Promise((function(e,n){var o={id_enduser:{$eq:t.vhmongo_firebase.auth().getUID()}};t.vhmongo_firebase.f3rdclouds().getCloudCamsByDataFieldsByEndUser(o,{},{},0).then((function(n){t.cloudcams=new Array,0===n.vcode?t.cloudcams=n.data:console.log(n),e(t.cloudcams)}),(function(t){n(t)}))}))},t.prototype.getlocalFunction=function(t){for(var e=0;e<this.functions.length;e++)if(this.functions[e]._id===t)return this.functions[e];return null},t.prototype.getlocalFunctions=function(){return this.functions},t.prototype.refreshLocalFunctions=function(){var t=this;return new Promise((function(e){t.getFunctions().then((function(){e(null)}))}))},t.prototype.addFunction=function(t){var e=this;return new Promise((function(n,o){var i=Object.assign({},t);i.id_enduser=e.vhAuth.getUID(),e.vhmongo_firebase.database().addDoc("functions",i).then((function(t){e.functions.push(t),n(t)}),(function(t){o(t)}))}))},t.prototype.updateFunction=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("functions",t,e).then((function(i){for(var a=0;a<n.functions.length;a++)if(n.functions[a]._id===t){n.functions[a]=Object.assign(Object.assign({},n.functions[a]),{data:e});break}o(i)}),(function(t){i(t)}))}))},t.prototype.deleteFunction=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("functions",t).then((function(o){for(var i=0;e.functions.length;i++)if(e.functions[i]._id===t){e.functions.splice(i,1);break}n(o)}),(function(t){o(t)}))}))},t.prototype.getFunctions=function(){var t=this;return new Promise((function(e,n){var o=t.vhAuth.getUID();t.vhmongo_firebase.database().getDocsByFields("functions",{id_enduser:{$eq:o}},{},{},0).then((function(n){var o;t.functions=E(n);for(var i=0;i<t.functions.length;i++)null===(o=t.functions[i])||void 0===o||delete o.id_enduser;e(n)}),(function(t){n(t)}))}))},t.prototype.getFunctions_byFields=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.database().getDocsByFields("functions",t,{},n,o).then((function(t){e(t)}),(function(t){a(t)}))}))},t.prototype.getlocalComponent=function(t){for(var e=0;e<this.components.length;e++)if(this.components[e]._id===t)return this.components[e];return null},t.prototype.getlocalComponents=function(){return this.components},t.prototype.refreshLocalComponents=function(){var t=this;return new Promise((function(e){t.getComponents().then((function(){e(null)}))}))},t.prototype.addComponent=function(t){var e=this;return new Promise((function(n,o){var i=Object.assign({},t);i.id_enduser=e.vhAuth.getUID(),e.vhmongo_firebase.database().addDoc("components",i).then((function(t){e.components.push(t),n(t)}),(function(t){o(t)}))}))},t.prototype.updateComponent=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("components",t,e).then((function(i){for(var a=0;a<n.components.length;a++)if(n.components[a]._id===t){n.components[a]=Object.assign(Object.assign({},n.components[a]),e);break}o(i)}),(function(t){i(t)}))}))},t.prototype.deleteComponent=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("components",t).then((function(o){for(var i=0;e.components.length;i++)if(e.components[i]._id===t){e.components.splice(i,1);break}n(o)}),(function(t){o(t)}))}))},t.prototype.getComponents=function(){var t=this;return new Promise((function(e,n){var o=t.vhAuth.getUID();t.vhmongo_firebase.database().getDocsByFields("components",{id_enduser:{$eq:o}},{},{},0).then((function(n){var o;t.components=E(n);for(var i=0;i<t.components.length;i++)null===(o=t.components[i])||void 0===o||delete o.id_enduser;e(n)}),(function(t){n(t)}))}))},t.prototype.getComponents_byFields=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.database().getDocsByFields("components",t,{},n,o).then((function(t){e(t)}),(function(t){a(t)}))}))},t.prototype.getlocalIcon=function(t){for(var e=0;e<this.icons.length;e++)if(this.icons[e]._id===t)return this.icons[e];return null},t.prototype.getlocalIcons=function(){return this.icons},t.prototype.refreshLocalIcons=function(){var t=this;return new Promise((function(e){t.getIcons().then((function(){e(null)}))}))},t.prototype.addIcon=function(t){var e=this;return new Promise((function(n,o){var i=Object.assign({},t);i.id_enduser=e.vhAuth.getUID(),e.vhmongo_firebase.database().addDoc("icons",i).then((function(t){e.icons.push(t),n(t)}),(function(t){o(t)}))}))},t.prototype.updateIcon=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("icons",t,e).then((function(i){for(var a=0;a<n.icons.length;a++)if(n.icons[a]._id===t){n.icons[a]=Object.assign(Object.assign({},n.icons[a]),e);break}o(i)}),(function(t){i(t)}))}))},t.prototype.deleteIcon=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("icons",t).then((function(o){for(var i=0;e.icons.length;i++)if(e.icons[i]._id===t){e.icons.splice(i,1);break}n(o)}),(function(t){o(t)}))}))},t.prototype.getIcons=function(){var t=this;return new Promise((function(e,n){var o=t.vhAuth.getUID();t.vhmongo_firebase.database().getDocsByFields("icons",{id_enduser:{$eq:o}},{},{},0).then((function(n){var o;t.icons=E(n);for(var i=0;i<t.icons.length;i++)null===(o=t.icons[i])||void 0===o||delete o.id_enduser;e(n)}),(function(t){n(t)}))}))},t.prototype.getIcons_byFields=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.database().getDocsByFields("icons",t,{},n,o).then((function(t){e(t)}),(function(t){a(t)}))}))},t.prototype.getlocalMainboard=function(t){for(var e=0;e<this.mainboards.length;e++)if(this.mainboards[e]._id===t)return this.mainboards[e];return null},t.prototype.getlocalMainboards=function(){return this.mainboards},t.prototype.refreshLocalMainboards=function(){var t=this;return new Promise((function(e){t.getMainboards().then((function(){e(null)}))}))},t.prototype.addMainboard=function(t){var e=this;return new Promise((function(n,o){var i=Object.assign({},t);i.id_enduser=e.vhAuth.getUID(),e.vhmongo_firebase.database().addDoc("mainboards",i).then((function(t){e.icons.push(t),n(t)}),(function(t){o(t)}))}))},t.prototype.updateMainboard=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("mainboards",t,e).then((function(i){for(var a=0;a<n.mainboards.length;a++)if(n.mainboards[a]._id===t){n.mainboards[a]=Object.assign(Object.assign({},n.mainboards[a]),e);break}o(i)}),(function(t){i(t)}))}))},t.prototype.deleteMainboard=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("mainboards",t).then((function(o){for(var i=0;e.mainboards.length;i++)if(e.mainboards[i]._id===t){e.mainboards.splice(i,1);break}n(o)}),(function(t){o(t)}))}))},t.prototype.getMainboard=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("mainboards",t).then((function(t){n(t)}))}))},t.prototype.getMainboards=function(){var t=this;return new Promise((function(e,n){var o=t.vhAuth.getUID();t.vhmongo_firebase.database().getDocsByFields("mainboards",{id_enduser:{$eq:o}},{},{},0).then((function(n){var o;t.mainboards=E(n);for(var i=0;i<t.mainboards.length;i++)null===(o=t.mainboards[i])||void 0===o||delete o.id_enduser;e(n)}),(function(t){n(t)}))}))},t.prototype.getMainboards_byFields=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.database().getDocsByFields("mainboards",t,{},n,o).then((function(t){e(t)}),(function(t){a(t)}))}))},t.prototype.getlocalZone=function(t){for(var e=0;e<this.zones.length;e++)if(this.zones[e]._id===t)return this.zones[e];return null},t.prototype.getlocalZones=function(){return this.zones},t.prototype.refreshLocalZones=function(){var t=this;return new Promise((function(e){t.getZones().then((function(){e(null)}))}))},t.prototype.addZone=function(t){var e=this;return new Promise((function(n,o){var i=Object.assign({},t);i.id_enduser=e.vhAuth.getUID(),e.vhmongo_firebase.database().addDoc("zones",i).then((function(t){e.zones.push(t),n(t)}),(function(t){o(t)}))}))},t.prototype.updateZone=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("zones",t,e).then((function(i){for(var a=0;a<n.zones.length;a++)if(n.zones[a]._id===t){n.zones[a]=Object.assign(Object.assign({},n.zones[a]),e);break}o(i)}),(function(t){i(t)}))}))},t.prototype.deleteZone=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("zones",t).then((function(o){for(var i=0;e.zones.length;i++)if(e.zones[i]._id===t){e.zones.splice(i,1);break}n(o)}),(function(t){o(t)}))}))},t.prototype.getZones=function(){var t=this;return new Promise((function(e,n){var o=t.vhAuth.getUID();t.vhmongo_firebase.database().getDocsByFields("zones",{id_enduser:{$eq:o}},{},{},0).then((function(n){var o;t.zones=E(n);for(var i=0;i<t.zones.length;i++)null===(o=t.zones[i])||void 0===o||delete o.id_enduser;e(n)}),(function(t){n(t)}))}))},t.prototype.getZones_byFields=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.database().getDocsByFields("zones",t,{},n,o).then((function(t){e(t)}),(function(t){a(t)}))}))},t}();Z.decorators=[{type:e.Injectable}],Z.ctorParameters=function(){return[{type:o.Vhmongo_firebase},{type:V},{type:F},{type:L}]};var K=function(){function t(t,e,n,o){var i=this;this.vhmongo_firebase=t,this.vhQuery=e,this.vhAuth=n,this.vhAlgorithm=o,this.cameras=new Array,this.provinces=new Array,this.rooms=new Array,this.positions=new Array,this.areas=new Array,this.mainboards=new Array,this.functions=new Array,this.components=new Array,this.icons=new Array,this.appsettingstations=new Array,this.scripts=new Array,this.script_details=new Array,this.logs=new Array,this.hwinfo={},this.subjectcameras=new c.Subject,this.subjectappsettingstations=new c.Subject,this.subjectrooms=new c.Subject,this.subjectmainboards=new c.Subject,this.subjectfunctions=new c.Subject,this.subjecticons=new c.Subject,this.subjectpositions=new c.Subject,this.subjectareas=new c.Subject,this.subjectpages=new c.Subject,this.subjectcomponents=new c.Subject,r.Device.getId().then((function(t){var e=i.vhAuth.localStorageGET("hwinfo");null!=e&&null!=e?i.hwinfo=e:(i.hwinfo=Object.assign({},t),i.vhAuth.localStorageSET("hwinfo",i.hwinfo))}))}return t.prototype.syncCollections=function(){var t=this;return new Promise((function(e,n){t.initSyncCollections(),t.callbackCollectionInsert().subscribe(),t.callbackCollectionUpdate().subscribe(),t.callbackCollectionDelete().subscribe(),t.getEUtokenfromDatabase(),setTimeout((function(){e(!0)}),3e3)}))},t.prototype.initSyncCollections=function(){var t=new Array;return t[8]="vhemployees",t[9]="appsettingstations",this.vhmongo_firebase.socketMongoDB().initSyncCollections(t)},t.prototype.closeSyncCollections=function(){this.vhmongo_firebase.socketMongoDB().closeSyncCollections()},t.prototype.callbackCollectionInsert=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackCollectionInsert().subscribe((function(n){if("vhemployees"===n.colname?n.colname="employees":"appsettingstations"===n.colname&&(n.colname="appsettingstations"),"employees"===n.colname)(o=Object.assign({},n.data))._id=n._id,t.vhAuth.insertlocalEmployeeFromSyncCollection(o),t.vhAuth.publishObservableEventEmployees(),e.next(n.colname);else if("appsettingstations"===n.colname){var o;if(!t.getLocalAppSettingStation(n._id))if(n.data.uuid===t.hwinfo.uuid)(o=Object.assign({},n.data))._id=n._id,delete o.uuid,t.appsettingstations.push(o),t.publishObservableEventAppSettingNameStations(),e.next(n.colname)}console.log("inserted",n.colname)}))}))},t.prototype.callbackCollectionUpdate=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackCollectionUpdate().subscribe((function(n){if("vhemployees"===n.colname?n.colname="employees":"appsettingstations"===n.colname&&(n.colname="appsettingstations"),"employees"===n.colname)t.vhAuth.updateLocalEmployeeFromSyncCollection(n._id,n.data),t.vhAuth.publishObservableEventEmployees(),e.next(n.colname);else if("appsettingstations"===n.colname)for(var o=0;o<t.appsettingstations.length;o++)if(t.appsettingstations[o]._id===n._id){t.appsettingstations[o]=Object.assign(Object.assign({},t.appsettingstations[o]),n.data),t.publishObservableEventAppSettingNameStations(),e.next(n.colname);break}console.log("updated",n.colname)}))}))},t.prototype.callbackCollectionDelete=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackCollectionDelete().subscribe((function(n){if("vhemployees"===n.colname?n.colname="employees":"appsettingstations"===n.colname&&(n.colname="appsettingstations"),"employees"===n.colname)t.vhAuth.deleteLocalEmployeeFromSyncCollection(n._id),t.vhAuth.publishObservableEventEmployees(),e.next(n.colname);else if("appsettingstations"===n.colname)for(var o=0;o<t.appsettingstations.length;o++)if(t.appsettingstations[o]._id===n._id){t.appsettingstations.splice(o,1),t.publishObservableEventAppSettingNameStations(),e.next(n.colname);break}console.log("deleted",n.colname)}))}))},t.prototype.startLocalStorage=function(){var t=this;return new Promise((function(e){var n=new Array;n[0]=t.vhAuth.refreshLocalMyPermission(),n[1]=t.refreshLocalProvinces(),t.vhQuery.asyncPromiseAll(n).then((function(){e(null)}))}))},t.prototype.publishObservableEventCameras=function(){this.subjectcameras.next(this.cameras)},t.prototype.observableLocalCameras=function(){return this.subjectcameras},t.prototype.getObservableLocalCameras=function(){var t=this;return new c.Observable((function(e){t.observableLocalCameras().subscribe((function(t){e.next(t)})),t.publishObservableEventCameras()}))},t.prototype.getlocalCamera=function(t){for(var e=0;e<this.cameras.length;e++)if(this.cameras[e]._id===t)return this.cameras[e];return null},t.prototype.getlocalCameras=function(){return this.cameras},t.prototype.refreshLocalCameras=function(){var t=this;return new Promise((function(e){t.getCameras().then((function(){e(null)}))}))},t.prototype.addCamera=function(t){return new Promise((function(t,e){}))},t.prototype.updateCamera=function(t,e){return new Promise((function(t,e){}))},t.prototype.deleteCamera=function(t){return new Promise((function(t,e){}))},t.prototype.getCamera=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("cameras",t).then((function(t){n(t)}))}))},t.prototype.getCameras=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("cameras").then((function(n){t.cameras=new Array,t.cameras=n,e(n)}),(function(t){n(t)}))}))},t.prototype.getLocalEUtoken=function(){return this.vhmongo_firebase.f3rdclouds().getLocalEUtoken()},t.prototype.getEUtokenfromDatabase=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.f3rdclouds().getEUtokenfromDatabase().then((function(){e(null)}))}))},t.prototype.checkExpiredUtoken=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.f3rdclouds().checkExpiredUtoken().then((function(t){0===t.vcode?e(!0):(console.log(t.message),e(!1))}))}))},t.prototype.changeCloudCamEnableCLPRbyEndUser=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().changeCloudCamEnableCLPRbyEndUser(t,e).then((function(t){0===t.vcode?o(!0):(console.log(t.message),o(!1))}))}))},t.prototype.changeCloudCamEnableRLPRbyEndUser=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().changeCloudCamEnableRLPRbyEndUser(t,e).then((function(t){0===t.vcode?o(!0):(console.log(t.message),o(!1))}))}))},t.prototype.changeCloudCamEnableDetectorByEndUser=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().changeCloudCamEnableDetectorByEndUser(t,e).then((function(t){0===t.vcode?o(!0):(console.log(t.message),o(!1))}))}))},t.prototype.changeCloudCamEnableRecordByEndUser=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().changeCloudCamEnableRecordByEndUser(t,e).then((function(t){0===t.vcode?o(!0):(console.log(t.message),o(!1))}))}))},t.prototype.changeCloudCamEnableActiveByEndUser=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().changeCloudCamEnableActiveByEndUser(t,e).then((function(t){0===t.vcode?o(!0):(console.log(t.message),o(!1))}))}))},t.prototype.changeCloudCamURLbyEndUser=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().changeCloudCamURLbyEndUser(t,e).then((function(t){0===t.vcode?o(!0):(console.log(t.message),o(!1))}))}))},t.prototype.addCloudCamByEndUser=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().addCloudCamByEndUser(t,e).then((function(t){0===t.vcode?o(t.data):(console.log(t.message),o(null))}))}))},t.prototype.updateCloudCamDataByEndUser=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().updateCloudCamDataByEndUser(t,e).then((function(t){0===t.vcode?o(!0):(console.log(t.message),o(!1))}))}))},t.prototype.deleteCloudCamByEndUser=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.f3rdclouds().deleteCloudCamByEndUser(t).then((function(t){0===t.vcode?n(!0):(console.log(t.message),n(!1))}))}))},t.prototype.getCloudCamByEndUser=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.f3rdclouds().getCloudCamByEndUser(t).then((function(t){0===t.vcode?n(t.data):(console.log(t.message),n(null))}))}))},t.prototype.getCloudCamsByDataFieldsByEndUser=function(t,e,n,o){var i=this;return new Promise((function(a,s){i.vhmongo_firebase.f3rdclouds().getCloudCamsByDataFieldsByEndUser(t,e,n,o).then((function(t){var e=new Array;0===t.vcode?e=E(t.data):console.log(t),a(e)}),(function(t){s(t)}))}))},t.prototype.getPlaybackListCamByEndUser=function(t,e,n,o){var i=this;return new Promise((function(a,s){i.vhmongo_firebase.f3rdclouds().getPlaybackListCambyEndUser(t,e,n,o).then((function(t){0===t.vcode?a(t.data):(console.log(t),a([]))}),(function(t){s(t)}))}))},t.prototype.getlocalProvince=function(t){for(var e=function(e){if(n.provinces[e]._id===t){var o=Object.assign({},n.provinces[e]);if(null!=o.subs){var i=E(o.subs);o.subs=new Array,i.forEach((function(t){o.subs.push(Object.assign({},t))}))}return{value:o}}},n=this,o=0;o<this.provinces.length;o++){var i=e(o);if("object"==typeof i)return i.value}return null},t.prototype.getlocalProvinces=function(){return this.provinces},t.prototype.refreshLocalProvinces=function(){var t=this;return new Promise((function(e){t.getProvinces().then((function(){e(null)}))}))},t.prototype.addProvince=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("provinces",t).then((function(t){e.provinces.push(t),n(t)}),(function(t){o(t)}))}))},t.prototype.updateProvince=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("provinces",t,e).then((function(i){for(var a=0;a<n.provinces.length;a++)if(n.provinces[a]._id===t){n.provinces[a]=E(n.provinces[a],[e]);break}o(i)}),(function(t){i(t)}))}))},t.prototype.deleteProvince=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("provinces",t).then((function(o){for(var i=0;i<e.provinces.length;i++)if(e.provinces[i]._id===t){e.provinces.splice(i,1);break}n(o)}),(function(t){o(t)}))}))},t.prototype.getProvinces=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("provinces").then((function(n){t.provinces=new Array,t.provinces=n,e(n)}),(function(t){n(t)}))}))},t.prototype.addSubsProvince=function(t,e){var n=this;return new Promise((function(o,i){for(var a=new Array,s=0;s<e.length;s++)a[s]=Object.assign(Object.assign({},e[s]),{_id:n.vhAlgorithm.ObjectId()});var r,l=!1,c=0,u=setInterval((function(){if(c++,r=n.getlocalProvince(t)){l=!0,void 0===r.subs&&(r.subs=new Array);var e=E(r.subs,a);n.vhmongo_firebase.database().updateDoc("provinces",t,{subs:e}).then((function(){for(var i=0;i<n.provinces.length;i++)if(n.provinces[i]._id===t){n.provinces[i].subs=e;break}o(a)}),(function(){o(null)}))}!0!==l&&20!==c||clearInterval(u)}),100)}))},t.prototype.updateSubProvince=function(t,e,n){var o=this;return new Promise((function(i,a){var s=o.getlocalProvince(t);if(null!=s.subs)for(var r=function(r){if(s.subs[r]._id===e){for(var l in n)s.subs[r][l]=n[l];var c=E(s.subs);return o.vhmongo_firebase.database().updateDoc("provinces",t,{subs:c}).then((function(e){for(var n=0;n<o.provinces.length;n++)if(o.provinces[n]._id===t){o.provinces[n].subs=c;break}i(e)}),(function(t){a(t)})),"break"}},l=0;l<s.subs.length;l++){if("break"===r(l))break}}))},t.prototype.deleteSubProvince=function(t,e){var n=this;return new Promise((function(o,i){var a=n.getlocalProvince(t);if(null!=a.subs)for(var s=0;s<a.subs.length;s++)if(a.subs[s]._id===e){a.subs.splice(s,1),n.vhmongo_firebase.database().updateDoc("provinces",t,{subs:a.subs}).then((function(t){for(var i=0;i<n.provinces.length;i++)for(var a=0;a<n.provinces[i].subs.length;a++)if(n.provinces[i].subs[a]._id===e){n.provinces[i].subs.splice(a,1);break}o(t)}),(function(t){i(t)}));break}}))},t.prototype.addDistrict=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("districts",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateDistrict=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("districts",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteDistrict=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("districts",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getDistrict=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("districts",t).then((function(t){n(t)}))}))},t.prototype.getDistricts=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("districts").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.getDistricts_byIDprovince=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("districts",{id_province:{$eq:t}},{},{},0).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.addSubsDistrict=function(t,e){var n=this;return new Promise((function(o,i){for(var a=new Array,s=0;s<e.length;s++)a[s]=Object.assign(Object.assign({},e[s]),{_id:n.vhAlgorithm.ObjectId()});n.getDistrict(t).then((function(e){if(e){void 0===e.subs&&(e.subs=new Array);var i=E(e.subs,a);n.vhmongo_firebase.database().updateDoc("districts",t,{subs:i}).then((function(){o(a)}),(function(){o(null)}))}}))}))},t.prototype.updateSubDistrict=function(t,e,n){var o=this;return new Promise((function(i,a){o.getDistrict(t).then((function(s){if(s&&null!=s.subs)for(var r=0;r<s.subs.length;r++)if(s.subs[r]._id===e){for(var l in s.subs[r]=Object.assign(Object.assign({},s.subs[r]),n),n)s.subs[r][l]=n[l];var c=E(s.subs);o.vhmongo_firebase.database().updateDoc("districts",t,{subs:c}).then((function(t){i(t)}),(function(t){a(t)}));break}}))}))},t.prototype.deleteSubDistrict=function(t,e){var n=this;return new Promise((function(o,i){n.getDistrict(t).then((function(t){if(t&&null!=t.subs)for(var a=0;a<t.subs.length;a++)if(t.subs[a]._id===e){t.subs.splice(a,1),n.vhmongo_firebase.database().updateDoc("districts",t._id,{subs:t.subs}).then((function(t){o(t)}),(function(t){i(t)}));break}}),(function(t){i(t)}))}))},t.prototype.addWard=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("wards",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateWard=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("wards",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteWard=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("wards",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getWard=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("wards",t).then((function(t){n(t)}))}))},t.prototype.getWards=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("wards").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.getWards_byIDdistrict=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("wards",{id_district:{$eq:t}},{},{},0).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.addSubsWard=function(t,e){var n=this;return new Promise((function(o,i){for(var a=new Array,s=0;s<e.length;s++)a[s]=Object.assign(Object.assign({},e[s]),{_id:n.vhAlgorithm.ObjectId()});n.getWard(t).then((function(e){if(e){void 0===e.subs&&(e.subs=new Array);var i=E(e.subs,a);n.vhmongo_firebase.database().updateDoc("wards",t,{subs:i}).then((function(){o(a)}),(function(){o(null)}))}}))}))},t.prototype.updateSubWard=function(t,e,n){var o=this;return new Promise((function(i,a){o.getWard(t).then((function(s){if(s&&null!=s.subs)for(var r=0;r<s.subs.length;r++)if(s.subs[r]._id===e){for(var l in n)s.subs[r][l]=n[l];var c=E(s.subs);o.vhmongo_firebase.database().updateDoc("wards",t,{subs:c}).then((function(t){i(t)}),(function(t){a(t)}));break}}))}))},t.prototype.deleteSubWard=function(t,e){var n=this;return new Promise((function(o,i){n.getWard(t).then((function(a){if(a&&null!=a.subs)for(var s=0;s<a.subs.length;s++)if(a.subs[s]._id===e){a.subs.splice(s,1),n.vhmongo_firebase.database().updateDoc("wards",t,{subs:a.subs}).then((function(t){o(t)}),(function(t){i(t)}));break}}),(function(t){i(t)}))}))},t.prototype.publishObservableEventRooms=function(){this.subjectrooms.next(this.rooms)},t.prototype.observableLocalRooms=function(){return this.subjectrooms},t.prototype.getObservableLocalRooms=function(){var t=this;return new c.Observable((function(e){t.observableLocalRooms().subscribe((function(t){e.next(t)})),t.publishObservableEventRooms()}))},t.prototype.getlocalRoom=function(t){for(var e=0;e<this.rooms.length;e++)if(this.rooms[e]._id===t)return this.rooms[e];return null},t.prototype.getlocalRooms=function(){return this.rooms},t.prototype.refreshLocalRooms=function(){var t=this;return new Promise((function(e){t.getRooms().then((function(){e(null)}))}))},t.prototype.addRoom=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("rooms",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateRoom=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("rooms",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteRoom=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("rooms",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getRoom=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("rooms",t).then((function(t){n(t)}))}))},t.prototype.getRooms=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("rooms").then((function(n){t.rooms=new Array,t.rooms=n,e(n)}),(function(t){n(t)}))}))},t.prototype.addPage=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("pages",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updatePage=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("pages",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deletePage=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("pages",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPage=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("pages",t).then((function(t){n(t)}))}))},t.prototype.getPages=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("pages").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.getPages_byIDdistrict=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("pages",{id_district:{$eq:t}},{},{},0).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPages_byIDemployee=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("pages",{id_employee:{$eq:t}},{},{},0).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.publishObservableEventAreas=function(){this.subjectareas.next(this.areas)},t.prototype.observableLocalAreas=function(){return this.subjectareas},t.prototype.getObservableLocalAreas=function(){var t=this;return new c.Observable((function(e){t.observableLocalAreas().subscribe((function(t){e.next(t)})),t.publishObservableEventAreas()}))},t.prototype.getlocalArea=function(t){for(var e=0;e<this.areas.length;e++)if(this.areas[e]._id===t)return this.areas[e];return null},t.prototype.getlocalAreas=function(){return this.areas},t.prototype.refreshLocalAreas=function(){var t=this;return new Promise((function(e){t.getAreas().then((function(){e(null)}))}))},t.prototype.addArea=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("areas",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateArea=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("areas",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteArea=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("areas",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getArea=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("areas",t).then((function(t){n(t)}))}))},t.prototype.getAreas=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("areas").then((function(n){t.areas=new Array,t.areas=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventPositions=function(){this.subjectpositions.next(this.positions)},t.prototype.observableLocalPositions=function(){return this.subjectpositions},t.prototype.getObservableLocalPositions=function(){var t=this;return new c.Observable((function(e){t.observableLocalPositions().subscribe((function(t){e.next(t)})),t.publishObservableEventPositions()}))},t.prototype.getlocalPosition=function(t){for(var e=0;e<this.positions.length;e++)if(this.positions[e]._id===t)return this.positions[e];return null},t.prototype.getlocalPositions=function(){return this.positions},t.prototype.refreshLocalPositions=function(){var t=this;return new Promise((function(e){t.getPositions().then((function(){e(null)}))}))},t.prototype.addPosition=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("positions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updatePosition=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("positions",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deletePosition=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("positions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPosition=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("positions",t).then((function(t){n(t)}))}))},t.prototype.getPositions=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("positions").then((function(n){t.positions=new Array,t.positions=n,e(n)}),(function(t){n(t)}))}))},t.prototype.getlocalLog=function(t){for(var e=0;e<this.logs.length;e++)if(this.logs[e]._id===t)return this.logs[e];return null},t.prototype.getlocalLogs=function(){return this.logs},t.prototype.refreshLocalLogs=function(){var t=this;return new Promise((function(e){t.getLogs().then((function(){e(null)}))}))},t.prototype.addLog=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("logs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateLog=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("logs",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteLog=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("logs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getLog=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("logs",t).then((function(t){n(t)}))}))},t.prototype.getLogs=function(){var t=this;return new Promise((function(e,n){t.logs=new Array,t.vhmongo_firebase.database().getDocs("logs").then((function(n){t.logs=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventMainboards=function(){this.subjectmainboards.next(this.mainboards)},t.prototype.observableLocalMainboards=function(){return this.subjectmainboards},t.prototype.getObservableLocalMainboards=function(){var t=this;return new c.Observable((function(e){t.observableLocalMainboards().subscribe((function(t){e.next(t)})),t.publishObservableEventMainboards()}))},t.prototype.getlocalMainboard=function(t){for(var e=0;e<this.mainboards.length;e++)if(this.mainboards[e]._id===t)return this.mainboards[e];return null},t.prototype.getlocalMainboards=function(){return this.mainboards},t.prototype.refreshLocalMainboards=function(){var t=this;return new Promise((function(e){t.getMainboards().then((function(){e(null)}))}))},t.prototype.addMainboard=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("mainboards",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateMainboard=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("mainboards",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteMainboard=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("mainboards",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getMainboard=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("mainboards",t).then((function(t){n(t)}))}))},t.prototype.getMainboards=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("mainboards").then((function(n){t.mainboards=new Array,t.mainboards=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventFunctions=function(){this.subjectfunctions.next(this.functions)},t.prototype.observableLocalFunctions=function(){return this.subjectfunctions},t.prototype.getObservableLocalFunctions=function(){var t=this;return new c.Observable((function(e){t.observableLocalFunctions().subscribe((function(t){e.next(t)})),t.publishObservableEventFunctions()}))},t.prototype.getlocalFunction=function(t){for(var e=0;e<this.functions.length;e++)if(this.functions[e]._id===t)return this.functions[e];return null},t.prototype.getlocalFunctions=function(){return this.functions},t.prototype.refreshLocalFunctions=function(){var t=this;return new Promise((function(e){t.getFunctions().then((function(){e(null)}))}))},t.prototype.addFunction=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("functions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateFunction=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("functions",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteFunction=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("functions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getFunction=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("functions",t).then((function(t){n(t)}))}))},t.prototype.getFunctions=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("functions").then((function(n){t.functions=new Array,t.functions=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventComponents=function(){this.subjectcomponents.next(this.components)},t.prototype.observableLocalComponents=function(){return this.subjectcomponents},t.prototype.getObservableLocalComponents=function(){var t=this;return new c.Observable((function(e){t.observableLocalComponents().subscribe((function(t){e.next(t)})),t.publishObservableEventComponents()}))},t.prototype.getlocalComponent=function(t){for(var e=0;e<this.components.length;e++)if(this.components[e]._id===t)return this.components[e];return null},t.prototype.getlocalComponents=function(){return this.components},t.prototype.refreshLocalComponents=function(){var t=this;return new Promise((function(e){t.getComponents().then((function(){e(null)}))}))},t.prototype.addComponent=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("components",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateComponent=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("components",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteComponent=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("components",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getComponent=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("components",t).then((function(t){n(t)}))}))},t.prototype.getComponents=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("components").then((function(n){t.components=new Array,t.components=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventIcons=function(){this.subjecticons.next(this.icons)},t.prototype.observableLocalIcons=function(){return this.subjecticons},t.prototype.getObservableLocalIcons=function(){var t=this;return new c.Observable((function(e){t.observableLocalIcons().subscribe((function(t){e.next(t)})),t.publishObservableEventIcons()}))},t.prototype.getlocalIcon=function(t){for(var e=0;e<this.icons.length;e++)if(this.icons[e]._id===t)return this.icons[e];return null},t.prototype.getlocalIcons=function(){return this.icons},t.prototype.refreshLocalIcons=function(){var t=this;return new Promise((function(e){t.getIcons().then((function(){e(null)}))}))},t.prototype.addIcon=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("icons",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateIcon=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("icons",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteIcon=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("icons",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getIcon=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("icons",t).then((function(t){n(t)}))}))},t.prototype.getIcons=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("icons").then((function(n){t.icons=new Array,t.icons=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventAppSettingNameStations=function(){this.subjectappsettingstations.next()},t.prototype.observableLocalAppSettingNameStations=function(){return this.subjectappsettingstations},t.prototype.getObservableLocalAppSettingNameStations=function(){var t=this;return new c.Observable((function(e){t.observableLocalAppSettingNameStations().subscribe((function(){for(var n=new Array,o=0;o<t.appsettingstations.length;o++)n.push(t.appsettingstations[o].appsetting_name);e.next(n)})),t.publishObservableEventAppSettingNameStations()}))},t.prototype.getLocalAppSettingNameStations=function(){for(var t=new Array,e=0;e<this.appsettingstations.length;e++)t.push(this.appsettingstations[e].appsetting_name);return t},t.prototype.getLocalAppSettingNameStation=function(t){for(var e={},n=0;n<this.appsettingstations.length;n++)if(this.appsettingstations[n].appsetting_name===t){delete(e=Object.assign({},this.appsettingstations[n]))._id,delete e.appsetting_name;break}return e},t.prototype.getLocalAppSettingStation=function(t){for(var e=0;e<this.appsettingstations.length;e++)if(this.appsettingstations[e]._id===t)return this.appsettingstations[e];return null},t.prototype.refreshLocalAppSettingNameStations=function(){return new Promise((function(t,e){t(null)}))},t.prototype.getAppSettingStations=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocsByFields("appsettingstations",{uuid:{$eq:t.hwinfo.uuid}},{},{},0).then((function(n){n.length>0&&(t.appsettingstations=n),e(null)}),(function(t){n(t)}))}))},t.prototype.updateAppSettingNameStation=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().getDocsByFields("appsettingstations",{appsetting_name:{$eq:t},uuid:{$eq:n.hwinfo.uuid}},{},{},0).then((function(a){if(a.length>0)n.vhmongo_firebase.database().updateDoc("appsettingstations",a[0]._id,e).then((function(t){o(t)}),(function(t){i(t)}));else{var s=Object.assign({},e);s.appsetting_name=t,s.uuid=n.hwinfo.uuid,n.vhmongo_firebase.database().addDoc("appsettingstations",s).then((function(){o(!0)}),(function(t){i(t)}))}}))}))},t.prototype.deleteAppSettingNameStation=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("appsettingstations",{appsetting_name:{$eq:t},uuid:{$eq:e.hwinfo.uuid}},{},{},0).then((function(t){t.length>0?e.vhmongo_firebase.database().deleteDoc("appsettingstations",t[0]._id).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}))}))},t.prototype.getlocalScript=function(t){for(var e=0;e<this.scripts.length;e++)if(this.scripts[e]._id===t)return this.scripts[e];return null},t.prototype.getlocalScripts=function(){return this.scripts},t.prototype.refreshLocalScripts=function(){var t=this;return new Promise((function(e){t.getScripts().then((function(){e(null)}))}))},t.prototype.addScript=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("scripts",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateScript=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("scripts",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteScript=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("scripts",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getScript=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("scripts",t).then((function(t){n(t)}))}))},t.prototype.getScripts=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("scripts").then((function(n){t.scripts=new Array,t.scripts=n,e(n)}),(function(t){n(t)}))}))},t.prototype.getlocalScript_detail=function(t){for(var e=0;e<this.script_details.length;e++)if(this.script_details[e]._id===t)return this.script_details[e];return null},t.prototype.getlocalScript_details=function(){return this.script_details},t.prototype.refreshLocalScript_details=function(){var t=this;return new Promise((function(e){t.getScript_details().then((function(){e(null)}))}))},t.prototype.addScript_detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("script_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateScript_detail=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("script_details",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteScript_detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("script_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getScript_detail=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("script_details",t).then((function(t){n(t)}))}))},t.prototype.getScript_details=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("script_details").then((function(n){t.script_details=new Array,t.script_details=n,e(n)}),(function(t){n(t)}))}))},t}();K.decorators=[{type:e.Injectable}],K.ctorParameters=function(){return[{type:o.Vhmongo_firebase},{type:V},{type:F},{type:L}]};var X=function(){function t(t,e,n,o){var i=this;this.vhmongo_firebase=t,this.vhQuery=e,this.vhAuth=n,this.vhAlgorithm=o,this.cameras=new Array,this.rooms=new Array,this.mainboards=new Array,this.functions=new Array,this.components=new Array,this.icons=new Array,this.appsettingstations=new Array,this.scripts=new Array,this.script_details=new Array,this.logs=new Array,this.hwinfo={},this.subjectcameras=new c.Subject,this.subjectappsettingstations=new c.Subject,this.subjectrooms=new c.Subject,this.subjectmainboards=new c.Subject,this.subjectfunctions=new c.Subject,this.subjecticons=new c.Subject,this.subjectcomponents=new c.Subject,r.Device.getId().then((function(t){var e=i.vhAuth.localStorageGET("hwinfo");null!=e&&null!=e?i.hwinfo=e:(i.hwinfo=Object.assign({},t),i.vhAuth.localStorageSET("hwinfo",i.hwinfo))}))}return t.prototype.syncCollections=function(){var t=this;return new Promise((function(e,n){t.initSyncCollections(),t.callbackCollectionInsert().subscribe(),t.callbackCollectionUpdate().subscribe(),t.callbackCollectionDelete().subscribe(),setTimeout((function(){e(!0)}),3e3)}))},t.prototype.initSyncCollections=function(){var t=new Array;return t[0]="cameras",t[1]="rooms",t[2]="mainboards",t[3]="components",t[4]="icons",t[5]="functions",t[6]="vhemployees",t[7]="appsettingstations",this.vhmongo_firebase.socketMongoDB().initSyncCollections(t)},t.prototype.closeSyncCollections=function(){this.vhmongo_firebase.socketMongoDB().closeSyncCollections()},t.prototype.callbackCollectionInsert=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackCollectionInsert().subscribe((function(n){if("vhemployees"===n.colname?n.colname="employees":"appsettingstations"===n.colname&&(n.colname="appsettingstations"),"cameras"===n.colname)t.getlocalCamera(n._id)||((o=Object.assign({},n.data))._id=n._id,t.cameras.push(o),t.publishObservableEventCameras(),e.next(n.colname));else if("rooms"===n.colname){if(!t.getlocalRoom(n._id))(o=Object.assign({},n.data))._id=n._id,t.rooms.push(o),t.publishObservableEventRooms(),e.next(n.colname)}else if("mainboards"===n.colname){if(!t.getlocalMainboard(n._id))(o=Object.assign({},n.data))._id=n._id,t.mainboards.push(o),t.publishObservableEventMainboards(),e.next(n.colname)}else if("components"===n.colname){if(!t.getlocalComponent(n._id))(o=Object.assign({},n.data))._id=n._id,t.components.push(o),t.publishObservableEventComponents(),e.next(n.colname)}else if("icons"===n.colname){if(!t.getlocalIcon(n._id))(o=Object.assign({},n.data))._id=n._id,t.icons.push(o),t.publishObservableEventIcons(),e.next(n.colname)}else if("functions"===n.colname){if(!t.getlocalFunction(n._id))(o=Object.assign({},n.data))._id=n._id,t.functions.push(o),t.publishObservableEventFunctions(),e.next(n.colname)}else if("employees"===n.colname){(o=Object.assign({},n.data))._id=n._id,t.vhAuth.insertlocalEmployeeFromSyncCollection(o),t.vhAuth.publishObservableEventEmployees(),e.next(n.colname)}else if("appsettingstations"===n.colname){var o;if(!t.getLocalAppSettingStation(n._id))if(n.data.uuid===t.hwinfo.uuid)(o=Object.assign({},n.data))._id=n._id,delete o.uuid,t.appsettingstations.push(o),t.publishObservableEventAppSettingNameStations(),e.next(n.colname)}console.log("inserted",n.colname)}))}))},t.prototype.callbackCollectionUpdate=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackCollectionUpdate().subscribe((function(n){if("vhemployees"===n.colname?n.colname="employees":"appsettingstations"===n.colname&&(n.colname="appsettingstations"),"cameras"===n.colname){for(var o=0;o<t.cameras.length;o++)if(t.cameras[o]._id===n._id){t.cameras[o]=Object.assign(Object.assign({},t.cameras[o]),n.data),t.publishObservableEventCameras(),e.next(n.colname);break}}else if("rooms"===n.colname){for(o=0;o<t.rooms.length;o++)if(t.rooms[o]._id===n._id){t.rooms[o]=Object.assign(Object.assign({},t.rooms[o]),n.data),t.publishObservableEventRooms(),e.next(n.colname);break}}else if("mainboards"===n.colname){for(o=0;o<t.mainboards.length;o++)if(t.mainboards[o]._id===n._id){t.mainboards[o]=Object.assign(Object.assign({},t.mainboards[o]),n.data),t.publishObservableEventMainboards(),e.next(n.colname);break}}else if("components"===n.colname){for(o=0;o<t.components.length;o++)if(t.rooms[o]._id===n._id){t.rooms[o]=Object.assign(Object.assign({},t.components[o]),n.data),t.publishObservableEventComponents(),e.next(n.colname);break}}else if("icons"===n.colname){for(o=0;o<t.icons.length;o++)if(t.icons[o]._id===n._id){t.icons[o]=Object.assign(Object.assign({},t.icons[o]),n.data),t.publishObservableEventIcons(),e.next(n.colname);break}}else if("functions"===n.colname){for(o=0;o<t.icons.functions;o++)if(t.functions[o]._id===n._id){t.functions[o]=Object.assign(Object.assign({},t.functions[o]),n.data),t.publishObservableEventFunctions(),e.next(n.colname);break}}else if("employees"===n.colname)t.vhAuth.updateLocalEmployeeFromSyncCollection(n._id,n.data),t.vhAuth.publishObservableEventEmployees(),e.next(n.colname);else if("appsettingstations"===n.colname)for(o=0;o<t.appsettingstations.length;o++)if(t.appsettingstations[o]._id===n._id){t.appsettingstations[o]=Object.assign(Object.assign({},t.appsettingstations[o]),n.data),t.publishObservableEventAppSettingNameStations(),e.next(n.colname);break}console.log("updated",n.colname)}))}))},t.prototype.callbackCollectionDelete=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackCollectionDelete().subscribe((function(n){if("vhemployees"===n.colname?n.colname="employees":"appsettingstations"===n.colname&&(n.colname="appsettingstations"),"cameras"===n.colname){for(var o=0;o<t.cameras.length;o++)if(t.cameras[o]._id===n._id){t.cameras.splice(o,1),t.publishObservableEventCameras(),e.next(n.colname);break}}else if("rooms"===n.colname){for(o=0;o<t.rooms.length;o++)if(t.rooms[o]._id===n._id){t.rooms.splice(o,1),t.publishObservableEventRooms(),e.next(n.colname);break}}else if("mainboards"===n.colname){for(o=0;o<t.mainboards.length;o++)if(t.mainboards[o]._id===n._id){t.mainboards.splice(o,1),t.publishObservableEventMainboards(),e.next(n.colname);break}}else if("components"===n.colname){for(o=0;o<t.components.length;o++)if(t.components[o]._id===n._id){t.components.splice(o,1),t.publishObservableEventComponents(),e.next(n.colname);break}}else if("icons"===n.colname){for(o=0;o<t.icons.length;o++)if(t.icons[o]._id===n._id){t.icons.splice(o,1),t.publishObservableEventIcons(),e.next(n.colname);break}}else if("functions"===n.colname){for(o=0;o<t.functions.length;o++)if(t.functions[o]._id===n._id){t.functions.splice(o,1),t.publishObservableEventFunctions(),e.next(n.colname);break}}else if("employees"===n.colname)t.vhAuth.deleteLocalEmployeeFromSyncCollection(n._id),t.vhAuth.publishObservableEventEmployees(),e.next(n.colname);else if("appsettingstations"===n.colname)for(o=0;o<t.appsettingstations.length;o++)if(t.appsettingstations[o]._id===n._id){t.appsettingstations.splice(o,1),t.publishObservableEventAppSettingNameStations(),e.next(n.colname);break}console.log("deleted",n.colname)}))}))},t.prototype.startLocalStorage=function(){var t=this;return new Promise((function(e){var n=new Array;n[0]=t.vhAuth.refreshLocalEmployees(),n[1]=t.vhAuth.refreshLocalMyPermission(),n[2]=t.refreshLocalRooms(),n[3]=t.refreshLocalCameras(),n[4]=t.refreshLocalComponents(),n[5]=t.refreshLocalFunctions(),n[6]=t.refreshLocalIcons(),n[7]=t.refreshLocalMainboards(),t.vhQuery.asyncPromiseAll(n).then((function(){e(null)}))}))},t.prototype.publishObservableEventCameras=function(){this.subjectcameras.next(this.cameras)},t.prototype.observableLocalCameras=function(){return this.subjectcameras},t.prototype.getObservableLocalCameras=function(){var t=this;return new c.Observable((function(e){t.observableLocalCameras().subscribe((function(t){e.next(t)})),t.publishObservableEventCameras()}))},t.prototype.getlocalCamera=function(t){for(var e=0;e<this.cameras.length;e++)if(this.cameras[e]._id===t)return this.cameras[e];return null},t.prototype.getlocalCameras=function(){return this.cameras},t.prototype.refreshLocalCameras=function(){var t=this;return new Promise((function(e){t.getCameras().then((function(){e(null)}))}))},t.prototype.addCamera=function(t){return new Promise((function(t,e){}))},t.prototype.updateCamera=function(t,e){return new Promise((function(t,e){}))},t.prototype.deleteCamera=function(t){return new Promise((function(t,e){}))},t.prototype.getCamera=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("cameras",t).then((function(t){n(t)}))}))},t.prototype.getCameras=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("cameras").then((function(n){t.cameras=new Array,t.cameras=n,e(n)}),(function(t){n(t)}))}))},t.prototype.getPlaybackListCambyEndUser=function(t,e,n,o){var i=this;return new Promise((function(a,s){i.vhmongo_firebase.f3rdclouds().getPlaybackListCambyEndUser(t,e,n,o).then((function(t){0===t.vcode?a(t.data):(console.log(t),a([]))}),(function(t){s(t)}))}))},t.prototype.publishObservableEventRooms=function(){this.subjectrooms.next(this.rooms)},t.prototype.observableLocalRooms=function(){return this.subjectrooms},t.prototype.getObservableLocalRooms=function(){var t=this;return new c.Observable((function(e){t.observableLocalRooms().subscribe((function(t){e.next(t)})),t.publishObservableEventRooms()}))},t.prototype.getlocalRoom=function(t){for(var e=0;e<this.rooms.length;e++)if(this.rooms[e]._id===t)return this.rooms[e];return null},t.prototype.getlocalRooms=function(){return this.rooms},t.prototype.refreshLocalRooms=function(){var t=this;return new Promise((function(e){t.getRooms().then((function(){e(null)}))}))},t.prototype.addRoom=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("rooms",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateRoom=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("rooms",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteRoom=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("rooms",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getRoom=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("rooms",t).then((function(t){n(t)}))}))},t.prototype.getRooms=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("rooms").then((function(n){t.rooms=new Array,t.rooms=n,e(n)}),(function(t){n(t)}))}))},t.prototype.getlocalLog=function(t){for(var e=0;e<this.logs.length;e++)if(this.logs[e]._id===t)return this.logs[e];return null},t.prototype.getlocalLogs=function(){return this.logs},t.prototype.refreshLocalLogs=function(){var t=this;return new Promise((function(e){t.getLogs().then((function(){e(null)}))}))},t.prototype.addLog=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("logs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateLog=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("logs",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteLog=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("logs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getLog=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("logs",t).then((function(t){n(t)}))}))},t.prototype.getLogs=function(){var t=this;return new Promise((function(e,n){t.logs=new Array,t.vhmongo_firebase.database().getDocs("logs").then((function(n){t.logs=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventMainboards=function(){this.subjectmainboards.next(this.mainboards)},t.prototype.observableLocalMainboards=function(){return this.subjectmainboards},t.prototype.getObservableLocalMainboards=function(){var t=this;return new c.Observable((function(e){t.observableLocalMainboards().subscribe((function(t){e.next(t)})),t.publishObservableEventMainboards()}))},t.prototype.getlocalMainboard=function(t){for(var e=0;e<this.mainboards.length;e++)if(this.mainboards[e]._id===t)return this.mainboards[e];return null},t.prototype.getlocalMainboards=function(){return this.mainboards},t.prototype.refreshLocalMainboards=function(){var t=this;return new Promise((function(e){t.getMainboards().then((function(){e(null)}))}))},t.prototype.addMainboard=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("mainboards",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateMainboard=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("mainboards",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteMainboard=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("mainboards",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getMainboard=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("mainboards",t).then((function(t){n(t)}))}))},t.prototype.getMainboards=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("mainboards").then((function(n){t.mainboards=new Array,t.mainboards=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventFunctions=function(){this.subjectfunctions.next(this.functions)},t.prototype.observableLocalFunctions=function(){return this.subjectfunctions},t.prototype.getObservableLocalFunctions=function(){var t=this;return new c.Observable((function(e){t.observableLocalFunctions().subscribe((function(t){e.next(t)})),t.publishObservableEventFunctions()}))},t.prototype.getlocalFunction=function(t){for(var e=0;e<this.functions.length;e++)if(this.functions[e]._id===t)return this.functions[e];return null},t.prototype.getlocalFunctions=function(){return this.functions},t.prototype.refreshLocalFunctions=function(){var t=this;return new Promise((function(e){t.getFunctions().then((function(){e(null)}))}))},t.prototype.addFunction=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("functions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateFunction=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("functions",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteFunction=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("functions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getFunction=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("functions",t).then((function(t){n(t)}))}))},t.prototype.getFunctions=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("functions").then((function(n){t.functions=new Array,t.functions=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventComponents=function(){this.subjectcomponents.next(this.components)},t.prototype.observableLocalComponents=function(){return this.subjectcomponents},t.prototype.getObservableLocalComponents=function(){var t=this;return new c.Observable((function(e){t.observableLocalComponents().subscribe((function(t){e.next(t)})),t.publishObservableEventComponents()}))},t.prototype.getlocalComponent=function(t){for(var e=0;e<this.components.length;e++)if(this.components[e]._id===t)return this.components[e];return null},t.prototype.getlocalComponents=function(){return this.components},t.prototype.refreshLocalComponents=function(){var t=this;return new Promise((function(e){t.getComponents().then((function(){e(null)}))}))},t.prototype.addComponent=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("components",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateComponent=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("components",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteComponent=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("components",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getComponent=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("components",t).then((function(t){n(t)}))}))},t.prototype.getComponents=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("components").then((function(n){t.components=new Array,t.components=n,e(n)}),(function(t){n(t)}))}))},t.prototype.addIRManufacturer_byID=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.rootdatabase().addDocbyID("IRmanufacturers",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.updateIRManufacturer=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.rootdatabase().updateDoc("IRmanufacturers",t,e).then((function(){o(void 0)}),(function(t){i(t)}))}))},t.prototype.deleteIRManufacturer=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.rootdatabase().deleteDoc("IRmanufacturers",t).then((function(){n(void 0)}),(function(t){o(t)}))}))},t.prototype.getIRManufacturer=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.rootdatabase().getDoc("IRmanufacturers",t).then((function(t){n(t)}),(function(t){n(t)}))}))},t.prototype.getIRManufacturers=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.rootdatabase().getDocsByFields("IRmanufacturers",{type:{$eq:t}},{}).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.publishObservableEventIcons=function(){this.subjecticons.next(this.icons)},t.prototype.observableLocalIcons=function(){return this.subjecticons},t.prototype.getObservableLocalIcons=function(){var t=this;return new c.Observable((function(e){t.observableLocalIcons().subscribe((function(t){e.next(t)})),t.publishObservableEventIcons()}))},t.prototype.getlocalIcon=function(t){for(var e=0;e<this.icons.length;e++)if(this.icons[e]._id===t)return this.icons[e];return null},t.prototype.getlocalIcons=function(){return this.icons},t.prototype.refreshLocalIcons=function(){var t=this;return new Promise((function(e){t.getIcons().then((function(){e(null)}))}))},t.prototype.addIcon=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("icons",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateIcon=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("icons",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteIcon=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("icons",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getIcon=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("icons",t).then((function(t){n(t)}))}))},t.prototype.getIcons=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("icons").then((function(n){t.icons=new Array,t.icons=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventAppSettingNameStations=function(){this.subjectappsettingstations.next()},t.prototype.observableLocalAppSettingNameStations=function(){return this.subjectappsettingstations},t.prototype.getObservableLocalAppSettingNameStations=function(){var t=this;return new c.Observable((function(e){t.observableLocalAppSettingNameStations().subscribe((function(){for(var n=new Array,o=0;o<t.appsettingstations.length;o++)n.push(t.appsettingstations[o].appsetting_name);e.next(n)})),t.publishObservableEventAppSettingNameStations()}))},t.prototype.getLocalAppSettingNameStations=function(){for(var t=new Array,e=0;e<this.appsettingstations.length;e++)t.push(this.appsettingstations[e].appsetting_name);return t},t.prototype.getLocalAppSettingNameStation=function(t){for(var e={},n=0;n<this.appsettingstations.length;n++)if(this.appsettingstations[n].appsetting_name===t){delete(e=Object.assign({},this.appsettingstations[n]))._id,delete e.appsetting_name;break}return e},t.prototype.getLocalAppSettingStation=function(t){for(var e=0;e<this.appsettingstations.length;e++)if(this.appsettingstations[e]._id===t)return this.appsettingstations[e];return null},t.prototype.refreshLocalAppSettingNameStations=function(){return new Promise((function(t,e){t(null)}))},t.prototype.getAppSettingStations=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocsByFields("appsettingstations",{uuid:{$eq:t.hwinfo.uuid}},{},{},0).then((function(n){n.length>0&&(t.appsettingstations=n),e(null)}),(function(t){n(t)}))}))},t.prototype.updateAppSettingNameStation=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().getDocsByFields("appsettingstations",{appsetting_name:{$eq:t},uuid:{$eq:n.hwinfo.uuid}},{},{},0).then((function(a){if(a.length>0)n.vhmongo_firebase.database().updateDoc("appsettingstations",a[0]._id,e).then((function(t){o(t)}),(function(t){i(t)}));else{var s=Object.assign({},e);s.appsetting_name=t,s.uuid=n.hwinfo.uuid,n.vhmongo_firebase.database().addDoc("appsettingstations",s).then((function(){o(!0)}),(function(t){i(t)}))}}))}))},t.prototype.deleteAppSettingNameStation=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("appsettingstations",{appsetting_name:{$eq:t},uuid:{$eq:e.hwinfo.uuid}},{},{},0).then((function(t){t.length>0?e.vhmongo_firebase.database().deleteDoc("appsettingstations",t[0]._id).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}))}))},t.prototype.getlocalScript=function(t){for(var e=0;e<this.scripts.length;e++)if(this.scripts[e]._id===t)return this.scripts[e];return null},t.prototype.getlocalScripts=function(){return this.scripts},t.prototype.refreshLocalScripts=function(){var t=this;return new Promise((function(e){t.getScripts().then((function(){e(null)}))}))},t.prototype.addScript=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("scripts",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateScript=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("scripts",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteScript=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("scripts",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getScript=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("scripts",t).then((function(t){n(t)}))}))},t.prototype.getScripts=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("scripts").then((function(n){t.scripts=new Array,t.scripts=n,e(n)}),(function(t){n(t)}))}))},t.prototype.getlocalScript_detail=function(t){for(var e=0;e<this.script_details.length;e++)if(this.script_details[e]._id===t)return this.script_details[e];return null},t.prototype.getlocalScript_details=function(){return this.script_details},t.prototype.refreshLocalScript_details=function(){var t=this;return new Promise((function(e){t.getScript_details().then((function(){e(null)}))}))},t.prototype.addScript_detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("script_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateScript_detail=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("script_details",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteScript_detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("script_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getScript_detail=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("script_details",t).then((function(t){n(t)}))}))},t.prototype.getScript_details=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("script_details").then((function(n){t.script_details=new Array,t.script_details=n,e(n)}),(function(t){n(t)}))}))},t}();X.decorators=[{type:e.Injectable}],X.ctorParameters=function(){return[{type:o.Vhmongo_firebase},{type:V},{type:F},{type:L}]};var tt=function(){function t(t){this.http=t}return t.prototype.getTranslation=function(t){var e=this,n="assets/i18n/"+t+".json";return new c.Observable((function(t){e.http.get(n).subscribe((function(e){t.next(e),t.complete()}),(function(t){}))}))},t}();tt.decorators=[{type:e.Injectable}],tt.ctorParameters=function(){return[{type:D.HttpClient}]};var et=function(){function t(t){this.translate=t}return t.prototype.list=function(){return[{id:"vn",name:"Vietnamese",icon:"assets/icon/vn.svg"},{id:"en",name:"English",icon:"assets/icon/en.svg"}]},t.prototype.get=function(){return JSON.parse(localStorage.getItem("vh_language")).id},t.prototype.set=function(t){this.translate.use(t),localStorage.setItem("vh_language",JSON.stringify(this.list().filter((function(e){return e.id==t}))[0]))},t.prototype.syncExistedLanguage=function(){var t=localStorage.getItem("vh_language");t?this.translate.use(JSON.parse(t).id):(this.translate.setDefaultLang("en"),localStorage.setItem("vh_language",JSON.stringify({id:"en",name:"English",icon:"assets/icon/en.svg"})))},t}();et.decorators=[{type:e.Injectable}],et.ctorParameters=function(){return[{type:P.TranslateService}]};var nt=function(){function t(t){this.bluetoothSerial=t,this.socketId=0,this.win=window,this.device=new Array,this.ESC="",this.GS="",this.InitializePrinter=this.ESC+"@",this.BoldOn=this.ESC+"E",this.BoldOff=this.ESC+"E\0",this.DoubleHeight=this.GS+"!",this.DoubleWidth=this.GS+"!",this.DoubleOn=this.GS+"!",this.DoubleOff=this.GS+"!\0",this.PrintAndFeedMaxLine=this.ESC+"Jÿ",this.TextAlignLeft=this.ESC+"a0",this.TextAlignCenter=this.ESC+"a1",this.TextAlignRight=this.ESC+"a2",this.commend=this.ESC+"t19",this.cutpaper=this.GS+"V",this.whiteblackmode=this.GS+"B",this.leftmargin=this.GS+"Lāā",this.bitmap=this.ESC+"*\0Đ0100\0",this.font=this.ESC+"M0",this.linefeed=this.ESC+"LF",this.dots=this.ESC+"4A 20"}return t.prototype.BluetoothSerialPrinter=function(){var t=this;return{search:function(){return t.bluetoothSerial.list()},printInvoice:function(e,n){return new Promise((function(o,i){var a={bgcolor:"white",height:n.clientHeight,width:n.clientWidth,size:e.size};$.default.toJpeg(n,a).then((function(n){t.encodeCommand(n,a).then((function(n){var i,a=t.useEscPrintImage(n),s=(i=e.address,t.bluetoothSerial.connect(i)).subscribe((function(e){t.bluetoothSerial.write(a).then((function(t){s.unsubscribe(),o(null)}),(function(t){console.log("WRITE FAILED",t),o(null)}))}),(function(t){console.log("CONNECTION ERROR",t)}))}))}))}))}}},t.prototype.IPSerialPrinter=function(){var t=this;return{printInvoice:function(e,n){return new Promise((function(o){var i=0,a=setInterval((function(){i++,chrome.sockets.tcp.create((function(i){if(!t.socketId){t.socketId=i.socketId;var s=setTimeout((function(){clearTimeout(s),chrome.sockets.tcp.connect(i.socketId,e.ip,e.port,(function(i){if(!i){clearInterval(a);var s={bgcolor:"white",height:n.clientHeight,width:n.clientWidth,size:e.size};$.default.toJpeg(n,s).then((function(e){t.encodeCommand(e,s).then((function(e){var n=t.useEscPrintImage(e);t.rawPrint(t.socketId,n).then((function(){var e=new Uint8Array(8);e.set([29,86,1,0,0,0,0,0],0),t.rawPrint(t.socketId,e).then((function(){new Promise((function(e){chrome.sockets.tcp.disconnect(t.socketId,(function(t){e(t)}))})).then((function(){t.socketId=0,o(!0)}))}))}))}))}))}}))}),1e3)}})),i>16&&(clearInterval(a),o(!1))}),500)}))}}},t.prototype.getImageData=function(t,e){if(0!=t.width||0!=t.height){(e=e||{}).x=e.x||0,e.y=e.y||0,e.width="number"==typeof e.width?e.width:t.width,e.height="number"==typeof e.height?e.height:t.height;var n,o=document.createElement("canvas"),i=o.getContext("2d");o.width=e.width,o.height=e.height,i.drawImage(t,e.x,e.y,e.width,e.height,0,0,e.width,e.height);try{n=i.getImageData(0,0,e.width,e.height)}catch(t){throw t}return n}},t.prototype.rawPrint=function(t,e){return new Promise((function(n,o){chrome.sockets.tcp.send(t,e.buffer,(function(t){n(t)}))}))},t.prototype.useEscPrintImage=function(t){var e=this.getImageData(t,0);this.threshold(e,"");var n=this.rgbToPixel(e.data),o=t.width,i=t.height,a=this.toEscPrintData(n,o,i);return this.printImage(0,o,i,a)},t.prototype.rgbToPixel=function(t){for(var e=[],n=0;n<t.length;n+=4){var o=t[n],i=t[n+1],a=t[n+2],s=(t[n+3]<<24)+(o<<16)+(i<<8)+a;e.push(s)}return e},t.prototype.threshold=function(t,e){null==e&&(e=180),e=180;for(var n=0;n<t.data.length;n+=4){var o=.299*t.data[n]+.587*t.data[n+1]+.114*t.data[n+2]<e?0:255;t.data.fill(o,n,n+3)}},t.prototype.toEscPrintData=function(t,e,n){for(var o=Math.floor((e+7)/8),i=new Array(o*n),a=0;a<n;a++)for(var s=0;s<8*o;s++)s<e?(16711680&t[a*e+s])>>16!=0?i[Math.floor(a*o+s/8)]|=1<<7-s%8:i[Math.floor(a*o+s/8)]&=-2<<7-s%8:s>=e&&(i[Math.floor(a*o+s/8)]|=1<<7-s%8);for(var r=0;r<i.length;r++)i[r]=~i[r];return i},t.prototype.encodeCommand=function(t,e){return new Promise((function(n,o){var i=document.createElement("canvas"),a=i.getContext("2d"),s=new Image,r=568;"K57"==e.size?r=400:"K80"==e.size?r=600:"A4"!=e.size&&"A5"!=e.size||(r=1500),s.onload=function(){i.width=r,i.height=e.height*r/e.width+100,a.drawImage(s,0,0,r,e.height*r/e.width),n(i)},s.src=t}))},t.prototype.PrintAndFeedLine=function(t){return this.ESC="",t>255&&(t=255),t<0&&(t=0),this.ESC+"J"+String.fromCharCode(t)},t.prototype.CutAndFeedLine=function(t){return this.ESC="",void 0===t?this.ESC+"V1":(t>255&&(t=255),t<0&&(t=0),this.ESC+"V"+String.fromCharCode(t))},t.prototype.printAndFeedLine=function(t){return t>255&&(t=255),t<0&&(t=0),this.ESC+"J"+String.fromCharCode(t)},t.prototype.cutAndFeedLine=function(t){return void 0===t?this.ESC+"V1":(t>255&&(t=255),t<0&&(t=0),this.ESC+"V66"+String.fromCharCode(t))},t.prototype.printImage=function(t,e,n,o){var i=Math.floor((e+7)/8%256),a=Math.floor((e+7)/8/256),s=Math.floor(n%256),r=Math.floor(n/256),l=new Uint8Array(o.length+8);return l.set([29,118,48,1&t,i,a,s,r],0),l.set(o,8),l},t}();nt.decorators=[{type:e.Injectable}],nt.ctorParameters=function(){return[{type:q.BluetoothSerial}]};var ot=function(){function t(t,e){this.mqttService=t,this.wifiWizard2=e,this.boolean=!0}return t.prototype.callbackTopic=function(t,e){return void 0===e?this.mqttService.observe(t):this.mqttService.observe(t+e)},t.prototype.publish=function(t,e,n){void 0===n?this.mqttService.unsafePublish(t,e,{qos:1,retain:!1}):this.mqttService.unsafePublish(t+n,e,{qos:1,retain:!1})},t.prototype.startESPsmartconfig=function(t){var e=this;return new Promise((function(n,o){e.wifiWizard2.getConnectedBSSID().then((function(i){esptouch.start(t.ssid,i,t.password,"1","1",(function(t){var o="";t.bssid?(""===(o=e.getIotID(t.bssid))&&console.log("vui lòng 1, báo với anh Huy lỗi này startESPsmartconfig"),n(o)):(""===o&&console.log("vui lòng 2, báo với anh Huy lỗi này startESPsmartconfig"),n(o))}),(function(t){console.log("error",t),o(t)}))}),(function(t){console.log("error1",t),o(t)}))}))},t.prototype.stopESPsmartconfig=function(){return new Promise((function(t,e){esptouch.stop((function(e){console.log("res",e),t(e)}),(function(t){console.log("err",t),e(t)}))}))},t.prototype.getConnectedSSID=function(){var t=this;return new Promise((function(e,n){t.wifiWizard2.getConnectedSSID().then((function(t){e(t)}))}))},t.prototype.getIotID=function(t){var e=t,n="";if(12===e.length){var o=e.slice(0,4),i=parseInt(o,16),a=e.slice(4,8),s=parseInt(a,16),r=e.slice(8,12),l=parseInt(r,16);parseInt(r,16)%2?(i>>>=1,i+=parseInt("8000",16)):i>>>=1,parseInt(o,16)%2?(s>>>=1,s+=parseInt("8000",16)):s>>>=1,parseInt(a,16)%2?(l>>>=1,l+=parseInt("8000",16)):l>>>=1;var c="0000",u="0000",d="0000";1===i.toString(16).length?c="000"+i.toString(16):2===i.toString(16).length?c="00"+i.toString(16):3===i.toString(16).length?c="0"+i.toString(16):4===i.toString(16).length&&(c=i.toString(16)),1===s.toString(16).length?u="000"+s.toString(16):2===s.toString(16).length?u="00"+s.toString(16):3===s.toString(16).length?u="0"+s.toString(16):4===s.toString(16).length&&(u=s.toString(16)),1===l.toString(16).length?d="000"+l.toString(16):2===l.toString(16).length?d="00"+l.toString(16):3===l.toString(16).length?d="0"+l.toString(16):4===l.toString(16).length&&(d=l.toString(16)),"000000000000"===(n=c.slice(0,1)+u+d)&&(n=""),9!=n.length&&(n="")}return n},t}();ot.decorators=[{type:e.Injectable}],ot.ctorParameters=function(){return[{type:g.MqttService},{type:x.WifiWizard2}]};var it=function(){function t(t,e,n,o){this.vhmongo_firebase=t,this.vhQuery=e,this.vhAuth=n,this.vhAlgorithm=o}return t.prototype.getBranch=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("branchs",t).then((function(t){n(t)}))}))},t.prototype.getBranchs=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("branchs").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.getProduct=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("products",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getProductsByFields=function(t,e,n,o){var i=this;return new Promise((function(a,s){i.vhQuery.getDocsByFields("products",t,e,n,o).then((function(t){a(t)}),(function(t){s(t)}))}))},t.prototype.getCategory=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("categorys",t).then((function(t){n(t)}))}))},t.prototype.getCategorys=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("categorys").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.getCategorysByFields=function(t,e,n,o){var i=this;return new Promise((function(a){i.vhQuery.getDocsByFields("categorys",t,e,n,o).then((function(t){a(t)}))}))},t}();it.decorators=[{type:e.Injectable}],it.ctorParameters=function(){return[{type:o.Vhmongo_firebase},{type:V},{type:F},{type:L}]};var at=function(){function t(t,e,n,o){this.vhmongo_firebase=t,this.vhQuery=e,this.vhAuth=n,this.vhAlgorithm=o}return t.prototype.getBranch=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("branchs",t).then((function(t){n(t)}))}))},t.prototype.getBranchs=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("branchs").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.addProduct=function(t){var e=this;return new Promise((function(n,o){1===(null==t?void 0:t.type)?e.getBranchs().then((function(i){t.quantity=0,t.quantity_branch={},i.forEach((function(e){t.quantity_branch[e._id]=0})),e.vhmongo_firebase.database().addDoc("products",t).then((function(t){n(t)}),(function(t){o(t)}))}),(function(t){o(t)})):e.vhmongo_firebase.database().addDoc("products",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateProduct=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("products",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteProduct=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("vhbill_details",{id_product:{$eq:t}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("products",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getProduct=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("products",t).then((function(t){n(t)}))}))},t.prototype.getProductsByFields=function(t,e,n,o){var i=this;return new Promise((function(a){i.vhQuery.getDocsByFields("products",t,e,n,o).then((function(t){a(t)}))}))},t.prototype.addCategory=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("categorys",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateCategory=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("categorys",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteCategory=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("products",{id_category:{$eq:t}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("categorys",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getCategory=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("categorys",t).then((function(t){n(t)}))}))},t.prototype.getCategorys=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("categorys").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.getCategorysByFields=function(t,e,n,o){var i=this;return new Promise((function(a){i.vhQuery.getDocsByFields("categorys",t,e,n,o).then((function(t){a(t)}))}))},t}();at.decorators=[{type:e.Injectable}],at.ctorParameters=function(){return[{type:o.Vhmongo_firebase},{type:V},{type:F},{type:L}]};var st=function(){function t(t,e,n,o){this.vhmongo_firebase=t,this.vhQuery=e,this.vhAuth=n,this.vhAlgorithm=o}return t.prototype.getBranch=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("branchs",t).then((function(t){n(t)}))}))},t.prototype.getBranchs=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("branchs").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.getProduct=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("products",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getProductsByFields=function(t,e,n,o){var i=this;return new Promise((function(a,s){i.vhQuery.getDocsByFields("products",t,e,n,o).then((function(t){a(t)}),(function(t){s(t)}))}))},t.prototype.getCategory=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("categorys",t).then((function(t){n(t)}))}))},t.prototype.getCategorys=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("categorys").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.getCategorysByFields=function(t,e,n,o){var i=this;return new Promise((function(a){i.vhQuery.getDocsByFields("categorys",t,e,n,o).then((function(t){a(t)}))}))},t}();st.decorators=[{type:e.Injectable}],st.ctorParameters=function(){return[{type:o.Vhmongo_firebase},{type:V},{type:F},{type:L}]};var rt=function(){function t(t,e,n,o){this.vhmongo_firebase=t,this.vhQuery=e,this.vhAuth=n,this.vhAlgorithm=o,this.products=new Array}return t.prototype.getlocalProductAndCombosAndToppings=function(t){for(var e=new Array,n=0;n<this.products.length;n++){if(this.products[n]._id===t&&(e.push(Object.assign({},this.products[n])),null!=this.products[n].subs)){var o=E(this.products[n].subs);e[e.length-1].subs=new Array,o.forEach((function(t){e[e.length-1].subs.push(Object.assign({},t))}))}if(null!=this.products[n].combos)for(var i=0;i<this.products[n].combos.length;i++)if(this.products[n].combos[i].id_product===t){e.push(Object.assign({},this.products[n]));break}if(null!=this.products[n].toppings)for(i=0;i<this.products[n].toppings.length;i++)if(this.products[n].toppings[i].id_product===t){e.push(Object.assign({},this.products[n]));break}}return e},t.prototype.getlocalProduct=function(t){for(var e=function(e){if(n.products[e]._id===t){var o=Object.assign({},n.products[e]);if(null!=o.subs){var i=E(o.subs);o.subs=new Array,i.forEach((function(t){o.subs.push(Object.assign({},t))}))}if(null!=o.toppings){var a=E(o.toppings);o.toppings=new Array,a.forEach((function(t){o.toppings.push(Object.assign({},t))}))}if(null!=o.combos){var s=E(o.combos);o.combos=new Array,s.forEach((function(t){o.combos.push(Object.assign({},t))}))}return{value:o}}},n=this,o=0;o<this.products.length;o++){var i=e(o);if("object"==typeof i)return i.value}return null},t.prototype.getBranch=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("branchs",t).then((function(t){n(t)}))}))},t.prototype.getBranchs=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("branchs").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.addProduct=function(t){var e=this;return new Promise((function(n,o){3===(null==t?void 0:t.type)?e.getBranchs().then((function(i){t.quantity=0,t.quantity_branch={},i.forEach((function(e){t.quantity_branch[e._id]=0})),e.vhmongo_firebase.database().addDoc("products",t).then((function(t){n(t)}),(function(t){o(t)}))}),(function(t){o(t)})):e.vhmongo_firebase.database().addDoc("products",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.addSubsProduct=function(t,e){var n=this;return new Promise((function(o,i){for(var a=new Array,s=0;s<e.length;s++)a[s]=Object.assign(Object.assign({},e[s]),{_id:n.vhAlgorithm.ObjectId()});n.vhmongo_firebase.database().getDoc("products",t).then((function(e){if(e){void 0===e.subs&&(e.subs=new Array);var i=E(e.subs,a);n.vhmongo_firebase.database().updateDoc("products",t,{subs:i}).then((function(){o(a)}),(function(t){o(null)}))}else o(null)}))}))},t.prototype.updateSubProduct=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.database().getDoc("products",t).then((function(t){t||i(!1),void 0===t.subs&&i(!1);for(var s=-1,r=0;r<t.subs.length;r++)if(t.subs[r]._id===e){s=r;break}-1===s?i(!1):(t.subs[s]=Object.assign(Object.assign({},t.subs[s]),n),o.vhmongo_firebase.database().updateDoc("products",t._id,{subs:t.subs}).then((function(t){i(t)}),(function(t){a(t)})))}))}))},t.prototype.deleteSubProduct=function(t,e){var n=this;return new Promise((function(o,i){var a=new Array;n.getlocalProductAndCombosAndToppings(t).forEach((function(t){a.push(t._id)})),1===a.length?n.vhmongo_firebase.database().getDocsByFields("vhbill_details",{id_subproduct:{$eq:e}},{},{},1).then((function(a){if(0===a.length){var s=n.getlocalProduct(t);if(null!=s.subs)for(var r=0;r<s.subs.length;r++)if(s.subs[r]._id===e){s.subs.splice(r,1),n.vhmongo_firebase.database().updateDoc("products",s._id,{subs:s.subs}).then((function(t){o(t)}),(function(t){i(t)}));break}}else o(!1)}),(function(t){i(t)})):(console.log("Bạn không thể xóa, vì sản phẩm đang liên kết với sản phẩm khác"),o(!1))}))},t.prototype.updateProduct=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("products",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteProduct=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("vhbill_details",{id_product:{$eq:t}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("products",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getProduct=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("products",t).then((function(t){n(t)}))}))},t.prototype.getProductsByFields=function(t,e,n,o){var i=this;return new Promise((function(a){i.vhQuery.getDocsByFields("products",t,e,n,o).then((function(t){i.products=JSON.parse(JSON.stringify(t)),a(t)}))}))},t.prototype.addCategory=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("categorys",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateCategory=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("categorys",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteCategory=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("products",{id_category:{$eq:t}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("categorys",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getCategory=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("categorys",t).then((function(t){n(t)}))}))},t.prototype.getCategorys=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("categorys").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.getCategorysByFields=function(t,e,n,o){var i=this;return new Promise((function(a){i.vhQuery.getDocsByFields("categorys",t,e,n,o).then((function(t){a(t)}))}))},t}();rt.decorators=[{type:e.Injectable}],rt.ctorParameters=function(){return[{type:o.Vhmongo_firebase},{type:V},{type:F},{type:L}]};var lt=function(){function t(){}return t.prototype.transform=function(t,e,n,o,i){return void 0===e&&(e="VND"),void 0===n&&(n="symbol"),void 0===o&&(o=""),void 0===i&&(i="en-VI"),_.formatCurrency(t,i,"",e,o)},t}();lt.decorators=[{type:e.Pipe,args:[{name:"vhcurrency"}]}];var ct=function(){function t(){}return t.prototype.transform=function(t,e,n,o,i){return void 0===e&&(e="en-VI"),void 0===n&&(n=""),void 0===o&&(o="symbol"),void 0===i&&(i="4.0-0"),_.formatCurrency(t,e,_.getCurrencySymbol(n,"wide"),n,i)},t}();ct.decorators=[{type:e.Pipe,args:[{name:"vhcurrencyunit"}]}];var ut=function(){function t(){}return t.prototype.transform=function(t,e,n){return void 0===e&&(e="en-VI"),void 0===n&&(n="1.2-2"),_.formatPercent(t,e,n)},t}();ut.decorators=[{type:e.Pipe,args:[{name:"vhpercent"}]}];var dt=function(){function t(t){this.dom=t}return t.prototype.transform=function(t,e){return this.dom.bypassSecurityTrustResourceUrl(e+t)},t}();dt.decorators=[{type:e.Pipe,args:[{name:"vhlink"}]}],dt.ctorParameters=function(){return[{type:p.DomSanitizer}]};var _t=function(){function t(t){this.dom=t}return t.prototype.transform=function(t){return this.dom.bypassSecurityTrustResourceUrl("https://www.youtube.com/embed/"+t)},t}();_t.decorators=[{type:e.Pipe,args:[{name:"vhyoutubelink"}]}],_t.ctorParameters=function(){return[{type:p.DomSanitizer}]};var pt=function(){function t(){}return t.prototype.transform=function(t,e,n){void 0===e&&(e=""),void 0===n&&(n="en-VI");var o="";if("time"===e)o="HH:mm:ss";else if("date"===e)o="dd/MM/YYYY";else{if("datetime"!==e)return"wrong format";o="dd/MM/YYYY HH:mm:ss"}return _.formatDate(t,o,"en-VI")},t}();pt.decorators=[{type:e.Pipe,args:[{name:"vhdate"}]}];var bt=function(){function t(){}return t.prototype.ngOnInit=function(){},t}();bt.decorators=[{type:e.Component,args:[{selector:"lib-ionic-vhframeworks",template:"\n <p>\n ionic-vhframeworks works!\n </p>\n "}]}],bt.ctorParameters=function(){return[]};var ft=function(){};ft.decorators=[{type:e.NgModule,args:[{declarations:[bt,z,T,M,N,R,dt,lt,ct,ut,_t,pt],imports:[],exports:[bt,z,T,M,N,R,dt,lt,ct,ut,_t,pt]}]}],t.DefaultLanguage=et,t.HttpLoaderFactory=tt,t.IonicVhframeworksComponent=bt,t.IonicVhframeworksModule=ft,t.VhAlgorithm=L,t.VhAuth=F,t.VhCamPlaybackComponent=z,t.VhCameraH265Ccomponent=M,t.VhCameraIMGcomponent=R,t.VhCameraJSMPEGCcomponent=N,t.VhCameraMSEVcomponent=T,t.VhCurrencyPipe=lt,t.VhCurrencyUnitPipe=ct,t.VhDate=pt,t.VhDriver=nt,t.VhEcommerce=G,t.VhForFirstTime=I,t.VhImage=U,t.VhLinkPipe=dt,t.VhMqttService=ot,t.VhPercentPipe=ut,t.VhQuery=V,t.VhQueryCafe=W,t.VhQueryCafeWebAdmin=rt,t.VhQueryCafeWebUser=st,t.VhQueryCare=Q,t.VhQueryCloudCam=J,t.VhQueryClouds=H,t.VhQuerySCclient=Z,t.VhQuerySales=Y,t.VhQuerySalesWebAdmin=at,t.VhQuerySalesWebUser=it,t.VhQuerySecurityCam=K,t.VhQuerySmhome=X,t.VhYoutubeLinkPipe=_t,t.vhDate=B,Object.defineProperty(t,"__esModule",{value:!0})}));
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/router"),require("vhmongo"),require("@ionic-native/image-picker/ngx"),require("@ionic-native/ionic-webview/ngx"),require("@ionic-native/camera/ngx"),require("@capacitor/device"),require("ngx-socket-io"),require("rxjs"),require("@ionic-native/in-app-purchase-2/ngx"),require("@ionic/angular"),require("@angular/common"),require("@angular/platform-browser"),require("ngx-papaparse"),require("@ionic-native/social-sharing/ngx"),require("@ionic-native/file/ngx"),require("xlsx"),require("cleave.js"),require("cleave.js/dist/addons/cleave-phone.i18n"),require("ngx-mqtt"),require("@ionic-native/wifi-wizard-2/ngx"),require("@ionic-native/bluetooth-serial/ngx"),require("dom-to-image"),require("@ngx-translate/core"),require("@angular/common/http"),require("@ionic-native/file/ngx/index"),require("@ionic-native/social-sharing/ngx/index")):"function"==typeof define&&define.amd?define("ionic-vhframeworks",["exports","@angular/core","@angular/router","vhmongo","@ionic-native/image-picker/ngx","@ionic-native/ionic-webview/ngx","@ionic-native/camera/ngx","@capacitor/device","ngx-socket-io","rxjs","@ionic-native/in-app-purchase-2/ngx","@ionic/angular","@angular/common","@angular/platform-browser","ngx-papaparse","@ionic-native/social-sharing/ngx","@ionic-native/file/ngx","xlsx","cleave.js","cleave.js/dist/addons/cleave-phone.i18n","ngx-mqtt","@ionic-native/wifi-wizard-2/ngx","@ionic-native/bluetooth-serial/ngx","dom-to-image","@ngx-translate/core","@angular/common/http","@ionic-native/file/ngx/index","@ionic-native/social-sharing/ngx/index"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["ionic-vhframeworks"]={},t.ng.core,t.ng.router,t.vhmongo,t[" @ionic-native/image-picker/ngx"],t["@ionic-native/ionic-webview/ngx"],t["@ionic-native/camera/ngx"],t["@capacitor/device"],t["ngx-socket-io"],t.rxjs,t["@ionic-native/in-app-purchase-2/ngx"],t["@ionic/angular"],t.ng.common,t.ng.platformBrowser,t["ngx-papaparse"],t["@ionic-native/social-sharing/ngx"],t["@ionic-native/file/ngx"],t.xlsx,t.cleave.js,null,t["ngx-mqtt"],t["@ionic-native/wifi-wizard-2/ngx"],t["@ionic-native/bluetooth-serial/ngx"],t["dom-to-image"],t["@ngx-translate/core"],t.ng.common.http,t["@ionic-native/file/ngx/index"],t["@ionic-native/social-sharing/ngx/index"])}(this,(function(t,e,n,o,i,a,s,r,l,c,u,d,_,p,b,f,h,y,m,v,g,x,q,w,P,D,k,A){"use strict";function S(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var O=S(m),$=S(w);Object.create;function C(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],o=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&o>=t.length&&(t=void 0),{value:t&&t[o++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function j(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var o,i,a=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(o=a.next()).done;)s.push(o.value)}catch(t){i={error:t}}finally{try{o&&!o.done&&(n=a.return)&&n.call(a)}finally{if(i)throw i.error}}return s}function E(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(j(arguments[e]));return t}Object.create;function B(t,e,n){var o="";if("time"===e)o="HH:mm:ss";else if("date"===e)o="dd/MM/YYYY";else if("datetime"===e)o="dd/MM/YYYY HH:mm:ss";else{if("YYYY-MM-dd HH:mm:ss"!==e)return"wrong format";o="YYYY-MM-dd HH:mm:ss"}return _.formatDate(t,o,"en-VI")}var L=function(){function t(t,e,n,o,i){this.platform=t,this.file=e,this.socialSharing=n,this.papa=o,this.dom=i}return t.prototype.isToday=function(t){var e=new Date(t);e.setHours(0),e.setMinutes(0),e.setSeconds(0),e.setMilliseconds(0);var n=new Date;return n.setHours(0),n.setMinutes(0),n.setSeconds(0),n.setMilliseconds(0),n.getTime()===e.getTime()},t.prototype.deepObjectEqual=function(t,e){var n,o,i=Object.keys(t),a=Object.keys(e);if(i.length!==a.length)return!1;try{for(var s=C(i),r=s.next();!r.done;r=s.next()){var l=r.value,c=t[l],u=e[l],d=this.isObject(c)&&this.isObject(u);if(d&&!this.deepObjectEqual(c,u)||!d&&c!==u)return!1}}catch(t){n={error:t}}finally{try{r&&!r.done&&(o=s.return)&&o.call(s)}finally{if(n)throw n.error}}return!0},t.prototype.isObject=function(t){return null!=t&&null!=t&&"object"==typeof t},t.prototype.ObjectId=function(t){null==t&&(t=24);for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",n="";t>0;)n+=e.charAt(Math.floor(Math.random()*e.length)),t--;return n},t.prototype.importXLSX=function(t){return new Promise((function(e,n){var o=new FileReader;o.readAsArrayBuffer(t),o.onload=function(t){for(var n=o.result,i=new Uint8Array(n),a=new Array,s=0;s!=i.length;++s)a[s]=String.fromCharCode(i[s]);var r=a.join(""),l=y.read(r,{type:"binary"}),c=l.SheetNames[0],u=l.Sheets[c],d=y.utils.sheet_to_json(u,{raw:!0});e(d)}}))},t.prototype.exportXLSX=function(t,e){var n=this;return new Promise((function(o,i){var a={Sheets:{data:y.utils.json_to_sheet(t)},SheetNames:["data"]},s=y.write(a,{bookType:"xlsx",type:"array"}),r=new Blob([s],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8"});if(n.platform.is("desktop")||n.platform.is("mobileweb")){var l=window.document.createElement("a");l.href=window.URL.createObjectURL(r),l.download=e+".xlsx",document.body.appendChild(l),l.click(),document.body.removeChild(l),o(null)}else n.file.writeFile(n.file.dataDirectory,e+".xlsx",r,{replace:!0}).then((function(t){n.socialSharing.share(e+".xlsx",e+".xlsx",t.nativeURL).then((function(){return o(null)})).catch((function(t){console.error(t),i(t)}))}))}))},t.prototype.importCSV=function(t){var e=this,n=t||"";return new Promise((function(t,o){e.papa.parse(n,{complete:function(e){var n=e.data.splice(0,1)[0],o=e.data;t({headerRow:n,csvData:o})}})}))},t.prototype.exportCSV=function(t,e,n){var o=this.papa.unparse({fields:t,data:e}),i=new Blob(["\ufeff",o]),a=window.document.createElement("a");a.href=window.URL.createObjectURL(i),a.download=n+".csv",document.body.appendChild(a),a.click(),document.body.removeChild(a)},t.prototype.waitingStack=function(){return new Promise((function(t,e){setTimeout((function(){t(null)}),0)}))},t.prototype.searchList=function(t,e,n){var o=this;new Array;return e.filter((function(e){for(var i=!1,a=0;a<n.length;a++)e[n[a]]&&(i=i||-1!==o.changeAlias(e[n[a]].toString().toLowerCase()).indexOf(o.changeAlias(t)));return!!i}))},t.prototype.changeAlias=function(t){var e=t;return e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=e.toLowerCase()).replace(/à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ/g,"a")).replace(/è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ/g,"e")).replace(/ì|í|ị|ỉ|ĩ/g,"i")).replace(/ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ/g,"o")).replace(/ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ/g,"u")).replace(/ỳ|ý|ỵ|ỷ|ỹ/g,"y")).replace(/đ/g,"d")).replace(/!|@|%|\^|\*|\(|\)|\+|\=|\<|\>|\?|\/|,|\.|\:|\;|\'|\"|\&|\#|\[|\]|~|\$|_|`|-|{|}|\||\\/g," ")).replace(/ + /g," ")).trim()},t.prototype.createBillCode=function(t){var e=Math.random().toString(36).substr(2,4),n=t?new Date(t):new Date;return(e+(1==(n.getMonth()+1).toString().length?"0"+(n.getMonth()+1).toString():(n.getMonth()+1).toString())+(1==n.getUTCDate().toString().length?"0"+n.getUTCDate().toString():n.getUTCDate().toString())).toUpperCase()},t.prototype.createPaymentCode=function(t){var e=Math.random().toString(36).substr(2,6),n=t?new Date(t):new Date;return(e+(1==(n.getMonth()+1).toString().length?"0"+(n.getMonth()+1).toString():(n.getMonth()+1).toString())+(1==n.getUTCDate().toString().length?"0"+n.getUTCDate().toString():n.getUTCDate().toString())).toUpperCase()},t.prototype.createCardCode=function(t){var e=Math.random().toString(36).substr(2,6),n=t?new Date(t):new Date;return(e+(1==(n.getMonth()+1).toString().length?"0"+(n.getMonth()+1).toString():(n.getMonth()+1).toString())+(1==n.getUTCDate().toString().length?"0"+n.getUTCDate().toString():n.getUTCDate().toString())).toUpperCase()},t.prototype.vhcurrencyunit=function(t){var e=localStorage.getItem("vhsales_currencyFormat");if(e){var n=JSON.parse(String(e)).digitDecimal.value,o=void 0;return 0===n?o="1.0-0":1===n?o="1.1-1":2===n?o="1.2-2":3===n?o="1.3-3":4===n?o="1.4-4":5===n&&(o="1.5-5"),_.formatCurrency(t,"en-VI",_.getCurrencySymbol("","wide"),"",o)}},t.prototype.vhcurrencyunit_symbol=function(t){var e=localStorage.getItem("vhsales_currencyFormat");if(e){var n=JSON.parse(String(e)).digitDecimal.value,o=void 0;0===n?o="1.0-0":1===n?o="1.1-1":2===n?o="1.2-2":3===n?o="1.3-3":4===n?o="1.4-4":5===n&&(o="1.5-5");var i=JSON.parse(String(e)).symbol.text,a=JSON.parse(String(e)).position.value,s="",r="";0===a?s=i+" ":1===a&&(r=" "+i);var l=/\(([^)]+)\)/,c=l.exec(s);c&&(s=c[1]);var u=l.exec(r);return u&&(r=u[1]),s+_.formatCurrency(t,"en-VI",_.getCurrencySymbol("","wide"),"",o)+r}},t.prototype.vhpercent=function(t){return _.formatPercent(t,"en-VI","1.2-2")},t.prototype.vhnumeral=function(t){return new O.default(t,{numeral:!0,numeralThousandsGroupStyle:"thousand"})},t.prototype.vhphoneNumber=function(t){return new O.default(t,{phone:!0,phoneRegionCode:"VN"})},t.prototype.vhYoutubeLink=function(t){return this.dom.bypassSecurityTrustResourceUrl("https://www.youtube.com/embed/"+t)},t.prototype.sortVietnamesebyASC=function(t,e){var n=this;return t.sort((function(t,o){return n.changeAlias(t[e])>n.changeAlias(o[e])?1:-1}))},t.prototype.sortVietnamesebyDESC=function(t,e){var n=this;return t.sort((function(t,o){return n.changeAlias(t[e])<n.changeAlias(o[e])?1:-1}))},t.prototype.sortDatebyASC=function(t,e){return t.sort((function(t,n){return new Date(t[e]).getTime()>new Date(n[e]).getTime()?1:-1}))},t.prototype.sortDatebyDESC=function(t,e){return t.sort((function(t,n){return new Date(t[e]).getTime()<new Date(n[e]).getTime()?1:-1}))},t.prototype.sortStringbyASC=function(t,e){return t.sort((function(t,n){return t[e].toUpperCase()>n[e].toUpperCase()?1:-1}))},t.prototype.sortStringbyDESC=function(t,e){return t.sort((function(t,n){return t[e].toUpperCase()<n[e].toUpperCase()?1:-1}))},t.prototype.sortNumberbyASC=function(t,e){return t.sort((function(t,n){return t[e]>n[e]?1:-1}))},t.prototype.sortNumberbyDESC=function(t,e){return t.sort((function(t,n){return t[e]<n[e]?1:-1}))},t.prototype.getNumberOfDaysInMonth=function(t,e){switch(e){case 1:case 3:case 5:case 7:case 8:case 10:case 12:return 31;case 2:return t%400==0||t%4==0&&t%100!=0?29:28;default:return 30}},t.prototype.Compare=function(t,e,n){return"=="===e?t==n:">"===e?t>n:">="===e?t>=n:"<"===e?t<n:"<="===e?t<=n:void 0},t.prototype.convert_STRING2OBJECT=function(t){try{return JSON.parse(t)}catch(t){return{}}},t.prototype.convert_OBJECT2STRING=function(t){return"object"==typeof t?JSON.stringify(t):""},t}();L.ɵprov=e.ɵɵdefineInjectable({factory:function(){return new L(e.ɵɵinject(d.Platform),e.ɵɵinject(k.File),e.ɵɵinject(A.SocialSharing),e.ɵɵinject(b.Papa),e.ɵɵinject(p.DomSanitizer))},token:L,providedIn:"root"}),L.decorators=[{type:e.Injectable,args:[{providedIn:"root"}]}],L.ctorParameters=function(){return[{type:d.Platform},{type:h.File},{type:f.SocialSharing},{type:b.Papa},{type:p.DomSanitizer}]};var I=function(){function t(t,e){this.vhmongo_firebase=t,this.vhAlgorithm=e}return t.prototype.addAPPdatabase_forFirstTime=function(){var t=this;return new Promise((function(e,n){if("vhsales"===t.vhmongo_firebase.auth().getProjectName()||"bvhsales"===t.vhmongo_firebase.auth().getProjectName())(o=new Array)[0]=t.addSales_branch(),o[1]=t.addSales_id_retail(),o[2]=t.addSales_tax(),o[3]=t.addSales_category_product(),o[4]=t.addSales_supplier(),o[5]=t.addSales_customer(),o[6]=t.addSales_wallet_Cash(),o[7]=t.addSales_incoming_group(),o[8]=t.addSales_spending_group(),Promise.all(o).then((function(){e(null)}),(function(t){e(t)}));else if("vhsmhome"===t.vhmongo_firebase.auth().getProjectName())e(null);else if("vhcafe"===t.vhmongo_firebase.auth().getProjectName()||"bvhcafe"===t.vhmongo_firebase.auth().getProjectName()){var o;(o=new Array)[0]=t.addCafe_branch(),o[1]=t.addSales_id_retail(),o[2]=t.addSales_tax(),o[3]=t.addCafe_category_product(),o[4]=t.addSales_supplier(),o[5]=t.addSales_customer(),o[6]=t.addSales_wallet_Cash(),o[7]=t.addCafe_area_table_GoHome(),o[8]=t.addSales_incoming_group(),o[9]=t.addSales_spending_group(),Promise.all(o).then((function(){e(null)}),(function(t){e(t)}))}else"vhcloudcam"===t.vhmongo_firebase.auth().getProjectName()||"securitycam"===t.vhmongo_firebase.auth().getProjectName()||"bsecuritycam"===t.vhmongo_firebase.auth().getProjectName()?t.vhmongo_firebase.f3rdclouds().createEUtokenFromUtoken().then((function(o){0===o.vcode?t.vhmongo_firebase.f3rdclouds().saveEUtokenToDatabase(o.eutoken).then((function(){e(!0)}),(function(t){n(t)})):e(!1)}),(function(t){n(t)})):("vhcare"===t.vhmongo_firebase.auth().getProjectName()||"vhclouds"===t.vhmongo_firebase.auth().getProjectName()||console.log("Lưu ý, projectname này không khởi tạo giá trị: ",t.vhmongo_firebase.auth().getProjectName()),e(null))}))},t.prototype.addAPPdatabase_forFirstTime_Sales_Cafe=function(){var t=this;return new Promise((function(e,n){if("vhsales"===t.vhmongo_firebase.auth().getProjectName()||"bvhsales"===t.vhmongo_firebase.auth().getProjectName())(o=new Array)[0]=t.addSales_id_retail(),o[1]=t.addSales_tax(),o[2]=t.addSales_category_product(),o[3]=t.addSales_supplier(),o[4]=t.addSales_customer(),o[5]=t.addSales_wallet_Cash(),o[6]=t.addSales_incoming_group(),o[7]=t.addSales_spending_group(),Promise.all(o).then((function(){e(null)}),(function(t){e(t)}));else if("vhcafe"===t.vhmongo_firebase.auth().getProjectName()||"bvhcafe"===t.vhmongo_firebase.auth().getProjectName()){var o;(o=new Array)[0]=t.addSales_id_retail(),o[1]=t.addSales_tax(),o[2]=t.addCafe_category_product(),o[3]=t.addSales_supplier(),o[4]=t.addSales_customer(),o[5]=t.addSales_wallet_Cash(),o[6]=t.addCafe_area_table_GoHome(),o[7]=t.addSales_incoming_group(),o[8]=t.addSales_spending_group(),Promise.all(o).then((function(){e(null)}),(function(t){e(t)}))}else console.log("Lưu ý, projectname này không khởi tạo giá trị: ",t.vhmongo_firebase.auth().getProjectName()),e(null)}))},t.prototype.addSales_id_retail=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().addDocbyID("customers","id_retail",{name:"Retail customer"}).then((function(){e(null)}),(function(t){n(t)}))}))},t.prototype.addSales_tax=function(){var t=this;return new Promise((function(e,n){var o=t.vhmongo_firebase.database().addDoc("taxs",{name:"VAT",value:0,status:!0,default:!0}),i=t.vhmongo_firebase.database().addDoc("taxs",{name:"VAT",value:5,status:!0,default:!1}),a=t.vhmongo_firebase.database().addDoc("taxs",{name:"VAT",value:10,status:!0,default:!1});Promise.all([o,i,a]).then((function(){e(null)}),(function(t){e(t)}))}))},t.prototype.addSales_category_product=function(){var t=this;return new Promise((function(e,n){var o=new Promise((function(e,n){t.vhmongo_firebase.database().addDoc("categorys",{name:"Danh mục sản phẩm",type:1}).then((function(n){t.vhmongo_firebase.database().addDoc("products",{id_category:n._id,allow_sell:!0,barcode:"0123456789",brand:"APPLE",cost_stock_last:0,img:"./assets/img/default/iphone-12-pro-max-512gb.jpg",name:"Iphone 12 Pro Max 512Gb",price:2e7,price_import:18e6,quantity:0,quantity_branch:{},unit:"Cái",warning_number:2,type:1}).then((function(){e(null)}))}))})),i=new Promise((function(e,n){t.vhmongo_firebase.database().addDoc("categorys",{name:"Danh mục dịch vụ",type:2}).then((function(n){t.vhmongo_firebase.database().addDoc("products",{id_category:n._id,allow_sell:!0,barcode:"1122334455",img:"./assets/img/default/bao-duong-ve-sinh-laptop.jpg",name:"Phí bảo dưỡng, vệ sinh laptop",price:1e5,unit:"Cái",type:2}).then((function(){e(null)}))}))})),a=new Promise((function(e,n){t.vhmongo_firebase.database().addDocbyID("categorys","id_category_combo",{name:"Danh mục món kết hợp",type:5}).then((function(){e(null)}),(function(t){n(t)}))}));Promise.all([o,i,a]).then((function(){e(null)}),(function(t){e(t)}))}))},t.prototype.addSales_supplier=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().addDoc("suppliers",{address:"116/18 Thiên Phước, F9, Tân Bình",email:"viethas.info@gmail.com",name:"Công Ty TNHH GPCN VIETHAS",note:"không có",phone:"02838661111",taxcode:"312122525"}).then((function(){e(null)}),(function(t){n(t)}))}))},t.prototype.addSales_customer=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().addDoc("customers",{address:"115 đường TL8, phường Phú Mỹ",date:new Date,datebirth:new Date,debt_enable:!0,district:"Củ chi",email:"vanminh@gmail.com",gender:"Nam",name:"Nguyễn Văn Minh",note:" ",phone:"0971606060",province:"Hồ chí minh"}).then((function(){e(null)}),(function(t){n(t)}))}))},t.prototype.addSales_wallet_Cash=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().addDocbyID("wallets","id_cash",{name:"Cash"}).then((function(){e(null)}),(function(t){n(t)}))}))},t.prototype.addSales_incoming_group=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().addDoc("incoming_groups",{name:"Thu khác",default:!0}).then((function(){e(null)}),(function(t){n(t)}))}))},t.prototype.addSales_spending_group=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().addDoc("spending_groups",{name:"Chi khác",default:!0}).then((function(){e(null)}),(function(t){n(t)}))}))},t.prototype.addSales_wallet=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("wallets",{address:"Hồ chí minh",bank_name:"Ngân Hàng Ngoại Thương",holder:"Trương Thị Thu Hương",name:"Vietcombank",note:"",number:"1940201041052",id_branch:t}).then((function(){n(null)}),(function(t){o(t)}))}))},t.prototype.addSales_branch=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().addDoc("branchs",{name:"Chi nhánh 1",address:t.vhmongo_firebase.auth().getUser().address,countrycode:t.vhmongo_firebase.auth().getUser().countrycode,phone:t.vhmongo_firebase.auth().getUser().phone,email:t.vhmongo_firebase.auth().getUser().email,company:t.vhmongo_firebase.auth().getUser().company,active:!0}).then((function(n){var o=t.addSales_StoreInfo(n._id),i=t.addSales_wallet(n._id);Promise.all([o,i]).then((function(){e(null)}))}),(function(t){n(t)}))}))},t.prototype.addCafe_branch=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().addDoc("branchs",{name:"Chi nhánh 1",address:t.vhmongo_firebase.auth().getUser().address,countrycode:t.vhmongo_firebase.auth().getUser().countrycode,phone:t.vhmongo_firebase.auth().getUser().phone,email:t.vhmongo_firebase.auth().getUser().email,company:t.vhmongo_firebase.auth().getUser().company,active:!0}).then((function(n){var o=t.addSales_StoreInfo(n._id),i=t.addSales_wallet(n._id),a=t.addCafe_area_table(n._id);Promise.all([o,i,a]).then((function(){e(null)}))}),(function(t){n(t)}))}))},t.prototype.addSales_StoreInfo=function(t){var e=this;return new Promise((function(n,o){var i=e.vhmongo_firebase.auth().getStore(),a={name:i.name,phone:i.phone,countrycode:null==i?void 0:i.countrycode,address:i.address,company:i.company,email:i.email,tax_number:"",opentime:"8h:00 AM",closetime:"10h:00 PM",img:"",appsetting_name:"store_info"};a.id_branch=t,e.vhmongo_firebase.database().addDoc("appsettingbranchs",a).then((function(){n(null)}),(function(t){o(t)}))}))},t.prototype.addCafe_category_product=function(){var t=this;return new Promise((function(e,n){var o=new Array;o[0]=new Promise((function(e,n){t.vhmongo_firebase.database().addDoc("categorys",{name:"Danh mục nước pha chế",type:1}).then((function(o){t.vhmongo_firebase.database().addDoc("products",{id_category:o._id,allow_sell:!0,describe:"",img:"./assets/img/default/ca-phe-sua-da.jpg",name:"Cà phê sửa đá",type:1,unit:"Ly",price:25e3,price_import:2e4,time_warning:5,manysize:!1}).then((function(){e(null)}),(function(t){n(t)}))}),(function(t){n(t)}))})),o[1]=new Promise((function(e,n){t.vhmongo_firebase.database().addDoc("categorys",{name:"Danh mục món ăn",type:1}).then((function(o){t.vhmongo_firebase.database().addDoc("products",{id_category:o._id,allow_sell:!0,describe:"",img:"./assets/img/default/com-chien-hai-san.jpg",name:"Cơm chiên hải sản",type:1,unit:"Dĩa",time_warning:15,manysize:!0,subs:[{_id:t.vhAlgorithm.ObjectId(),price:149e3,name:"Size lớn"},{_id:t.vhAlgorithm.ObjectId(),price:99e3,name:"Size nhỏ"}]}).then((function(){e(null)}),(function(t){n(t)}))}),(function(t){n(t)}))})),o[2]=new Promise((function(e,n){t.vhmongo_firebase.database().addDoc("categorys",{name:"Danh mục dịch vụ",type:2}).then((function(n){t.vhmongo_firebase.database().addDoc("products",{id_category:n._id,img:"./assets/img/default/phong-vip.jpg",name:"Phòng VIP",price:1e5,type:2,unit:"Giờ",allow_sell:!0}).then((function(){e(null)}))}))})),o[3]=new Promise((function(e,n){t.vhmongo_firebase.database().addDoc("categorys",{name:"Danh mục nước đóng sẳn",type:3}).then((function(o){t.vhmongo_firebase.database().addDoc("products",{id_category:o._id,describe:"",img:"./assets/img/default/coca-cola.jpg",name:"Coca cola",price_import:15e3,price:2e4,type:3,unit:"Lon",allow_sell:!0,time_warning:10,warning_number:5,quantity:0,quantity_branch:{}}).then((function(){e(null)}),(function(t){n(t)}))}),(function(t){n(t)}))})),o[4]=new Promise((function(e,n){t.vhmongo_firebase.database().addDoc("categorys",{name:"Danh mục nguyên liệu",type:3}).then((function(n){t.vhmongo_firebase.database().addDoc("products",{id_category:n._id,describe:"",img:"./assets/img/default/nuoc-mam-nam-ngu-750ml.jpg",name:"Nguyên liệu mẫu",price_import:2e4,price:3e4,type:3,unit:"Chai",allow_sell:!1,warning_number:5,quantity:0,quantity_branch:{}}).then((function(){e(null)}))}))})),o[5]=new Promise((function(e,n){t.vhmongo_firebase.database().addDocbyID("categorys","id_category_topping",{name:"Danh mục món bán kèm",type:4}).then((function(){e(null)}),(function(t){n(t)}))})),o[6]=new Promise((function(e,n){t.vhmongo_firebase.database().addDocbyID("categorys","id_category_combo",{name:"Danh mục món kết hợp",type:5}).then((function(){e(null)}),(function(t){n(t)}))})),Promise.all(o).then((function(){e(null)}),(function(t){e(t)}))}))},t.prototype.addCafe_area_table_GoHome=function(){var t=this;return new Promise((function(e,n){var o=t.vhmongo_firebase.database().addDocbyID("areas","go_home",{name:"Take away",status:!0}).then((function(){e(null)}),(function(t){n(t)})),i=t.vhmongo_firebase.database().addDocbyID("tables","go_home",{id_area:"go_home",name:"Take away",status:!0}).then((function(){e(null)}),(function(t){n(t)}));Promise.all([o,i]).then((function(){e(!0)}),(function(t){e(t)}))}))},t.prototype.addCafe_area_table=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("areas",{name:"Area 1",status:!0,id_branch:t}).then((function(o){e.vhmongo_firebase.database().addDoc("tables",{id_area:o._id,name:"Table 1",status:!1,id_branch:t}).then((function(){n(null)}))}))}))},t}();I.decorators=[{type:e.Injectable}],I.ctorParameters=function(){return[{type:o.Vhmongo_firebase},{type:L}]};var F=function(){function t(t,e,n){var o=this;this.vhmongo_firebase=t,this.vhForFirstTime=e,this.renderFactory=n,this.mypermission={},this.employees=new Array,this.endusers=new Array,this.appsetting_stations=new Array,this.hwinfo={},this.subjectemployees=new c.Subject,r.Device.getId().then((function(t){var e=o.localStorageGET("hwinfo");null!=e&&null!=e?o.hwinfo=e:(o.hwinfo=Object.assign({},t),o.localStorageSET("hwinfo",o.hwinfo))})),this.renderer=this.renderFactory.createRenderer(null,null)}return t.prototype.signInWithEmailAndPasswordOfEndUser=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.auth().signInWithEmailAndPasswordOfEndUser(t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.onAuthStateChangedOfEndUser=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.auth().onAuthStateChangedOfEndUser().then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.signInWithEmailAndPassword=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.auth().signInWithEmailAndPassword(t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.onAuthStateChanged=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.auth().onAuthStateChanged().then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.signUpOwner_Sales=function(t,e,n,o){var i=this;return new Promise((function(a,s){i.vhmongo_firebase.auth().signUpOwner_Sales(t,e,n,o).then((function(n){console.log("owner1",n),i.signInWithEmailAndPassword_Sales(t,e).then((function(){console.log("owner2",n),i.vhForFirstTime.addAPPdatabase_forFirstTime_Sales_Cafe().then((function(){console.log("owner3",n),a(n),i.signOut()}))}))}),(function(t){s(t)}))}))},t.prototype.signInWithEmailAndPassword_Sales=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.auth().signInWithEmailAndPassword_Sales(t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.onAuthStateChanged_Sales=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.auth().onAuthStateChanged_Sales().then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.signUpOwner_Cafe=function(t,e,n,o){var i=this;return new Promise((function(a,s){i.vhmongo_firebase.auth().signUpOwner_Cafe(t,e,n,o).then((function(n){console.log("owner1",n),i.signInWithEmailAndPassword_Cafe(t,e).then((function(){console.log("owner2",n),i.vhForFirstTime.addAPPdatabase_forFirstTime_Sales_Cafe().then((function(){console.log("owner3",n),a(n),i.signOut()}))}))}),(function(t){s(t)}))}))},t.prototype.signInWithEmailAndPassword_Cafe=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.auth().signInWithEmailAndPassword_Cafe(t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.onAuthStateChanged_Cafe=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.auth().onAuthStateChanged_Cafe().then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.signOut=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.auth().signOut().then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.resetPasswordbyEmail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.auth().sendPasswordResetEmail(t).then((function(){n(!0)})).catch((function(){n(!1)}))}))},t.prototype.getProjectName=function(){return this.vhmongo_firebase.auth().getProjectName()},t.prototype.getUser=function(){return this.vhmongo_firebase.auth().getUser()},t.prototype.getUID=function(){return this.vhmongo_firebase.auth().getUID()},t.prototype.getUUID=function(){return this.hwinfo},t.prototype.getToken=function(){return this.vhmongo_firebase.auth().getToken()},t.prototype.getDBCloudURL=function(){return this.vhmongo_firebase.auth().getDBCloudURL()},t.prototype.getStore=function(){return this.vhmongo_firebase.auth().getStore()},t.prototype.getDBstorage=function(){return this.vhmongo_firebase.auth().getDBstorage()},t.prototype.newDate=function(t){return"firebase-mongo"===this.vhmongo_firebase.auth().getDBstorage()?new Date(t):"firebase"===this.vhmongo_firebase.auth().getDBstorage()?t.toDate():void 0},t.prototype.initializeDB=function(t){},t.prototype.initializeProject=function(t,e,n,o,i,a){if(!(20062220==i||20062220==i))return null;this.vhmongo_firebase.initializeProject(t,e,n,o,a)},t.prototype.initializeWebAppProject=function(t,e,n){if(!(20062220==e||20062220==e))return null;this.vhmongo_firebase.initializeWebAppProject(t,n)},t.prototype.runOnMGDBServerVersion=function(t){this.vhmongo_firebase.runOnMGDBServerVersion(t)},t.prototype.runOnCamServerVersion=function(t){this.vhmongo_firebase.runOnCamServerVersion(t)},t.prototype.localStorageSET=function(t,e){"object"==typeof e?localStorage.setItem(this.vhmongo_firebase.auth().getProjectName()+"_"+t,JSON.stringify(e)):localStorage.setItem(this.vhmongo_firebase.auth().getProjectName()+"_"+t,e)},t.prototype.localStorageGET=function(t){return JSON.parse(localStorage.getItem(this.vhmongo_firebase.auth().getProjectName()+"_"+t))},t.prototype.signUpOwner=function(t,e,n,o){var i=this;return new Promise((function(a,s){i.vhmongo_firebase.auth().signUpOwner(t,e,n,o).then((function(n){i.signInWithEmailAndPassword(t,e).then((function(){i.vhForFirstTime.addAPPdatabase_forFirstTime().then((function(){a(n),i.signOut()}))}))}),(function(t){s(t)}))}))},t.prototype.signUpMember=function(t,e,n,o){var i=this;return new Promise((function(a,s){i.vhmongo_firebase.auth().signUpMember(t,e,n,o).then((function(t){a(t)}),(function(t){s(t)}))}))},t.prototype.signUpEndUser=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=Object.assign({},o);r.eucode=Math.random().toString(10).substr(2,11),i.vhmongo_firebase.auth().signUpEndUser(t,e,n,r).then((function(t){a(t)}),(function(t){s(t)}))}))},t.prototype.getLocalMyPermission=function(){return this.mypermission},t.prototype.refreshLocalMyPermission=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDoc("vhpermissions",t.getUser()._id).then((function(n){n&&(t.mypermission=n),e(null)}),(function(t){n(t)}))}))},t.prototype.checkMyPermission=function(t){return"boss"==this.getUser().owner||!!this.getLocalMyPermission()[t]},t.prototype.checkLocalMyPermissionName=function(t){return"boss"==this.getUser().owner||!!this.getLocalMyPermission()[t]},t.prototype.getLocalMyPermissionName=function(t){if("boolean"!=typeof this.getLocalMyPermission()[t])return this.getLocalMyPermission()[t]},t.prototype.updateMyPermission=function(t){var e=this,n=this.getUID();return new Promise((function(o,i){e.getPermission(n).then((function(a){a?e.vhmongo_firebase.database().updateDoc("vhpermissions",n,t).then((function(t){o(t)}),(function(t){i(t)})):e.vhmongo_firebase.database().addDocbyID("vhpermissions",n,t).then((function(){o(!0)}),(function(t){i(t)}))}),(function(t){i(t)}))}))},t.prototype.updatePermission=function(t,e){var n=this;return new Promise((function(o,i){n.getPermission(t).then((function(a){a?n.vhmongo_firebase.database().updateDoc("vhpermissions",t,e).then((function(t){o(t)}),(function(t){i(t)})):n.vhmongo_firebase.database().addDocbyID("vhpermissions",t,e).then((function(){o(!0)}),(function(t){i(t)}))}),(function(t){i(t)}))}))},t.prototype.getPermission=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("vhpermissions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.publishObservableEventEmployees=function(){this.subjectemployees.next(this.employees)},t.prototype.observableLocalEmployees=function(){return this.subjectemployees},t.prototype.getObservableLocalEmployees=function(){var t=this;return new c.Observable((function(e){t.observableLocalEmployees().subscribe((function(t){e.next(t)})),t.publishObservableEventEmployees()}))},t.prototype.clearLocalEmployeeFromSyncCollection=function(){this.employees=new Array},t.prototype.deleteLocalEmployeeFromSyncCollection=function(t){for(var e=!1,n=0;n<this.employees.length;n++)if(this.employees[n]._id===t){this.employees.splice(n,1),e=!0;break}return e},t.prototype.updateLocalEmployeeFromSyncCollection=function(t,e){for(var n=!1,o=0;o<this.employees.length;o++)if(this.employees[o]._id===t){this.employees[o]=Object.assign(Object.assign({},this.employees[o]),e),n=!0;break}return n},t.prototype.insertlocalEmployeeFromSyncCollection=function(t){var e=!1;return this.getlocalEmployee(t._id)||(this.employees.push(t),e=!0),e},t.prototype.getlocalEmployee=function(t){for(var e=0;e<this.employees.length;e++)if(this.employees[e]._id===t)return this.employees[e];return null},t.prototype.getlocalEmployees=function(){return this.employees},t.prototype.refreshLocalEmployees=function(){return new Promise((function(t,e){t(null)}))},t.prototype.updateEmployee=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("vhemployees",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteEmployee=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("bills",{id_employee:{$eq:t}},{},{},1).then((function(i){0===i.length?e.getEmployee(t).then((function(i){return i?"member"!=i.owner?n(!1):void e.getPermission(t).then((function(i){i&&e.vhmongo_firebase.database().deleteDoc("vhpermissions",t),e.vhmongo_firebase.database().deleteDoc("vhemployees",t).then((function(t){n(t)}),(function(t){o(t)}))}),(function(t){o(t)})):n(!1)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getEmployee=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("vhemployees",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getEmployees=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("vhemployees").then((function(n){t.employees=n,e(n)}),(function(t){n(t)}))}))},t.prototype.updateLocalEndUser=function(t,e){for(var n=0;n<this.endusers.length;n++)if(this.endusers[n]._id===t){this.endusers[n]=Object.assign(Object.assign({},this.endusers[n]),e);break}return!0},t.prototype.getlocalEndUser=function(t){for(var e=0;e<this.endusers.length;e++)if(this.endusers[e]._id===t)return this.endusers[e];return null},t.prototype.getlocalEndUsers=function(){return this.endusers},t.prototype.refreshLocalEndUsers=function(){var t=this;return new Promise((function(e,n){t.getEndUsers().then((function(){e(null)}))}))},t.prototype.updateEndUser=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("vhendusers",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteEndUser=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("bills",{id_employee:{$eq:t}},{},{},1).then((function(i){0===i.length?e.getEndUser(t).then((function(i){return i?"enduser"!=i.owner?n(!1):void e.getPermission(t).then((function(i){i&&e.vhmongo_firebase.database().deleteDoc("vhpermissions",t),e.vhmongo_firebase.database().deleteDoc("vhendusers",t).then((function(t){n(t)}),(function(t){o(t)}))}),(function(t){o(t)})):n(!1)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getEndUser=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("vhendusers",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getEndUsers=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("vhendusers").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.getEndUsers_byFields=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.database().getDocsByFields("vhendusers",t,{},n,o).then((function(t){e(t)}),(function(t){a(t)}))}))},t.prototype.getExistedCurrencyFormat=function(){var t=localStorage.getItem("vhsales_currencyFormat");return t?JSON.parse(String(t)):null},t.prototype.syncExistedCurrencyFormat=function(){localStorage.getItem("vhsales_currencyFormat")||localStorage.setItem("vhsales_currencyFormat",JSON.stringify({symbol:{text:"₫",value:5},position:{text:"1",value:0},digitDecimal:{text:"0",value:0},digitGroup:{text:"123,456",value:1}}))},t.prototype.getExistedTheme=function(){return localStorage.getItem("vh_theme")},t.prototype.setTheme=function(t){for(var e=Array.from(document.body.classList),n=0;n<e.length;n++)e[n].indexOf("-theme")>-1&&e.splice(n,1);document.body.className=e.join(" "),"vh-theme"!=t?(this.renderer.addClass(document.body,t),localStorage.setItem("vh_theme",t)):localStorage.removeItem("vh_theme")},t.prototype.syncExistedTheme=function(){var t=this.getExistedTheme();t&&this.setTheme(t)},t.prototype.changeThemeIcon=function(){var t=this.getExistedTheme();t?document.getElementsByClassName("color "+t)[0].click():document.getElementsByClassName("vh-theme")[0].click()},t.prototype.changeTheme=function(t,e){var n,o;try{for(var i=C(e.target.parentElement.children),a=i.next();!a.done;a=i.next()){a.value.innerHTML=""}}catch(t){n={error:t}}finally{try{a&&!a.done&&(o=i.return)&&o.call(i)}finally{if(n)throw n.error}}e.target.innerHTML='<ion-icon color="vh-white" src=\'data:image/svg+xml;utf8,\n <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"\n viewBox="0 0 600 600" style="enable-background:new 0 0 512 512;" xml:space="preserve"> \n <path d="M504.502,75.496c-9.997-9.998-26.205-9.998-36.204,0L161.594,382.203L43.702,264.311c-9.997-9.998-26.205-9.997-36.204,0\n c-9.998,9.997-9.998,26.205,0,36.203l135.994,135.992c9.994,9.997,26.214,9.99,36.204,0L504.502,111.7\n C514.5,101.703,514.499,85.494,504.502,75.496z"/> \n </svg>\'>\n </ion-icon>',this.setTheme(t)},t.prototype.getManualVideos=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getManualVideos(t).then((function(t){n(t)}),(function(t){o(t)}))}))},t}();F.decorators=[{type:e.Injectable}],F.ctorParameters=function(){return[{type:o.Vhmongo_firebase},{type:I},{type:e.RendererFactory2}]};var z=function(){function t(t,e,n){this.platform=t,this.router=e,this.vhmongo_firebase=n,this.licensecam="",this.filename="",this.camplaybackURL="",this._src="",this.randomId="cpb",this.oldrandomId="cpb",t.ready().then((function(){}))}return t.prototype.ngOnChanges=function(t){""!=this.filename&&""!=this.licensecam&&this.playbackVideo()},t.prototype.ngOnInit=function(){},t.prototype.playbackVideo=function(){var t=this;this.randomId=Math.random().toString(36).substr(2,5),document.getElementById(this.oldrandomId).id=this.randomId,this.camplayback=document.getElementById(this.randomId),this.oldrandomId=this.randomId,this.camplayback.src="",this.makePlaybackVideoByUser().then((function(e){if(e){var n="licensecam="+t.licensecam,o="rd="+t.randomId;t._src=t.camplaybackURL+"/cloudcamplayback/playbackvideo?"+n+"&filename=playbackvideo&"+o,t.camplayback.src=t._src}}))},t.prototype.ngOnDestroy=function(){document.getElementById(this.oldrandomId).src=""},t.prototype.feAdjustVideoPlaybackInFrame=function(t,e){var n;for(n=0;n<t.frames.length;n++)try{this.feAdjustVideoPlaybackInFrame(t.frames[n],e),t.frames[n].document.querySelector("video").playbackRate=e}catch(t){}},t.prototype.makePlaybackVideoByUser=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.clouds().makePlaybackVideoByUser(t.licensecam,t.camplaybackURL,t.filename).then((function(t){e(t)}),(function(t){n(t)}))}))},t}();z.decorators=[{type:e.Component,args:[{selector:"vh-camplayback",template:' \n <iframe id="cpb" allow="autoplay" allowfullscreen frameborder="0" style="object-fit: fill; width: 100%; height: 100%;" marginheight="0" marginwidth="0"> \n </iframe> \n '}]}],z.ctorParameters=function(){return[{type:d.Platform},{type:n.Router},{type:o.Vhmongo_firebase}]},z.propDecorators={licensecam:[{type:e.Input}],filename:[{type:e.Input}],camplaybackURL:[{type:e.Input}]};var M=function(){function t(t,o){var i=this;this.platform=t,this.router=o,this.url="",this.licensecam="",this.camliveURL="",this.poster="",this.roomid="",this.play=!0,this.monitor=1,this.os="android",this.change=new e.EventEmitter,this.list_camera=[],this._src="",this._video={},this._run=void 0,this._first_time=!0,this._play=!0,this._count=0,this._poster="",this.mime='video/mp4; codecs="avc1.640032"',this.video={},this.randomId="",this.integer=0,t.ready().then((function(){i.router.events.subscribe((function(t){(t instanceof n.NavigationEnd&&"/mobile/tabs/settings"===t.url||t instanceof n.NavigationEnd&&"/mobile/tabs/scripts"===t.url||t instanceof n.NavigationEnd&&"/mobile/tabs/scene"===t.url||t instanceof n.NavigationEnd&&"/mobile/tabs/play-back"===t.url)&&i._run&&i.stopVideo()})),i.randomId=Math.random().toString(36).substr(2,5),i._poster=localStorage.getItem(i.licensecam),document.getElementById("mse").id=i.randomId,i._play&&i.loadVideo()}))}return t.prototype.ngOnInit=function(){},t.prototype.ngOnChanges=function(t){this._play=this.play,null!=this._run&&(this._play?this._run||this.startVideo():this._run&&this.stopVideo())},t.prototype.ngOnDestroy=function(){this._run&&this.stopVideo(),console.log("destroyed camera")},t.prototype.loadVideo=function(){var t=this;console.log("loadVideo"),this.config={channelid:this.licensecam,channelname:this.licensecam,url:this.url,monitor:this.monitor,os:this.os};for(var e=0,n=0,o=new Array,i=0;i<10;i++)o[i]=0;this.video=document.getElementById(this.randomId),this.mediaSource=new MediaSource,this.video.src=URL.createObjectURL(this.mediaSource),this.subscription_listenMediaSource=this.listenMediaSource().subscribe((function(i){t.subscription_listenBuffer=t.listenBuffer().subscribe((function(i){t.mediaSource.duration!==Number.POSITIVE_INFINITY&&0===t.video.currentTime&&t.mediaSource.duration>0&&(t.video.currentTime=t.mediaSource.duration-1,t.mediaSource.duration=Number.POSITIVE_INFINITY),e=t.video.currentTime-n,n=t.video.currentTime;var a=0;if(0!=e){o[Math.round(e)]++;for(var s=0;s<o.length;s++)o[s]>a&&(a=o[s],t.integer=s);0!=t.integer&&(t.video.playbackRate=e/t.integer+.1)}}),(function(t){console.log(t)})),t._play?t.startVideo():(t._run=!1,t.change.emit({status:"loaded"}))}),(function(t){console.log(t)}))},t.prototype.startVideo=function(){this.change.emit({status:"play"}),this.config.monitor=this.monitor;var t=this,e="?channelid="+this.config.channelid+"&channelname="+this.config.channelname+"&url="+this.config.url+"&monitor="+this.config.monitor+"&os="+this.config.os;this.socket=new WebSocket(this.camliveURL+e),this.socket.addEventListener("open",(function(t){})),this.socket.addEventListener("message",(function(e){new Blob([e.data],{type:"image/jpeg"}).arrayBuffer().then((function(e){var n=new Uint8Array(e);t.buffer.appendBuffer(n),5==t._count&&t.getScreenshot(),t._count++}))})),this.video.muted=!0,this._run=!0,console.log("startVideo")},t.prototype.stopVideo=function(){this.video.pause(),this._run=!1,this.socket.removeAllListeners(),this.socket.close(),console.log("stopVideo")},t.prototype.listenMediaSource=function(){var t=this,e=this;return c.Observable.create((function(n){t.mediaSource.addEventListener("updateend",(function(t){console.log("updateend: "+e.mediaSource.readyState)})),t.mediaSource.addEventListener("sourceended",(function(t){console.log("sourceended: "+e.mediaSource.readyState)})),t.mediaSource.addEventListener("sourceclose",(function(t){console.log("sourceclose: "+e.mediaSource.readyState)})),t.mediaSource.addEventListener("error",(function(t){console.log("error: "+e.mediaSource.readyState)})),t.mediaSource.addEventListener("sourceopen",(function(t){n.next("sourceopen")}),!0)}))},t.prototype.listenBuffer=function(){var t=this;return c.Observable.create((function(e){t.buffer=t.mediaSource.addSourceBuffer(t.mime),t.buffer.mode="sequence",t.buffer.addEventListener("updateend",(function(t){e.next("updateend")}))}))},t.prototype.getScreenshot=function(){var t=document.getElementById(this.randomId),e=document.createElement("canvas");(null==t?void 0:t.videoWidth)>=1280?(e.width=t.videoWidth/4,e.height=t.videoHeight/4):(null==t?void 0:t.videoWidth)<1280&&(e.width=t.videoWidth/2,e.height=t.videoHeight/2),e.getContext("2d").drawImage(t,0,0,e.width,e.height);var n=e.toDataURL();localStorage.setItem(this.licensecam,n)},t}();M.decorators=[{type:e.Component,args:[{selector:"vh-camera-msev",template:'\n <video id="mse" poster={{_poster}} autoplay=true style="object-fit: fill; width: 100%; height: 100%;">\n </video>\n '}]}],M.ctorParameters=function(){return[{type:d.Platform},{type:n.Router}]},M.propDecorators={url:[{type:e.Input,args:["url"]}],licensecam:[{type:e.Input}],camliveURL:[{type:e.Input}],poster:[{type:e.Input}],roomid:[{type:e.Input}],width:[{type:e.Input}],height:[{type:e.Input}],play:[{type:e.Input}],monitor:[{type:e.Input}],os:[{type:e.Input}],change:[{type:e.Output}]};var T=function(){function t(t,o){var i=this;this.platform=t,this.router=o,this.url="",this.licensecam="",this.camliveURL="",this.poster="",this.roomid="",this.play=!0,this.monitor=1,this.os="ios",this.change=new e.EventEmitter,this.online=new e.EventEmitter,this.detection=new e.EventEmitter,this.list_camera=[],this._src="",this._run=void 0,this._autoplay=!1,this._play=!0,this._poster="",this.randomId="",t.ready().then((function(){i.router.events.subscribe((function(t){(t instanceof n.NavigationEnd&&"/mobile/tabs/settings"===t.url||t instanceof n.NavigationEnd&&"/mobile/tabs/scripts"===t.url||t instanceof n.NavigationEnd&&"/mobile/tabs/scene"===t.url||t instanceof n.NavigationEnd&&"/mobile/tabs/play-back"===t.url)&&i._run&&i.stopVideo()})),i._poster=localStorage.getItem(i.licensecam),i.randomId=Math.random().toString(36).substr(2,5),document.getElementById("vh-camera-canvas").id=i.randomId,i._play&&i.loadVideo()}))}return t.prototype.ngOnInit=function(){},t.prototype.ngOnChanges=function(t){this._play=this.play,null!=this._run&&(this._play?this._run||this.startVideo():this._run&&this.stopVideo())},t.prototype.ngOnDestroy=function(){this._run&&this.stopVideo()},t.prototype.loadVideo=function(){this.config={channelid:this.licensecam,channelname:this.licensecam,url:this.url,monitor:this.monitor,os:this.os},this._play?this.startVideo():this._run=!1},t.prototype.startVideo=function(){var t=this;this.online.emit({status:!0}),this.config.monitor=this.monitor;var e="?channelid="+this.config.channelid+"&channelname="+this.config.channelname+"&url="+this.config.url+"&monitor="+this.config.monitor+"&os="+this.config.os,n=document.getElementById(this.randomId);this.wsavc=new WSAvcPlayer(n,"webgl",1,35),this.wsavc.connect(this.camliveURL+e),this.wsavc.on("deadprocess",(function(){t._run&&(t.stopVideo(),t.settimeout=setTimeout((function(){t.startVideo()}),5e3))})),this.wsavc.on("detection",(function(e){t.detection.emit({status:e})})),this._run=!0},t.prototype.stopVideo=function(){this.online.emit({status:!1}),this.settimeout&&clearTimeout(this.settimeout),this._run=!1,this.wsavc.disconnect()},t.prototype.getScreenshot=function(){var t=document.getElementById(this.randomId),e=document.createElement("canvas");(null==t?void 0:t.videoWidth)>=1280?(e.width=t.videoWidth/4,e.height=t.videoHeight/4):(null==t?void 0:t.videoWidth)<1280&&(e.width=t.videoWidth/2,e.height=t.videoHeight/2),e.getContext("2d").drawImage(t,0,0,e.width,e.height);var n=e.toDataURL();localStorage.setItem(this.licensecam,n)},t}();T.decorators=[{type:e.Component,args:[{selector:"vh-camera-h265c",template:' \n <canvas id="vh-camera-canvas">\n </canvas> \n '}]}],T.ctorParameters=function(){return[{type:d.Platform},{type:n.Router}]},T.propDecorators={url:[{type:e.Input,args:["url"]}],licensecam:[{type:e.Input}],camliveURL:[{type:e.Input}],poster:[{type:e.Input}],roomid:[{type:e.Input}],width:[{type:e.Input}],height:[{type:e.Input}],play:[{type:e.Input}],monitor:[{type:e.Input}],os:[{type:e.Input}],change:[{type:e.Output}],online:[{type:e.Output}],detection:[{type:e.Output}]};var N=function(){function t(t,o){var i=this;this.platform=t,this.router=o,this.url="",this.licensecam="",this.camliveURL="",this.poster="",this.roomid="",this.play=!0,this.monitor=1,this.os="ios",this.change=new e.EventEmitter,this.list_camera=[],this._src="",this._run=void 0,this._autoplay=!1,this._play=!0,this._poster="",this.randomId="",t.ready().then((function(){i.router.events.subscribe((function(t){(t instanceof n.NavigationEnd&&"/mobile/tabs/settings"===t.url||t instanceof n.NavigationEnd&&"/mobile/tabs/scripts"===t.url||t instanceof n.NavigationEnd&&"/mobile/tabs/scene"===t.url||t instanceof n.NavigationEnd&&"/mobile/tabs/play-back"===t.url)&&i._run&&i.stopVideo()})),i._poster=localStorage.getItem(i.licensecam),i.randomId=Math.random().toString(36).substr(2,5),document.getElementById("vh-camera-mobile-canvas").id=i.randomId,i._play&&i.loadVideo()}))}return t.prototype.ngOnInit=function(){},t.prototype.ngOnChanges=function(t){this._play=this.play,null!=this._run&&(this._play?this._run||this.startVideo():this._run&&this.stopVideo())},t.prototype.ngOnDestroy=function(){this._run&&this.stopVideo(),console.log("destroyed camera")},t.prototype.loadVideo=function(){console.log("loadVideo on mobile"),this.config={channelid:this.licensecam,channelname:this.licensecam,url:this.url,monitor:this.monitor,os:this.os},this._play?this.startVideo():this._run=!1},t.prototype.startVideo=function(){this.config.monitor=this.monitor;var t="?channelid="+this.config.channelid+"&channelname="+this.config.channelname+"&url="+this.config.url+"&monitor="+this.config.monitor+"&os="+this.config.os,e=document.getElementById(this.randomId);this.player=new JSMpeg.Player(this.camliveURL+t,{canvas:e}),this._run=!0,console.log("startVideo on mobile")},t.prototype.stopVideo=function(){this._run=!1,this.player.destroy(),console.log("stopVideo on mobile")},t.prototype.getScreenshot=function(){var t=document.getElementById(this.randomId),e=document.createElement("canvas");(null==t?void 0:t.videoWidth)>=1280?(e.width=t.videoWidth/4,e.height=t.videoHeight/4):(null==t?void 0:t.videoWidth)<1280&&(e.width=t.videoWidth/2,e.height=t.videoHeight/2),e.getContext("2d").drawImage(t,0,0,e.width,e.height);var n=e.toDataURL();localStorage.setItem(this.licensecam,n)},t}();N.decorators=[{type:e.Component,args:[{selector:"vh-camera-jsmpegc",template:' \n <canvas id="vh-camera-mobile-canvas">\n </canvas> \n '}]}],N.ctorParameters=function(){return[{type:d.Platform},{type:n.Router}]},N.propDecorators={url:[{type:e.Input,args:["url"]}],licensecam:[{type:e.Input}],camliveURL:[{type:e.Input}],poster:[{type:e.Input}],roomid:[{type:e.Input}],width:[{type:e.Input}],height:[{type:e.Input}],play:[{type:e.Input}],monitor:[{type:e.Input}],os:[{type:e.Input}],change:[{type:e.Output}]};var R=function(){function t(t,o){var i=this;this.platform=t,this.router=o,this.url="",this.licensecam="",this.camliveURL="",this.poster="",this.roomid="",this.play=!0,this.monitor=1,this.os="ios",this.change=new e.EventEmitter,this.list_camera=[],this._src="",this._run=void 0,this._autoplay=!1,this._play=!0,this._poster="",this.randomId="",t.ready().then((function(){i.router.events.subscribe((function(t){(t instanceof n.NavigationEnd&&"/mobile/tabs/settings"===t.url||t instanceof n.NavigationEnd&&"/mobile/tabs/scripts"===t.url||t instanceof n.NavigationEnd&&"/mobile/tabs/scene"===t.url||t instanceof n.NavigationEnd&&"/mobile/tabs/play-back"===t.url)&&i._run&&i.stopVideo()})),i._poster=localStorage.getItem(i.licensecam),i._play&&i.loadVideo()}))}return t.prototype.ngOnInit=function(){},t.prototype.ngOnChanges=function(t){this._play=this.play,null!=this._run&&(this._play?this._run||this.startVideo():this._run&&this.stopVideo())},t.prototype.ngOnDestroy=function(){this._run&&this.stopVideo(),console.log("destroyed camera")},t.prototype.loadVideo=function(){console.log("loadVideo"),this.config={channelid:this.licensecam,channelname:this.licensecam,url:this.url,monitor:this.monitor,os:this.os},this._play?this.startVideo():(this._run=!1,this.change.emit({status:"loaded"}))},t.prototype.startVideo=function(){this.change.emit({status:"play"});var t=this;this.socket=new l.Socket({url:this.camliveURL}),this.socket.emit("start",JSON.stringify(this.config)),this.socket.on("segment-ios",(function(e){e&&(t._src="data:image/jpeg;base64,"+e),console.log("channelid:",t.config.channelid)})),this._run=!0,console.log("startVideo ios")},t.prototype.stopVideo=function(){this._run=!1,this.change.emit({status:"stop"}),this.socket.disconnect(),this.socket.removeAllListeners(),console.log("stopVideo")},t.prototype.getScreenshot=function(){var t=document.getElementById(this.randomId),e=document.createElement("canvas");(null==t?void 0:t.videoWidth)>=1280?(e.width=t.videoWidth/4,e.height=t.videoHeight/4):(null==t?void 0:t.videoWidth)<1280&&(e.width=t.videoWidth/2,e.height=t.videoHeight/2),e.getContext("2d").drawImage(t,0,0,e.width,e.height);var n=e.toDataURL();localStorage.setItem(this.licensecam,n)},t}();R.decorators=[{type:e.Component,args:[{selector:"vh-camera-img",template:"\n <img src={{_src}}> \n "}]}],R.ctorParameters=function(){return[{type:d.Platform},{type:n.Router}]},R.propDecorators={url:[{type:e.Input,args:["url"]}],licensecam:[{type:e.Input}],camliveURL:[{type:e.Input}],poster:[{type:e.Input}],roomid:[{type:e.Input}],width:[{type:e.Input}],height:[{type:e.Input}],play:[{type:e.Input}],monitor:[{type:e.Input}],os:[{type:e.Input}],change:[{type:e.Output}]};var U=function(){function t(t,e,n,o){this.vhmongo_firebase=t,this.imagePicker=e,this.webview=n,this.camera=o}return t.prototype.getThumbnailFromCamera=function(t,e,n,o){var i=this;return console.log("oldthumbnailURL",o),new Promise((function(a,s){var r={quality:100,destinationType:i.camera.DestinationType.FILE_URI,encodingType:i.camera.EncodingType.JPEG,mediaType:i.camera.MediaType.PICTURE};i.camera.getPicture(r).then((function(r){null==o||(null==o?void 0:o.length)<30||i.deleteThumbnail([o]).then((function(t){}),(function(t){console.log("Lỗi này chỉ xảy ra khi đường link hình ko tồn tại trong storage firebase, hoặc hàm deleteThumbnail bị lỗi")})),i.uploadThumbnailToImageServer(r,t,e,n).then((function(t){a(t)}),(function(t){s(t)}))}),(function(t){s(t)}))}))},t.prototype.getThumbnailFromAlbum=function(t,e,n,o){var i=this;return console.log("oldthumbnailURL",o),new Promise((function(a,s){i.imagePicker.hasReadPermission().then((function(r){r?i.imagePicker.getPictures({maximumImagesCount:1}).then((function(r){r.length>0?(null==o||(null==o?void 0:o.length)<30||i.deleteThumbnail([o]).then((function(t){}),(function(t){console.log("Lỗi này chỉ xảy ra khi đường link hình ko tồn tại trong storage firebase, hoặc hàm deleteThumbnail bị lỗi")})),i.uploadThumbnailToImageServer(r[0],t,e,n).then((function(t){a(t)}),(function(t){s(t)}))):s({message:"cancel"})}),(function(t){s(t)})):(i.imagePicker.requestReadPermission(),s({message:"cancel"}))}),(function(t){s(t)}))}))},t.prototype.getThumbnailFromDesktop=function(t,e,n,o,i){var a=this;return new Promise((function(s,r){if(console.log("oldthumbnailURL",i),null!=t){null==i||(null==i?void 0:i.length)<30||a.deleteThumbnail([i]).then((function(t){}),(function(t){console.log("link hình muốn xóa, ko tồn tại trên imageserver")}));var l=new FileReader;l.addEventListener("load",(function(t){var i=Math.random().toString(36).substr(2,5);a.uploadThumbnail(t.target.result,e,n,i,o).then((function(t){s(t)}),(function(t){r(t)}))})),l.readAsDataURL(t)}else r({})}))},t.prototype.uploadThumbnailToImageServer=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=i.webview.convertFileSrc(t),l=Math.random().toString(36).substr(2,5);i.uploadThumbnail(r,e,n,l,o).then((function(t){a(t)}),(function(t){s(t)}))}))},t.prototype.uploadThumbnail=function(t,e,n,o,i){var a=this;return new Promise((function(s,r){var l=a.vhmongo_firebase.auth().getDatabase(),c=a;a.encodeThumbnailUri(t,e,n,(function(t){c.vhmongo_firebase.image().uploadBase64Image(t,o,l,i).then((function(t){s(t)})).catch((function(t){r(t)}))}))}))},t.prototype.encodeThumbnailUri=function(t,e,n,o){var i=document.createElement("canvas"),a=i.getContext("2d"),s=new Image;s.onload=function(){i.width=e,i.height=n,a.drawImage(s,0,0,e,n);var t=i.toDataURL("image/jpeg");o(t)},s.src=t},t.prototype.deleteThumbnail=function(t){var e=this;return new Promise((function(n,o){for(var i=e,a=new Array,s=0;s<t.length;s++)a[s]=i.vhmongo_firebase.image().deleteImage(t[s]).then((function(t){n(!0)}),(function(t){n(!1)})).catch((function(t){n(!1)}));Promise.all(a).then((function(t){for(var e=0;t.length;e++)if(!t[e])return n(t[e]);n(!0)}))}))},t}();U.decorators=[{type:e.Injectable}],U.ctorParameters=function(){return[{type:o.Vhmongo_firebase},{type:i.ImagePicker},{type:a.WebView},{type:s.Camera}]};var V=function(){function t(t){this.vhmongo_firebase=t}return t.prototype.listener=function(t,e){var n=this;return c.Observable.create((function(o){n.vhmongo_firebase.database().listener(t,e).subscribe((function(t){o.next(t)}))}))},t.prototype.addDoc=function(t,e){var n=this;return new Promise((function(o,i){return"vhbill_details"===t||"printers"===t||"vhpermissions"===t||"vhemployees"===t||"branchs"===t||"appsettingstations"===t?o(null):void n.vhmongo_firebase.database().addDoc(t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.addDocbyID=function(t,e,n){var o=this;return new Promise((function(i,a){return"vhbill_details"===t||"printers"===t||"vhpermissions"===t||"vhemployees"===t||"branchs"===t||"appsettingstations"===t?i(null):void o.vhmongo_firebase.database().addDocbyID(t,e,n).then((function(t){i(t)}),(function(t){a(t)}))}))},t.prototype.updateDoc=function(t,e,n){var o=this;return new Promise((function(i,a){return"vhbill_details"===t||"printers"===t||"vhpermissions"===t||"vhemployees"===t||"branchs"===t||"appsettingstations"===t?i(!1):void o.vhmongo_firebase.database().updateDoc(t,e,n).then((function(t){i(t)}),(function(t){a(t)}))}))},t.prototype.deleteDoc=function(t,e){var n=this;return new Promise((function(o,i){return"vhbill_details"===t||"printers"===t||"vhpermissions"===t||"vhemployees"===t||"branchs"===t||"appsettingstations"===t?o(!1):void n.vhmongo_firebase.database().deleteDoc(t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.getDoc=function(t,e){var n=this;return new Promise((function(o,i){return"vhbill_details"===t||"printers"===t||"vhpermissions"===t||"vhemployees"===t||"branchs"===t||"appsettingstations"===t?o(null):void n.vhmongo_firebase.database().getDoc(t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.getDocs=function(t){var e=this;return new Promise((function(n){return"vhbill_details"===t||"printers"===t||"vhpermissions"===t||"vhemployees"===t||"branchs"===t||"appsettingstations"===t?n([]):void e.vhmongo_firebase.database().getDocs(t).then((function(t){n(t)}))}))},t.prototype.getDocsByFields=function(t,e,n,o,i){var a=this;return new Promise((function(s){return"vhbill_details"===t||"printers"===t||"vhpermissions"===t||"vhemployees"===t||"branchs"===t||"appsettingstations"===t?s([]):void a.vhmongo_firebase.database().getDocsByFields(t,e,n,o,i).then((function(t){s(t)}))}))},t.prototype.asyncPromiseAll=function(t){return new Promise((function(e,n){Promise.all(t).then((function(t){e(t)})).catch((function(t){n(t)}))}))},t}();V.decorators=[{type:e.Injectable}],V.ctorParameters=function(){return[{type:o.Vhmongo_firebase}]};var W=function(){function t(t,e,n,o){var i=this;this.vhmongo_firebase=t,this.vhQuery=e,this.vhAuth=n,this.vhAlgorithm=o,this.restriction_main_package=null,this.areas=new Array,this.tables=new Array,this.products=new Array,this.customers=new Array,this.suppliers=new Array,this.wallets=new Array,this.taxs=new Array,this.categorys=new Array,this.inventorytimes=new Array,this.deliverys=new Array,this.addresss=new Array,this.incoming_groups=new Array,this.spending_groups=new Array,this.branchs=new Array,this.promotions=new Array,this.patternmenus=new Array,this.printers=new Array,this.discount_bills=new Array,this.discount_saless=new Array,this.customer_classs=new Array,this.commissions=new Array,this.hwinfo={},this.appsettingstations=new Array,this.appsettingbranchs=new Array,this.kitchendispatcherlist=new Array,this.servicedispatcherlist=new Array,this.warehousedispatcherlist=new Array,this.subjectwallets=new c.Subject,this.subjectappsettingstations=new c.Subject,this.subjectappsettingbranchs=new c.Subject,this.subjectbranchs=new c.Subject,this.subjectcategorys=new c.Subject,this.subjectcustomers=new c.Subject,this.subjectinventorytimes=new c.Subject,this.subjectprinters=new c.Subject,this.subjectproducts=new c.Subject,this.subjectpromotions=new c.Subject,this.subjectsuppliers=new c.Subject,this.subjecttaxs=new c.Subject,this.subjectareas=new c.Subject,this.subjecttables=new c.Subject,this.subjectdiscount_bills=new c.Subject,this.subjectcustomer_classs=new c.Subject,this.sync_code=Math.random().toString(36).substr(2,10).toUpperCase(),r.Device.getId().then((function(t){var e=i.vhAuth.localStorageGET("hwinfo");null!=e&&null!=e?i.hwinfo=e:(i.hwinfo=Object.assign({},t),i.vhAuth.localStorageSET("hwinfo",i.hwinfo))}))}return t.prototype.refreshLocalRestrictionMainPackage=function(){var t=this;return new Promise((function(e,n){var o=t.getDefaultBranch()._id,i=t.vhAuth.getStore()[o].main_package_expire.id_restriction;t.vhmongo_firebase.rootdatabase().getDoc("restrictions",i).then((function(n){n&&(t.restriction_main_package=Object.assign(Object.assign({},n),t.vhAuth.getStore()[o].main_package_expire),delete t.restriction_main_package.id_restriction,delete t.restriction_main_package._id,console.log("restriction_main_package",t.restriction_main_package)),e(null)}),(function(t){n(t)}))}))},t.prototype.getLocalRestrictionMainPackage=function(){return this.restriction_main_package},t.prototype.syncCollections_Mobile=function(){var t=this;return new Promise((function(e,n){t.initSyncCollections(),t.callbackCollectionInsert().subscribe(),t.callbackCollectionUpdate().subscribe(),t.callbackCollectionDelete().subscribe(),setTimeout((function(){t.checkExpireBranch_Cafe(),e(!0)}),3e3)}))},t.prototype.syncCollections_Desktop=function(){var t=this;return new Promise((function(e,n){t.initSyncCollections(),t.callbackCollectionInsert().subscribe(),t.callbackCollectionUpdate().subscribe(),t.callbackCollectionDelete().subscribe(),setTimeout((function(){t.syncCashBookEveryDay_Stock1stDayOfMonth().then((function(){t.syncInventoryEveryDay_Stock1stDayOfMonth().then((function(){e(!0)}))})),t.checkExpireBranch_Cafe()}),3e3)}))},t.prototype.checkExpireBranch_Cafe=function(){if(this.getDefaultBranch()){var t=this.getDefaultBranch()._id;this.vhmongo_firebase.auth().checkExpireBranch_Cafe(t).then((function(){console.log("success checkExpireBranch_Cafe")}),(function(t){console.log("no success checkExpireBranch_Cafe")}))}},t.prototype.initSyncCollections=function(){this.categorys=new Array,this.products=new Array,this.suppliers=new Array,this.customers=new Array,this.wallets=new Array,this.areas=new Array,this.tables=new Array,this.branchs=new Array,this.taxs=new Array,this.promotions=new Array,this.inventorytimes=new Array,this.appsettingbranchs=new Array,this.appsettingstations=new Array,this.printers=new Array,this.vhAuth.clearLocalEmployeeFromSyncCollection();var t=new Array;return t[0]="categorys",t[1]="printers",t[2]="suppliers",t[3]="customers",t[4]="wallets",t[5]="areas",t[6]="tables",t[7]="branchs",t[8]="taxs",t[9]="vhemployees",t[10]="promotions",t[11]="inventorytimes",t[12]="appsettingstations",t[13]="appsettingbranchs",t[14]="products",t[15]="discount_bills",t[16]="customer_classs",this.vhmongo_firebase.socketMongoDB().initSyncCollections(t)},t.prototype.closeSyncCollections=function(){this.vhmongo_firebase.socketMongoDB().closeSyncCollections()},t.prototype.callbackCollectionInsert=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackCollectionInsert().subscribe((function(n){if("vhemployees"===n.colname?n.colname="employees":"branchs"===n.colname?n.colname="branchs":"printers"===n.colname?n.colname="printers":"appsettingstations"===n.colname&&(n.colname="appsettingstations"),"categorys"===n.colname)t.getlocalCategory(n._id)||((o=Object.assign({},n.data))._id=n._id,t.categorys.push(o),t.publishObservableEventCategorys(),e.next(n.colname));else if("products"===n.colname){if(!t.getlocalProduct(n._id))(o=Object.assign({},n.data))._id=n._id,t.products.push(o),t.publishObservableEventProducts(),e.next(n.colname)}else if("suppliers"===n.colname){if(!t.getlocalSupplier(n._id))(o=Object.assign({},n.data))._id=n._id,t.suppliers.push(o),t.publishObservableEventSuppliers(),e.next(n.colname)}else if("customers"===n.colname){if(!t.getlocalCustomer(n._id))(o=Object.assign({},n.data))._id=n._id,t.customers.push(o),t.publishObservableEventCustomers(),e.next(n.colname)}else if("wallets"===n.colname){if(!t.getlocalWallet(n._id))(o=Object.assign({},n.data))._id=n._id,t.wallets.push(o),t.publishObservableEventWallets(),e.next(n.colname)}else if("areas"===n.colname){if(!t.getlocalArea(n._id))(o=Object.assign({},n.data))._id=n._id,t.areas.push(o),t.publishObservableEventAreas(),e.next(n.colname)}else if("tables"===n.colname){if(!t.getlocalTable(n._id))(o=Object.assign({},n.data))._id=n._id,t.tables.push(o),t.publishObservableEventTables(),e.next(n.colname)}else if("branchs"===n.colname){if(!t.getlocalBranch(n._id))(o=Object.assign({},n.data))._id=n._id,t.branchs.push(o),t.publishObservableEventBranchs(),e.next(n.colname)}else if("taxs"===n.colname){if(!t.getlocalTax(n._id))(o=Object.assign({},n.data))._id=n._id,t.taxs.push(o),t.publishObservableEventTaxs(),e.next(n.colname)}else if("employees"===n.colname){(o=Object.assign({},n.data))._id=n._id,t.vhAuth.insertlocalEmployeeFromSyncCollection(o),t.vhAuth.publishObservableEventEmployees(),e.next(n.colname)}else if("promotions"===n.colname){if(!t.getlocalPromotion(n._id))(o=Object.assign({},n.data))._id=n._id,t.promotions.push(o),t.publishObservableEventPromotions(),e.next(n.colname)}else if("inventorytimes"===n.colname){if(!t.getlocalInventorytime(n._id))(o=Object.assign({},n.data))._id=n._id,t.inventorytimes.push(o),t.publishObservableEventInventorytimes(),e.next(n.colname)}else if("appsettingbranchs"===n.colname){if(!t.getLocalAppSettingBranch(n._id))if(n.data.id_branch===t.getDefaultBranch()._id)(o=Object.assign({},n.data))._id=n._id,delete o.id_branch,t.appsettingbranchs.push(o),t.publishObservableEventAppSettingNameBranchs(),e.next(n.colname)}else if("appsettingstations"===n.colname){if(!t.getLocalAppSettingStation(n._id))if(n.data.uuid===t.hwinfo.uuid)(o=Object.assign({},n.data))._id=n._id,delete o.uuid,t.appsettingstations.push(o),t.publishObservableEventAppSettingNameStations(),e.next(n.colname)}else if("printers"===n.colname){if(!t.getlocalPrinter(n._id))if(n.data.uuid===t.hwinfo.uuid)(o=Object.assign({},n.data))._id=n._id,delete o.uuid,t.printers.push(o),t.publishObservableEventPrinters(),e.next(n.colname)}else if("discount_bills"===n.colname){if(!t.getlocalDiscount_bill(n._id))(o=Object.assign({},n.data))._id=n._id,t.discount_bills.push(o),t.publishObservableEventDiscount_bills(),e.next(n.colname)}else if("customer_classs"===n.colname){var o;if(!t.getlocalCustomerClass(n._id))(o=Object.assign({},n.data))._id=n._id,t.customer_classs.push(o),t.publishObservableEventCustomerClasss(),e.next(n.colname)}console.log("inserted",n.colname)}))}))},t.prototype.callbackCollectionUpdate=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackCollectionUpdate().subscribe((function(n){if("vhemployees"===n.colname&&(n.colname="employees"),"categorys"===n.colname){for(var o=0;o<t.categorys.length;o++)if(t.categorys[o]._id===n._id){t.categorys[o]=Object.assign(Object.assign({},t.categorys[o]),n.data),t.publishObservableEventCategorys(),e.next(n.colname);break}}else if("products"===n.colname){for(o=0;o<t.products.length;o++)if(t.products[o]._id===n._id){t.products[o]=Object.assign(Object.assign({},t.products[o]),n.data),t.publishObservableEventProducts(),e.next(n.colname);break}}else if("suppliers"===n.colname){for(o=0;o<t.suppliers.length;o++)if(t.suppliers[o]._id===n._id){t.suppliers[o]=Object.assign(Object.assign({},t.suppliers[o]),n.data),t.publishObservableEventSuppliers(),e.next(n.colname);break}}else if("customers"===n.colname){for(o=0;o<t.customers.length;o++)if(t.customers[o]._id===n._id){t.customers[o]=Object.assign(Object.assign({},t.customers[o]),n.data),t.publishObservableEventCustomers(),e.next(n.colname);break}e.next(n.colname)}else if("wallets"===n.colname){for(o=0;o<t.wallets.length;o++)if(t.wallets[o]._id===n._id){t.wallets[o]=Object.assign(Object.assign({},t.wallets[o]),n.data),t.publishObservableEventWallets(),e.next(n.colname);break}}else if("areas"===n.colname){for(o=0;o<t.areas.length;o++)if(t.areas[o]._id===n._id){t.areas[o]=Object.assign(Object.assign({},t.areas[o]),n.data),t.publishObservableEventAreas(),e.next(n.colname);break}}else if("tables"===n.colname){for(o=0;o<t.tables.length;o++)if(t.tables[o]._id===n._id){t.tables[o]=Object.assign(Object.assign({},t.tables[o]),n.data),t.publishObservableEventTables(),e.next(n.colname);break}}else if("branchs"===n.colname){for(o=0;o<t.branchs.length;o++)if(t.branchs[o]._id===n._id){t.branchs[o]=Object.assign(Object.assign({},t.branchs[o]),n.data),t.publishObservableEventBranchs(),e.next(n.colname);break}}else if("taxs"===n.colname){for(o=0;o<t.taxs.length;o++)if(t.taxs[o]._id===n._id){t.taxs[o]=Object.assign(Object.assign({},t.taxs[o]),n.data),t.publishObservableEventTaxs(),e.next(n.colname);break}}else if("employees"===n.colname)t.vhAuth.updateLocalEmployeeFromSyncCollection(n._id,n.data),t.vhAuth.publishObservableEventEmployees(),e.next(n.colname);else if("promotions"===n.colname){for(o=0;o<t.promotions.length;o++)if(t.promotions[o]._id===n._id){t.promotions[o]=Object.assign(Object.assign({},t.promotions[o]),n.data),t.publishObservableEventPromotions(),e.next(n.colname);break}}else if("inventorytimes"===n.colname){for(o=0;o<t.inventorytimes.length;o++)if(t.inventorytimes[o]._id===n._id){t.inventorytimes[o]=Object.assign(Object.assign({},t.inventorytimes[o]),n.data),t.publishObservableEventInventorytimes(),e.next(n.colname);break}}else if("appsettingbranchs"===n.colname){for(o=0;o<t.appsettingbranchs.length;o++)if(t.appsettingbranchs[o]._id===n._id){t.appsettingbranchs[o]=Object.assign(Object.assign({},t.appsettingbranchs[o]),n.data),t.publishObservableEventAppSettingNameBranchs(),e.next(n.colname);break}}else if("appsettingstations"===n.colname){for(o=0;o<t.appsettingstations.length;o++)if(t.appsettingstations[o]._id===n._id){t.appsettingstations[o]=Object.assign(Object.assign({},t.appsettingstations[o]),n.data),t.publishObservableEventAppSettingNameStations(),e.next(n.colname);break}}else if("printers"===n.colname){for(o=0;o<t.printers.length;o++)if(t.printers[o]._id===n._id){t.printers[o]=Object.assign(Object.assign({},t.printers[o]),n.data),t.publishObservableEventPrinters(),e.next(n.colname);break}}else if("discount_bills"===n.colname){for(o=0;o<t.discount_bills.length;o++)if(t.discount_bills[o]._id===n._id){t.discount_bills[o]=Object.assign(Object.assign({},t.discount_bills[o]),n.data),t.publishObservableEventDiscount_bills(),e.next(n.colname);break}}else if("customer_classs"===n.colname)for(o=0;o<t.customer_classs.length;o++)if(t.customer_classs[o]._id===n._id){t.customer_classs[o]=Object.assign(Object.assign({},t.customer_classs[o]),n.data),t.publishObservableEventCustomerClasss(),e.next(n.colname);break}console.log("updated",n.colname)}))}))},t.prototype.callbackCollectionDelete=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackCollectionDelete().subscribe((function(n){if("vhemployees"===n.colname&&(n.colname="employees"),"categorys"===n.colname){for(var o=0;o<t.categorys.length;o++)if(t.categorys[o]._id===n._id){t.categorys.splice(o,1),t.publishObservableEventCategorys(),e.next(n.colname);break}}else if("products"===n.colname){for(o=0;o<t.products.length;o++)if(t.products[o]._id===n._id){t.products.splice(o,1),t.publishObservableEventProducts(),e.next(n.colname);break}}else if("suppliers"===n.colname){for(o=0;o<t.suppliers.length;o++)if(t.suppliers[o]._id===n._id){t.suppliers.splice(o,1),t.publishObservableEventSuppliers(),e.next(n.colname);break}}else if("customers"===n.colname){for(o=0;o<t.customers.length;o++)if(t.customers[o]._id===n._id){t.customers.splice(o,1),t.publishObservableEventCustomers(),e.next(n.colname);break}}else if("wallets"===n.colname){for(o=0;o<t.wallets.length;o++)if(t.wallets[o]._id===n._id){t.wallets.splice(o,1),t.publishObservableEventWallets(),e.next(n.colname);break}}else if("areas"===n.colname){for(o=0;o<t.areas.length;o++)if(t.areas[o]._id===n._id){t.areas.splice(o,1),t.publishObservableEventAreas(),e.next(n.colname);break}}else if("tables"===n.colname){for(o=0;o<t.tables.length;o++)if(t.tables[o]._id===n._id){t.tables.splice(o,1),t.publishObservableEventTables(),e.next(n.colname);break}}else if("branchs"===n.colname){for(o=0;o<t.branchs.length;o++)if(t.branchs[o]._id===n._id){t.branchs.splice(o,1),t.publishObservableEventBranchs(),e.next(n.colname);break}}else if("taxs"===n.colname){for(o=0;o<t.taxs.length;o++)if(t.taxs[o]._id===n._id){t.taxs.splice(o,1),t.publishObservableEventTaxs(),e.next(n.colname);break}}else if("employees"===n.colname)t.vhAuth.deleteLocalEmployeeFromSyncCollection(n._id),t.vhAuth.publishObservableEventEmployees(),e.next(n.colname);else if("promotions"===n.colname){for(o=0;o<t.promotions.length;o++)if(t.promotions[o]._id===n._id){t.promotions.splice(o,1),t.publishObservableEventPromotions(),e.next(n.colname);break}}else if("inventorytimes"===n.colname){for(o=0;o<t.inventorytimes.length;o++)if(t.inventorytimes[o]._id===n._id){t.inventorytimes.splice(o,1),t.publishObservableEventInventorytimes(),e.next(n.colname);break}}else if("appsettingbranchs"===n.colname){for(o=0;o<t.appsettingbranchs.length;o++)if(t.appsettingbranchs[o]._id===n._id){t.appsettingbranchs.splice(o,1),t.publishObservableEventAppSettingNameBranchs(),e.next(n.colname);break}}else if("appsettingstations"===n.colname){for(o=0;o<t.appsettingstations.length;o++)if(t.appsettingstations[o]._id===n._id){t.appsettingstations.splice(o,1),t.publishObservableEventAppSettingNameStations(),e.next(n.colname);break}}else if("printers"===n.colname){for(o=0;o<t.printers.length;o++)if(t.printers[o]._id===n._id){t.printers.splice(o,1),t.publishObservableEventPrinters(),e.next(n.colname);break}}else if("discount_bills"===n.colname){for(o=0;o<t.discount_bills.length;o++)if(t.discount_bills[o]._id===n._id){t.discount_bills.splice(o,1),t.publishObservableEventDiscount_bills(),e.next(n.colname);break}}else if("customer_classs"===n.colname)for(o=0;o<t.customer_classs.length;o++)if(t.customer_classs[o]._id===n._id){t.customer_classs.splice(o,1),t.publishObservableEventCustomerClasss(),e.next(n.colname);break}console.log("deleted",n.colname)}))}))},t.prototype.initChatToAppCare=function(){return this.vhmongo_firebase.socketMongoDB().initChat("vhmessages",{})},t.prototype.listeningChatToAppCare_Insert=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackChatInsert().subscribe((function(t){e.next(t)}))}))},t.prototype.listeningChatToAppCare_Update=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackChatUpdate().subscribe((function(t){e.next(t)}))}))},t.prototype.getOldMessages=function(t){return this.vhmongo_firebase.database().getDocsByFields("vhmessages",{},{},{date:1},t)},t.prototype.sendMessageToAppCare=function(t){var e=this;return new Promise((function(n,o){var i={msg:t,date:new Date,avatar:e.getLocalAppSettingNameStation("store_info").img,email:e.getLocalAppSettingNameStation("store_info").email,company:e.getLocalAppSettingNameStation("store_info").company,align:"left"};e.vhmongo_firebase.database().addDoc("vhmessages",i).then((function(t){n(t)}),(function(t){o(t)})),e.vhmongo_firebase.socketMongoDB().saytoAppCareFirebase()}))},t.prototype.sendImageToAppCare=function(t){var e=this;return new Promise((function(n,o){var i={img:t,date:new Date,avatar:e.getLocalAppSettingNameStation("store_info").img,email:e.getLocalAppSettingNameStation("store_info").email,company:e.getLocalAppSettingNameStation("store_info").company,align:"left"};e.vhmongo_firebase.database().addDoc("vhmessages",i).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.startLocalStorage=function(){var t=this;return new Promise((function(e){var n=new Array;n[0]=t.vhAuth.refreshLocalMyPermission(),n[1]=t.refreshLocalDeliverys(),n[2]=t.refreshLocalAddresss(),t.vhQuery.asyncPromiseAll(n).then((function(){e(null)}))}))},t.prototype.observableDispatcher=function(t){var e=this;return new c.Observable((function(n){e.kitchendispatcherlist=new Array,e.servicedispatcherlist=new Array,e.warehousedispatcherlist=new Array,e.initDispatcher().then((function(o){o&&(e.callbackdispatcher=e.callbackDispatcher(t).subscribe((function(t){n.next(t)})))}))}))},t.prototype.initDispatcher=function(){var t=this.getDefaultBranch()._id;return this.vhmongo_firebase.socketMongoDB().initDispatcher("vhbill_details",t)},t.prototype.closeDispatcher=function(){this.callbackdispatcher.unsubscribe(),this.vhmongo_firebase.socketMongoDB().closeDispatcher()},t.prototype.doneDispatcher=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().updateDoc("vhbill_details",t,{done:!0}).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.callbackDispatcher=function(t){var e=this;this.getDefaultBranch()._id;return new c.Observable((function(n){e.listeningDispatcher_Insert().subscribe((function(o){1!==t||1!==o.ptype&&4!==o.ptype&&5!==o.ptype?2===t&&2===o.ptype?(e.servicedispatcherlist.push(o),e.refreshServiceDispatcherList().then((function(t){n.next(t)}))):3===t&&3===o.ptype&&(e.warehousedispatcherlist.push(o),e.refreshWarehouseDispatcherList().then((function(t){n.next(t)}))):(e.kitchendispatcherlist.push(o),e.refreshKitchenDispatcherList().then((function(t){n.next(t)})))}),(function(t){console.log(t)})),e.listeningDispatcher_Update().subscribe((function(t){for(var o,i,a,s=0;s<e.kitchendispatcherlist.length;s++)if(e.kitchendispatcherlist[s]._id===t._id){if(!0===(null===(o=t.value)||void 0===o?void 0:o.done))e.kitchendispatcherlist.splice(s,1);else for(var r in t.value)e.kitchendispatcherlist[s][r]=t.value[r];e.refreshKitchenDispatcherList().then((function(t){n.next(t)}));break}for(s=0;s<e.servicedispatcherlist.length;s++)if(e.servicedispatcherlist[s]._id===t._id){if(!0===(null===(i=t.value)||void 0===i?void 0:i.done))e.servicedispatcherlist.splice(s,1);else for(var r in t.value)e.servicedispatcherlist[s][r]=t.value[r];e.refreshServiceDispatcherList().then((function(t){n.next(t)}));break}for(s=0;s<e.warehousedispatcherlist.length;s++)if(e.warehousedispatcherlist[s]._id===t._id){if(!0===(null===(a=t.value)||void 0===a?void 0:a.done))e.warehousedispatcherlist.splice(s,1);else for(var r in t.value)e.warehousedispatcherlist[s][r]=t.value[r];e.refreshWarehouseDispatcherList().then((function(t){n.next(t)}));break}})),e.listeningDispatcher_Delete().subscribe((function(t){for(var o=0;o<e.kitchendispatcherlist.length;o++)if(e.kitchendispatcherlist[o]._id===t._id){e.kitchendispatcherlist.splice(o,1),e.refreshKitchenDispatcherList().then((function(t){n.next(t)}));break}for(o=0;o<e.servicedispatcherlist.length;o++)if(e.servicedispatcherlist[o]._id===t._id){e.servicedispatcherlist.splice(o,1),e.refreshServiceDispatcherList().then((function(t){n.next(t)}));break}for(o=0;o<e.warehousedispatcherlist.length;o++)if(e.warehousedispatcherlist[o]._id===t._id){e.warehousedispatcherlist.splice(o,1),e.refreshWarehouseDispatcherList().then((function(t){n.next(t)}));break}}))}))},t.prototype.listeningDispatcher_Insert=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackDispatcherInsert().subscribe((function(t){e.next(t)}))}))},t.prototype.listeningDispatcher_Update=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackDispatcherUpdate().subscribe((function(t){e.next(t)}))}))},t.prototype.listeningDispatcher_Delete=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackDispatcherDelete().subscribe((function(t){e.next(t)}))}))},t.prototype.refreshKitchenDispatcherList=function(){var t=this;return new Promise((function(e,n){var o,i,a,s,r,l,c={bills_takeaway:new Array,bills_table:new Array,products:new Array},u=t.kitchendispatcherlist;if(u.length>0){for(var d=t.getlocalProducts(145),_=0;_<d.length;_++)if(null===(o=d[_])||void 0===o||delete o.allow_sell,null===(i=d[_])||void 0===i||delete i.describe,null===(a=d[_])||void 0===a||delete a.id_category,null===(s=d[_])||void 0===s||delete s.toppings,null===(r=d[_])||void 0===r||delete r.combos,d[_].late_warning=!1,d[_].quantity=0,d[_].bill_details=new Array,null!=d[_].subs)for(var p=0;p<d[_].subs.length;p++)null===(l=d[_].subs[p])||void 0===l||delete l.active,delete d[_].subs[p].price,d[_].subs[p].late_warning=!1,d[_].subs[p].quantity=0,d[_].subs[p].bill_details=new Array;var b=new Array,f=new Array;for(_=0;_<u.length;_++){var h=!1;for(p=0;p<b.length;p++)if(u[_].id_bill===b[p].id_bill){h=!0;break}if(!h&&"go_home"!=u[_].id_table){var y=t.getlocalTable(u[_].id_table),m={id_bill:u[_].id_bill,id_table:u[_].id_table,table_name:y.name,quantity:0,orders:0,bill_details:new Array,late_warning:!1};b.push(m)}}for(_=0;_<u.length;_++){for(h=!1,p=0;p<f.length;p++)if(u[_].id_bill===f[p].id_bill){h=!0;break}if(!h&&"go_home"===u[_].id_table){m={id_bill:u[_].id_bill,bill_code:u[_].bill_code,table_name:"Take away",quantity:0,orders:0,bill_details:new Array,late_warning:!1};f.push(m)}}for(_=0;_<u.length;_++){m=Object.assign({},u[_]),y=t.getlocalTable(u[_].id_table);if(m.late_warning=!1,m.table_name=y.name,m._id=u[_]._id,null==m||delete m.date,null==m||delete m.tax,null==m||delete m.bill_type,null==m||delete m.id_cashier,null==m||delete m.id_employee,null==m||delete m.id_supplier,delete m.id_customer,delete m.id_branch,delete m.id_category,null==m||delete m.done,null==m||delete m.price,null!=m.toppings)for(p=0;p<m.toppings.length;p++)m.toppings[p].name=t.getlocalProduct(m.toppings[p].id_product).name;if(null!=m.combos)for(p=0;p<m.combos.length;p++)m.combos[p].name=t.getlocalProduct(m.combos[p].id_product).name;var v=(new Date).getTime()-new Date(m.date_order).getTime();(v=Math.floor(v/6e4))>t.getlocalProduct(m.id_product).time_warning?m.late_warning=!0:m.late_warning=!1;for(p=0;p<b.length;p++)b[p].id_bill===m.id_bill&&(b[p].orders++,b[p].quantity=b[p].quantity+m.quantity,v>t.getlocalProduct(m.id_product).time_warning&&(b[p].late_warning=!0),b[p].bill_details.push(m));for(p=0;p<f.length;p++)f[p].id_bill===m.id_bill&&(f[p].orders++,f[p].quantity=f[p].quantity+m.quantity,v>t.getlocalProduct(m.id_product).time_warning&&(f[p].late_warning=!0),f[p].bill_details.push(m));for(p=0;p<d.length;p++)if(v>d[p].time_warning&&(d[p].late_warning=!0),d[p]._id===m.id_product){if(d[p].quantity=d[p].quantity+m.quantity,null!=d[p].subs)for(var g=0;g<d[p].subs.length;g++)d[p].subs[g]._id===m.id_subproduct&&(d[p].subs[g].quantity=d[p].subs[g].quantity+m.quantity,v>d[p].time_warning&&(d[p].subs[g].late_warning=!0),d[p].subs[g].bill_details.push(m));d[p].bill_details.push(m)}}d=d.filter((function(t){return t.quantity>0}));for(_=0;_<d.length;_++)if(null!=d[_].subs){var x=d[_].subs.filter((function(t){return t.quantity>0}));delete d[_].subs,d[_].subs=x}b.length>0&&(c.bills_table=b),f.length>0&&(c.bills_takeaway=f),d.length>0&&(c.products=d)}e(c)}))},t.prototype.getKitchenDispatcherList=function(t){var e=new Date;return e.setDate(e.getDate()-1),e.setHours(0),e.setMinutes(0),e.setSeconds(0),e.setMilliseconds(0),this.vhmongo_firebase.database().getDocsByFields("vhbill_details",{id_branch:{$eq:t},done:{$eq:!1},bill_type:{$in:[1,5]},ptype:{$eq:1},date_order:{$gte:e}},{},{date_order:1},0)},t.prototype.refreshWarehouseDispatcherList=function(){var t=this;return new Promise((function(e,n){var o,i,a,s,r,l={bills_takeaway:new Array,bills_table:new Array,products:new Array},c=t.warehousedispatcherlist;if(c.length>0){for(var u=t.getlocalProducts(3),d=0;d<u.length;d++)if(null===(o=u[d])||void 0===o||delete o.allow_sell,null===(i=u[d])||void 0===i||delete i.describe,null===(a=u[d])||void 0===a||delete a.id_category,u[d].late_warning=!1,u[d].quantity=0,u[d].bill_details=new Array,null!=u[d].subs)for(var _=0;_<u[d].subs.length;_++)null===(s=u[d].subs[_])||void 0===s||delete s.active,null===(r=u[d].subs[_])||void 0===r||delete r.price,u[d].subs[_].late_warning=!1,u[d].subs[_].quantity=0,u[d].subs[_].bill_details=new Array;var p=new Array,b=new Array;for(d=0;d<c.length;d++){var f=!1;for(_=0;_<p.length;_++)if(c[d].id_bill===p[_].id_bill){f=!0;break}if(!f&&"go_home"!=c[d].id_table){var h=t.getlocalTable(c[d].id_table),y={id_bill:c[d].id_bill,id_table:c[d].id_table,table_name:h.name,quantity:0,orders:0,bill_details:new Array,late_warning:!1};p.push(y)}}for(d=0;d<c.length;d++){for(f=!1,_=0;_<b.length;_++)if(c[d].id_bill===b[_].id_bill){f=!0;break}if(!f&&"go_home"===c[d].id_table){y={id_bill:c[d].id_bill,bill_code:c[d].bill_code,table_name:"Take away",quantity:0,orders:0,bill_details:new Array,late_warning:!1};b.push(y)}}for(d=0;d<c.length;d++){y=Object.assign({},c[d]),h=t.getlocalTable(c[d].id_table);y.late_warning=!1,y.table_name=h.name,y._id=c[d]._id,null==y||delete y.date,null==y||delete y.tax,null==y||delete y.bill_type,null==y||delete y.id_cashier,null==y||delete y.id_employee,null==y||delete y.id_supplier,delete y.id_customer,delete y.id_branch,delete y.id_category,null==y||delete y.done,null==y||delete y.price;var m=(new Date).getTime()-new Date(y.date_order).getTime();(m=Math.floor(m/6e4))>t.getlocalProduct(y.id_product).time_warning?y.late_warning=!0:y.late_warning=!1;for(_=0;_<p.length;_++)p[_].id_bill===y.id_bill&&(p[_].orders++,p[_].quantity=p[_].quantity+y.quantity,m>t.getlocalProduct(y.id_product).time_warning&&(p[_].late_warning=!0),p[_].bill_details.push(y));for(_=0;_<b.length;_++)b[_].id_bill===y.id_bill&&(b[_].orders++,b[_].quantity=b[_].quantity+y.quantity,m>t.getlocalProduct(y.id_product).time_warning&&(b[_].late_warning=!0),b[_].bill_details.push(y));for(_=0;_<u.length;_++)if(m>u[_].time_warning&&(u[_].late_warning=!0),u[_]._id===y.id_product){if(u[_].quantity=u[_].quantity+y.quantity,null!=u[_].subs)for(var v=0;v<u[_].subs.length;v++)u[_].subs[v]._id===y.id_subproduct&&(u[_].subs[v].quantity=u[_].subs[v].quantity+y.quantity,m>u[_].time_warning&&(u[_].subs[v].late_warning=!0),u[_].subs[v].bill_details.push(y));u[_].bill_details.push(y)}}u=u.filter((function(t){return t.quantity>0}));for(d=0;d<u.length;d++)if(null!=u[d].subs){var g=u[d].subs.filter((function(t){return t.quantity>0}));delete u[d].subs,u[d].subs=g}p.length>0&&(l.bills_table=p),b.length>0&&(l.bills_takeaway=b),u.length>0&&(l.products=u)}e(l)}))},t.prototype.getWarehouseDispatcherList=function(t){var e=new Date;return e.setDate(e.getDate()-1),e.setHours(0),e.setMinutes(0),e.setSeconds(0),e.setMilliseconds(0),this.vhmongo_firebase.database().getDocsByFields("vhbill_details",{id_branch:{$eq:t},done:{$eq:!1},bill_type:{$in:[1,5]},ptype:{$eq:3},date_order:{$gte:e}},{},{date_order:1},0)},t.prototype.refreshServiceDispatcherList=function(){var t=this;return new Promise((function(e,n){var o,i,a,s,r,l={bills_takeaway:new Array,bills_table:new Array,products:new Array},c=t.servicedispatcherlist;if(c.length>0){for(var u=t.getlocalProducts(2),d=0;d<u.length;d++)if(null===(o=u[d])||void 0===o||delete o.allow_sell,null===(i=u[d])||void 0===i||delete i.describe,null===(a=u[d])||void 0===a||delete a.id_category,u[d].late_warning=!1,u[d].quantity=0,u[d].bill_details=new Array,null!=u[d].subs)for(var _=0;_<u[d].subs.length;_++)null===(s=u[d].subs[_])||void 0===s||delete s.active,null===(r=u[d].subs[_])||void 0===r||delete r.price,u[d].subs[_].late_warning=!1,u[d].subs[_].quantity=0,u[d].subs[_].bill_details=new Array;var p=new Array,b=new Array;for(d=0;d<c.length;d++){var f=!1;for(_=0;_<p.length;_++)if(c[d].id_bill===p[_].id_bill){f=!0;break}if(!f&&"go_home"!=c[d].id_table){var h=t.getlocalTable(c[d].id_table),y={id_bill:c[d].id_bill,id_table:c[d].id_table,table_name:h.name,quantity:0,orders:0,bill_details:new Array,late_warning:!1};p.push(y)}}for(d=0;d<c.length;d++){for(f=!1,_=0;_<b.length;_++)if(c[d].id_bill===b[_].id_bill){f=!0;break}if(!f&&"go_home"===c[d].id_table){y={id_bill:c[d].id_bill,bill_code:c[d].bill_code,table_name:"Take away",quantity:0,orders:0,bill_details:new Array,late_warning:!1};b.push(y)}}for(d=0;d<c.length;d++){y=Object.assign({},c[d]),h=t.getlocalTable(c[d].id_table);y.late_warning=!1,y.table_name=h.name,y._id=c[d]._id,null==y||delete y.date,null==y||delete y.tax,null==y||delete y.bill_type,null==y||delete y.id_cashier,null==y||delete y.id_employee,null==y||delete y.id_supplier,delete y.id_customer,delete y.id_branch,delete y.id_category,null==y||delete y.done,null==y||delete y.price;var m=(new Date).getTime()-new Date(y.date_order).getTime();(m=Math.floor(m/6e4))>t.getlocalProduct(y.id_product).time_warning?y.late_warning=!0:y.late_warning=!1;for(_=0;_<p.length;_++)p[_].id_bill===y.id_bill&&(p[_].orders++,p[_].quantity=p[_].quantity+y.quantity,m>t.getlocalProduct(y.id_product).time_warning&&(p[_].late_warning=!0),p[_].bill_details.push(y));for(_=0;_<b.length;_++)b[_].id_bill===y.id_bill&&(b[_].orders++,b[_].quantity=b[_].quantity+y.quantity,m>t.getlocalProduct(y.id_product).time_warning&&(b[_].late_warning=!0),b[_].bill_details.push(y));for(_=0;_<u.length;_++)if(m>u[_].time_warning&&(u[_].late_warning=!0),u[_]._id===y.id_product){if(u[_].quantity=u[_].quantity+y.quantity,null!=u[_].subs)for(var v=0;v<u[_].subs.length;v++)u[_].subs[v]._id===y.id_subproduct&&(u[_].subs[v].quantity=u[_].subs[v].quantity+y.quantity,m>u[_].time_warning&&(u[_].subs[v].late_warning=!0),u[_].subs[v].bill_details.push(y));u[_].bill_details.push(y)}}u=u.filter((function(t){return t.quantity>0}));for(d=0;d<u.length;d++)if(null!=u[d].subs){var g=u[d].subs.filter((function(t){return t.quantity>0}));delete u[d].subs,u[d].subs=g}p.length>0&&(l.bills_table=p),b.length>0&&(l.bills_takeaway=b),u.length>0&&(l.products=u)}e(l)}))},t.prototype.getServiceDispatcherList=function(t){var e=new Date;return e.setDate(e.getDate()-1),e.setHours(0),e.setMinutes(0),e.setSeconds(0),e.setMilliseconds(0),this.vhmongo_firebase.database().getDocsByFields("vhbill_details",{id_branch:{$eq:t},done:{$eq:!1},bill_type:{$in:[1,5]},ptype:{$eq:2},date_order:{$gte:e}},{},{date_order:1},0)},t.prototype.publishObservableEventAreas=function(){this.subjectareas.next(this.areas)},t.prototype.observableLocalAreas=function(){return this.subjectareas},t.prototype.getObservableLocalAreas=function(){var t=this;return new c.Observable((function(e){t.observableLocalAreas().subscribe((function(t){e.next(t)})),t.publishObservableEventAreas()}))},t.prototype.getlocalArea=function(t){for(var e=0;e<this.areas.length;e++)if(this.areas[e]._id===t)return this.areas[e];return null},t.prototype.getlocalAreas=function(){return this.areas},t.prototype.refreshLocalAreas=function(){return new Promise((function(t,e){t(null)}))},t.prototype.addArea=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("areas",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateArea=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("areas",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteArea=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("tables",{id_area:{$eq:t}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("areas",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getArea=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("areas",t).then((function(t){n(t)}))}))},t.prototype.getAreas=function(){var t=this;return new Promise((function(e){t.vhmongo_firebase.database().getDocs("areas").then((function(n){t.areas=n,e(n)}))}))},t.prototype.addAdss=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("adss",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateAds=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("adss",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteAds=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("adss",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getAds=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("adss",t).then((function(t){n(t)}))}))},t.prototype.getAdss=function(){var t=this;return new Promise((function(e){t.vhmongo_firebase.database().getDocs("adss").then((function(t){e(t)}))}))},t.prototype.getAdss_byFields=function(t,e,n,o){var i=this;return new Promise((function(a,s){void 0===e&&(e={}),void 0===n&&(n={}),void 0===o&&(o=0),i.vhmongo_firebase.database().getDocsByFields("adss",t,e,n,o).then((function(t){a(t)}),(function(t){s(t)}))}))},t.prototype.publishObservableEventTables=function(){this.subjecttables.next(this.tables)},t.prototype.observableLocalTables=function(){return this.subjecttables},t.prototype.getObservableLocalTables=function(){var t=this;return new c.Observable((function(e){t.observableLocalTables().subscribe((function(t){e.next(t)})),t.publishObservableEventTables()}))},t.prototype.getlocalTable=function(t){for(var e=0;e<this.tables.length;e++)if(this.tables[e]._id===t)return this.tables[e];return null},t.prototype.getlocalTables=function(){return this.tables},t.prototype.refreshLocalTables=function(){return new Promise((function(t,e){t(null)}))},t.prototype.addTable=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("tables",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateTable=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("tables",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteTable=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("bills",{id_table:{$eq:t}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("tables",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getTable=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("tables",t).then((function(t){n(t)}))}))},t.prototype.getTables=function(){var t=this;return new Promise((function(e){t.vhmongo_firebase.database().getDocs("tables").then((function(n){t.tables=n,e(n)}))}))},t.prototype.publishObservableEventProducts=function(){this.subjectproducts.next()},t.prototype.observableLocalProducts=function(){return this.subjectproducts},t.prototype.getObservableLocalProducts=function(t){var e=this;return new c.Observable((function(n){e.observableLocalProducts().subscribe((function(){n.next(e.getlocalProducts(t))})),e.publishObservableEventProducts()}))},t.prototype.getlocalProductAndCombosAndToppings=function(t){for(var e=new Array,n=0;n<this.products.length;n++){if(this.products[n]._id===t&&(e.push(Object.assign({},this.products[n])),null!=this.products[n].subs)){var o=E(this.products[n].subs);e[e.length-1].subs=new Array,o.forEach((function(t){e[e.length-1].subs.push(Object.assign({},t))}))}if(null!=this.products[n].combos)for(var i=0;i<this.products[n].combos.length;i++)if(this.products[n].combos[i].id_product===t){e.push(Object.assign({},this.products[n]));break}if(null!=this.products[n].toppings)for(i=0;i<this.products[n].toppings.length;i++)if(this.products[n].toppings[i].id_product===t){e.push(Object.assign({},this.products[n]));break}}return e},t.prototype.getlocalProduct=function(t){for(var e=function(e){if(n.products[e]._id===t){var o=Object.assign({},n.products[e]);if(null!=o.subs){var i=E(o.subs);o.subs=new Array,i.forEach((function(t){o.subs.push(Object.assign({},t))}))}if(null!=o.toppings){var a=E(o.toppings);o.toppings=new Array,a.forEach((function(t){o.toppings.push(Object.assign({},t))}))}if(null!=o.combos){var s=E(o.combos);o.combos=new Array,s.forEach((function(t){o.combos.push(Object.assign({},t))}))}return{value:o}}},n=this,o=0;o<this.products.length;o++){var i=e(o);if("object"==typeof i)return i.value}return null},t.prototype.getlocalProducts=function(t){var e=this,n=new Array;return this.products.forEach((function(o){var i=Object.assign({},o);if(null!=i.subs){var a=E(i.subs);i.subs=new Array,a.forEach((function(t){i.subs.push(Object.assign({},t))}))}if(null!=i.toppings){var s=E(i.toppings);i.toppings=new Array,s.forEach((function(t){var n=e.getlocalProduct(t.id_product);t.name=n.name,t.price=n.price,t.img=n.img,t.id_category=n.id_category,t.ptype=n.type,i.toppings.push(Object.assign({},t))}))}if(null!=i.combos){var r=E(i.combos);i.combos=new Array,r.forEach((function(t){var n=e.getlocalProduct(t.id_product);if(t.name=n.name,t.img=n.img,t.id_category=n.id_category,t.ptype=n.type,null!=t.id_subproduct)for(var o=0;o<n.subs.length;o++)if(t.id_subproduct===n.subs[o]._id){t.name=t.name+"("+n.subs[o].name+")";break}i.combos.push(Object.assign({},t))}))}1===t||2===t||3===t||4===t||5===t?i.type===t&&n.push(Object.assign({},i)):13===t?1!==i.type&&3!==i.type||n.push(Object.assign({},i)):15===t?1!==i.type&&5!==i.type||n.push(Object.assign({},i)):25===t?2!==i.type&&5!==i.type||n.push(Object.assign({},i)):35===t?3!==i.type&&5!==i.type||n.push(Object.assign({},i)):41===t?1!==i.type&&4!==i.type||n.push(Object.assign({},i)):1234===t&&1!==i.type&&2!==i.type&&3!==i.type&&4!==i.type||n.push(Object.assign({},i))})),n},t.prototype.refreshLocalProduct=function(t){return new Promise((function(t,e){t(null)}))},t.prototype.refreshLocalProducts=function(){return new Promise((function(t,e){t(null)}))},t.prototype.addProduct=function(t){var e=this;return new Promise((function(n,o){3===(null==t?void 0:t.type)&&(t.quantity=0,t.quantity_branch={},e.branchs.forEach((function(e){t.quantity_branch[e._id]=0}))),e.vhmongo_firebase.database().addDoc("products",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.addProducts=function(t){var e=this;return new Promise((function(n,o){for(var i,a=new Array,s=function(n){3===(null===(i=t[n])||void 0===i?void 0:i.type)&&(t[n].quantity=0,t[n].quantity_branch={},e.branchs.forEach((function(e){t[n].quantity_branch[e._id]=0}))),a[n]=new Promise((function(o){e.vhmongo_firebase.database().addDoc("products",t[n]).then((function(t){o(t)}),(function(){o(null)}))}))},r=0;r<t.length;r++)s(r);Promise.all(a).then((function(t){var e=t.filter((function(t){return null!=t}));n(e)}))}))},t.prototype.updateProduct=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("products",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteProduct=function(t){var e=this;return new Promise((function(n,o){var i=new Array;e.getlocalProductAndCombosAndToppings(t).forEach((function(t){i.push(t._id)})),1===i.length?e.vhmongo_firebase.database().getDocsByFields("vhbill_details",{id_product:{$in:i}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("products",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)})):(console.log("Bạn không thể xóa, vì sản phẩm đang liên kết với sản phẩm khác"),n(!1))}))},t.prototype.getProduct=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("products",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getProducts=function(){var t=this;return new Promise((function(e,n){return new Promise((function(e){t.vhmongo_firebase.database().getDocs("products").then((function(n){t.products=n,e(n)}),(function(t){n(t)}))}))}))},t.prototype.addToppingsProduct=function(t,e){var n=this;return new Promise((function(o,i){new Array;for(var a=new Array,s=0;s<e.length;s++)a[s]=Object.assign(Object.assign({},e[s]),{_id:n.vhAlgorithm.ObjectId()});var r,l=!1,c=0,u=setInterval((function(){var e,s,d;if(c++,r=n.getlocalProduct(t)){l=!0,void 0===r.toppings&&(r.toppings=new Array);for(var _=0;_<r.toppings.length;_++)null===(e=r.toppings[_])||void 0===e||delete e.name,null===(s=r.toppings[_])||void 0===s||delete s.price,null===(d=r.toppings[_])||void 0===d||delete d.img;var p=E(r.toppings,a);n.vhmongo_firebase.database().updateDoc("products",t,{toppings:p}).then((function(){for(var t=0;t<a.length;t++)a[t].name=n.getlocalProduct(a[t].id_product).name,a[t].price=n.getlocalProduct(a[t].id_product).price,a[t].img=n.getlocalProduct(a[t].id_product).img;o(a)}),(function(t){i(t)}))}!0!==l&&20!==c||clearInterval(u)}),100)}))},t.prototype.deleteToppingProduct=function(t,e){var n=this;return new Promise((function(o,i){var a=n.getlocalProduct(t);if(null!=a.toppings)for(var s=0;s<a.toppings.length;s++)if(a.toppings[s]._id===e){a.toppings.splice(s,1),n.vhmongo_firebase.database().updateDoc("products",a._id,{toppings:a.toppings}).then((function(t){o(t)}),(function(t){i(t)}));break}}))},t.prototype.addCombosProduct=function(t,e){for(var n,o=this,i=0;i<e.length;i++)null===(n=e[i])||void 0===n||delete n.name;return new Promise((function(n,i){for(var a=new Array,s=0;s<e.length;s++)a[s]=Object.assign(Object.assign({},e[s]),{_id:o.vhAlgorithm.ObjectId()});var r,l=!1,c=0,u=setInterval((function(){var e,s;if(c++,r=o.getlocalProduct(t)){l=!0,void 0===r.combos&&(r.combos=new Array);for(var d=0;d<r.combos.length;d++)null===(e=r.combos[d])||void 0===e||delete e.name,null===(s=r.combos[d])||void 0===s||delete s.img;var _=E(r.combos,a);o.vhmongo_firebase.database().updateDoc("products",t,{combos:_}).then((function(){for(var t=0;t<a.length;t++){var e=o.getlocalProduct(a[t].id_product);if(a[t].name=e.name,a[t].img=e.img,null!=a[t].id_subproduct)for(var i=0;i<e.subs.length;i++)if(a[t].id_subproduct===e.subs[i]._id){a[t].name=a[t].name+"("+e.subs[i].name+")";break}}n(a)}),(function(){i(null)}))}!0!==l&&20!==c||clearInterval(u)}),100)}))},t.prototype.updateComboProduct=function(t,e,n){var o=this;return null==n||delete n.name,null==n||delete n.quantity,new Promise((function(i,a){var s=o.getlocalProduct(t);if(null!=s.combos){s.combos.forEach((function(t){null==t||delete t.name,null==t||delete t.img}));for(var r=0;r<s.combos.length;r++)if(s.combos[r]._id===e){s.combos[r]=Object.assign(Object.assign({},s.combos[r]),n),o.vhmongo_firebase.database().updateDoc("products",s._id,{combos:s.combos}).then((function(t){i(t)}),(function(t){a(t)}));break}}}))},t.prototype.addSubProduct=function(t,e){var n=this;return new Promise((function(o,i){var a,s=Object.assign(Object.assign({},e),{_id:n.vhAlgorithm.ObjectId()}),r=!1,l=0,c=setInterval((function(){if(l++,a=n.getlocalProduct(t)){r=!0,void 0===a.subs&&(a.subs=new Array);var e=a.subs;e.push(s),n.vhmongo_firebase.database().updateDoc("products",t,{subs:e}).then((function(){o(s)}),(function(t){o(null)}))}!0!==r&&5!==l||clearInterval(c)}),100)}))},t.prototype.addSubsProduct=function(t,e){var n=this;return new Promise((function(o,i){for(var a=new Array,s=0;s<e.length;s++)a[s]=Object.assign(Object.assign({},e[s]),{_id:n.vhAlgorithm.ObjectId()});var r,l=!1,c=0,u=setInterval((function(){if(c++,r=n.getlocalProduct(t)){l=!0,void 0===r.subs&&(r.subs=new Array);var e=E(r.subs,a);n.vhmongo_firebase.database().updateDoc("products",t,{subs:e}).then((function(){o(a)}),(function(t){o(null)}))}!0!==l&&20!==c||clearInterval(u)}),100)}))},t.prototype.updateSubProduct=function(t,e,n){var o=this;return new Promise((function(i,a){var s=o.getlocalProduct(t);if(null!=s.subs)for(var r=0;r<s.subs.length;r++)if(s.subs[r]._id===e){s.subs[r]=Object.assign(Object.assign({},s.subs[r]),n),o.vhmongo_firebase.database().updateDoc("products",s._id,{subs:s.subs}).then((function(t){i(t)}),(function(t){a(t)}));break}}))},t.prototype.deleteSubProduct=function(t,e){var n=this;return new Promise((function(o,i){var a=new Array;n.getlocalProductAndCombosAndToppings(t).forEach((function(t){a.push(t._id)})),1===a.length?n.vhmongo_firebase.database().getDocsByFields("vhbill_details",{id_subproduct:{$eq:e}},{},{},1).then((function(a){if(0===a.length){var s=n.getlocalProduct(t);if(null!=s.subs)for(var r=0;r<s.subs.length;r++)if(s.subs[r]._id===e){s.subs.splice(r,1),n.vhmongo_firebase.database().updateDoc("products",s._id,{subs:s.subs}).then((function(t){o(t)}),(function(t){i(t)}));break}o(!0)}else o(!1)}),(function(t){i(t)})):(console.log("Bạn không thể xóa, vì sản phẩm đang liên kết với sản phẩm khác"),o(!1))}))},t.prototype.publishObservableEventCustomers=function(){this.subjectcustomers.next(this.customers)},t.prototype.observableLocalCustomers=function(){return this.subjectcustomers},t.prototype.getObservableLocalCustomers=function(){var t=this;return new c.Observable((function(e){t.observableLocalCustomers().subscribe((function(t){e.next(t)})),t.publishObservableEventCustomers()}))},t.prototype.getlocalCustomer=function(t){for(var e=0;e<this.customers.length;e++)if(this.customers[e]._id===t)return this.customers[e];return null},t.prototype.getlocalCustomers=function(){return this.customers},t.prototype.refreshLocalCustomers=function(){return new Promise((function(t){t(null)}))},t.prototype.addCustomer=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("customers",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.addCustomers=function(t){var e=this;return new Promise((function(n,o){for(var i=new Array,a=function(n){i[n]=new Promise((function(o){e.vhmongo_firebase.database().addDoc("customers",t[n]).then((function(t){o(t)}),(function(){o(null)}))}))},s=0;s<t.length;s++)a(s);Promise.all(i).then((function(t){var e=t.filter((function(t){return null!=t}));n(e)}))}))},t.prototype.updateCustomer=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("customers",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteCustomer=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("bills",{id_customer:{$eq:t}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("customers",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getCustomer=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("customers",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getCustomers=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("customers").then((function(n){t.customers=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventSuppliers=function(){this.subjectsuppliers.next(this.suppliers)},t.prototype.observableLocalSuppliers=function(){return this.subjectsuppliers},t.prototype.getObservableLocalSuppliers=function(){var t=this;return new c.Observable((function(e){t.observableLocalSuppliers().subscribe((function(t){e.next(t)})),t.publishObservableEventSuppliers()}))},t.prototype.getlocalSupplier=function(t){for(var e=0;e<this.suppliers.length;e++)if(this.suppliers[e]._id===t)return Object.assign({},this.suppliers[e]);return null},t.prototype.getlocalSuppliers=function(){return this.suppliers},t.prototype.refreshLocalSuppliers=function(){return new Promise((function(t){t(null)}))},t.prototype.addSupplier=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("suppliers",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.addSuppliers=function(t){var e=this;return new Promise((function(n,o){for(var i=new Array,a=function(n){i[n]=new Promise((function(o){e.vhmongo_firebase.database().addDoc("suppliers",t[n]).then((function(t){o(t)}),(function(){o(null)}))}))},s=0;s<t.length;s++)a(s);Promise.all(i).then((function(t){var e=t.filter((function(t){return null!=t}));n(e)}))}))},t.prototype.updateSupplier=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("suppliers",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteSupplier=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("bills",{id_supplier:{$eq:t}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("suppliers",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getSupplier=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("suppliers",t).then((function(t){n(t)}))}))},t.prototype.getSuppliers=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("suppliers").then((function(n){t.suppliers=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventWallets=function(){this.subjectwallets.next(this.wallets)},t.prototype.observableLocalWallets=function(){return this.subjectwallets},t.prototype.getObservableLocalWallets=function(){var t=this;return new c.Observable((function(e){t.observableLocalWallets().subscribe((function(t){e.next(t)})),t.publishObservableEventWallets()}))},t.prototype.getlocalWallet=function(t){for(var e=0;e<this.wallets.length;e++)if(this.wallets[e]._id===t)return this.wallets[e];return null},t.prototype.getlocalWallets=function(){return this.wallets},t.prototype.refreshLocalWallets=function(){return new Promise((function(t){t(null)}))},t.prototype.addWallet=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("wallets",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateWallet=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("wallets",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteWallet=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("bills",{id_wallet:{$eq:t}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("wallets",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getWallet=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("wallets",t).then((function(t){n(t)}))}))},t.prototype.getWallets=function(){var t=this;return new Promise((function(e,n){t.wallets=new Array,t.vhmongo_firebase.database().getDocs("wallets").then((function(n){t.wallets=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventTaxs=function(){this.subjecttaxs.next(this.taxs)},t.prototype.observableLocalTaxs=function(){return this.subjecttaxs},t.prototype.getObservableLocalTaxs=function(){var t=this;return new c.Observable((function(e){t.observableLocalTaxs().subscribe((function(t){e.next(t)})),t.publishObservableEventTaxs()}))},t.prototype.getlocalTax=function(t){for(var e=0;e<this.taxs.length;e++)if(this.taxs[e]._id===t)return this.taxs[e];return null},t.prototype.getlocalTaxs=function(){return this.taxs},t.prototype.refreshLocalTaxs=function(){return new Promise((function(t){t(null)}))},t.prototype.addTax=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("taxs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateTax=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("taxs",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteTax=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("taxs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getTax=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("taxs",t).then((function(t){n(t)}))}))},t.prototype.getTaxs=function(){var t=this;return new Promise((function(e,n){t.taxs=new Array,t.vhmongo_firebase.database().getDocs("taxs").then((function(n){t.taxs=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventCategorys=function(){this.subjectcategorys.next()},t.prototype.observableLocalCategorys=function(){return this.subjectcategorys},t.prototype.getObservableLocalCategorys=function(t){var e=this;return new c.Observable((function(n){e.observableLocalCategorys().subscribe((function(){n.next(e.getlocalCategorys(t))})),e.publishObservableEventCategorys()}))},t.prototype.getlocalCategory=function(t){for(var e=0;e<this.categorys.length;e++)if(this.categorys[e]._id===t)return Object.assign({},this.categorys[e]);return null},t.prototype.getlocalCategorys=function(t){var e=new Array;return 1===t||2===t||3===t||4===t||4===t?this.categorys.forEach((function(n){n.type===t&&e.push(Object.assign({},n))})):1234===t?this.categorys.forEach((function(t){1!==t.type&&2!==t.type&&3!==t.type&&4!==t.type||e.push(Object.assign({},t))})):this.categorys.forEach((function(t){e.push(Object.assign({},t))})),e},t.prototype.refreshLocalCategorys=function(){return new Promise((function(t){t(null)}))},t.prototype.addCategory=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("categorys",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.addCategorys=function(t){var e=this;return new Promise((function(n,o){for(var i=new Array,a=function(n){i[n]=new Promise((function(o){e.vhmongo_firebase.database().addDoc("categorys",t[n]).then((function(t){o(t)}),(function(){o(null)}))}))},s=0;s<t.length;s++)a(s);Promise.all(i).then((function(t){var e=t.filter((function(t){return null!=t}));n(e)}))}))},t.prototype.updateCategory=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("categorys",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteCategory=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("products",{id_category:{$eq:t}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("categorys",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getCategory=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("categorys",t).then((function(t){n(t)}))}))},t.prototype.getCategorys=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("categorys").then((function(n){t.categorys=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventInventorytimes=function(){this.subjectinventorytimes.next(this.inventorytimes)},t.prototype.observableLocalInventorytimes=function(){return this.subjectinventorytimes},t.prototype.getObservableLocalInventorytimes=function(){var t=this;return new c.Observable((function(e){t.observableLocalInventorytimes().subscribe((function(t){e.next(t)})),t.publishObservableEventInventorytimes()}))},t.prototype.getlocalInventorytime=function(t){for(var e=0;e<this.inventorytimes.length;e++)if(this.inventorytimes[e]._id===t)return this.inventorytimes[e];return null},t.prototype.getlocalInventorytimes=function(){return this.inventorytimes},t.prototype.refreshLocalInventorytimes=function(){return new Promise((function(t){t(null)}))},t.prototype.addInventorytime=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("inventorytimes",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateInventorytime=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("inventorytimes",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteInventorytime=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("inventorytimes",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getInventorytime=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("inventorytimes",t).then((function(t){n(t)}))}))},t.prototype.getInventorytimes=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("inventorytimes").then((function(n){t.inventorytimes=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventCustomerClasss=function(){this.subjectcustomer_classs.next(this.customer_classs)},t.prototype.observableLocalCustomerClasss=function(){return this.subjectcustomer_classs},t.prototype.getObservableLocalCustomerClasss=function(){var t=this;return new c.Observable((function(e){t.observableLocalCustomerClasss().subscribe((function(t){e.next(t)})),t.publishObservableEventCustomerClasss()}))},t.prototype.getlocalCustomerClass=function(t){for(var e=0;e<this.customer_classs.length;e++)if(this.customer_classs[e]._id===t)return JSON.parse(JSON.stringify(this.customer_classs[e]));return null},t.prototype.getlocalCustomerClasss=function(){return JSON.parse(JSON.stringify(this.customer_classs))},t.prototype.addCustomerClass=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("customer_classs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateCustomerClass=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("customer_classs",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteCustomerClass=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("customer_classs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.publishObservableEventDiscount_bills=function(){this.subjectdiscount_bills.next(this.discount_bills)},t.prototype.observableLocalDiscount_bills=function(){return this.subjectdiscount_bills},t.prototype.getObservableLocalDiscount_bills=function(){var t=this;return new c.Observable((function(e){t.observableLocalDiscount_bills().subscribe((function(t){e.next(t)})),t.publishObservableEventDiscount_bills()}))},t.prototype.getlocalDiscount_bill=function(t){for(var e=0;e<this.discount_bills.length;e++)if(this.discount_bills[e]._id===t)return JSON.parse(JSON.stringify(this.discount_bills[e]));return null},t.prototype.getlocalDiscount_bills=function(){return JSON.parse(JSON.stringify(this.discount_bills))},t.prototype.addDiscount_bill=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("discount_bills",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateDiscount_bill=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("discount_bills",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteDiscount_bill=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("discount_bills",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.addDiscount_sales=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("discount_saless",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateDiscount_sales=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("discount_saless",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteDiscount_sales=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("discount_saless",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getDiscount_sales=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("discount_saless",t).then((function(t){n(t)}))}))},t.prototype.getDiscount_saless=function(){var t=this;return new Promise((function(e,n){t.discount_saless=new Array,t.vhmongo_firebase.database().getDocs("discount_saless").then((function(n){t.discount_saless=n,e(n)}),(function(t){n(t)}))}))},t.prototype.addCommission=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("commissions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateCommission=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("commissions",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteCommission=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("commissions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getCommission=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("commissions",t).then((function(t){n(t)}))}))},t.prototype.getCommissions=function(){var t=this;return new Promise((function(e,n){t.commissions=new Array,t.vhmongo_firebase.database().getDocs("commissions").then((function(n){t.commissions=n,e(n)}),(function(t){n(t)}))}))},t.prototype.getlocalDelivery=function(t){for(var e=0;e<this.deliverys.length;e++)if(this.deliverys[e]._id===t)return this.deliverys[e];return null},t.prototype.getlocalDeliverys=function(){return this.deliverys},t.prototype.refreshLocalDeliverys=function(){var t=this;return new Promise((function(e){t.getDeliverys().then((function(){e(null)}))}))},t.prototype.addDelivery=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("deliverys",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateDelivery=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("deliverys",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteDelivery=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("deliverys",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getDelivery=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("deliverys",t).then((function(t){n(t)}))}))},t.prototype.getDeliverys=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("deliverys").then((function(n){t.deliverys=n,e(n)}),(function(t){n(t)}))}))},t.prototype.getlocalAddress=function(t){for(var e=0;e<this.addresss.length;e++)if(this.addresss[e]._id===t)return this.addresss[e];return null},t.prototype.getlocalAddresss=function(){return this.addresss},t.prototype.refreshLocalAddresss=function(){var t=this;return new Promise((function(e){t.getAddresss().then((function(){e(null)}))}))},t.prototype.addAddress=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("addresss",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateAddress=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("addresss",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteAddress=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("addresss",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getAddress=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("addresss",t).then((function(t){n(t)}))}))},t.prototype.getAddresss=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("addresss").then((function(n){t.addresss=n,e(n)}),(function(t){n(t)}))}))},t.prototype.getlocalIncoming_group=function(t){for(var e=0;e<this.incoming_groups.length;e++)if(this.incoming_groups[e]._id===t)return Object.assign({},this.incoming_groups[e]);return null},t.prototype.getlocalIncoming_groups=function(){return E(this.incoming_groups)},t.prototype.refreshLocalIncoming_groups=function(){var t=this;return new Promise((function(e){t.getIncoming_groups().then((function(){e(null)}))}))},t.prototype.addIncoming_group=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("incoming_groups",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateIncoming_group=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("incoming_groups",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteIncoming_group=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("bills",{id_incoming_group:{$eq:t}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("incoming_groups",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getIncoming_groups=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("incoming_groups").then((function(n){t.incoming_groups=n,t.incoming_groups=t.vhAlgorithm.sortVietnamesebyASC(t.incoming_groups,"name"),e(t.incoming_groups)}),(function(t){n(t)}))}))},t.prototype.getlocalSpending_group=function(t){for(var e=0;e<this.spending_groups.length;e++)if(this.spending_groups[e]._id===t)return Object.assign({},this.spending_groups[e]);return null},t.prototype.getlocalSpending_groups=function(){return E(this.spending_groups)},t.prototype.refreshLocalSpending_groups=function(){var t=this;return new Promise((function(e){t.getSpending_groups().then((function(){e(null)}))}))},t.prototype.addSpending_group=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("spending_groups",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateSpending_group=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("spending_groups",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteSpending_group=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("bills",{id_spending_group:{$eq:t}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("spending_groups",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getSpending_groups=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("spending_groups").then((function(n){t.spending_groups=n,t.spending_groups=t.vhAlgorithm.sortVietnamesebyASC(t.spending_groups,"name"),e(t.spending_groups)}),(function(t){n(t)}))}))},t.prototype.addPatternMenu=function(t){var e=this;return new Promise((function(n,o){var i=Object.assign(Object.assign({},t),{id_branch:e.getDefaultBranch()._id});e.vhmongo_firebase.database().addDoc("patternmenus",i).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updatePatternMenu=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("patternmenus",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deletePatternMenu=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("patternmenus",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPatternMenu=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("patternmenus",t).then((function(t){n(t)}))}))},t.prototype.getPatternMenus=function(){var t=this;return new Promise((function(e,n){t.taxs=new Array,t.vhmongo_firebase.database().getDocsByFields("patternmenus",{id_branch:{$eq:t.getDefaultBranch()._id}},{},{},0).then((function(n){t.patternmenus=n,e(n)}),(function(t){n(t)}))}))},t.prototype.updateDebtAtBeginningCustomer=function(t,e,n){var o=this;return new Promise((function(i,a){var s=o.getlocalCustomer(t),r={};null!=s[e]?r[e]=s[e]:r[e]={},r[e].debt_beginning=n,o.vhmongo_firebase.database().updateDoc("customers",t,Object.assign({},r)).then((function(t){i(t)}),(function(t){a(t)}))}))},t.prototype.getDebtAtBeginningCustomers_byIDcustomer=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("debt_at_beginning_customers",{id_customer:{$eq:t}},{}).then((function(t){n(t)})).catch((function(t){o(t)}))}))},t.prototype.getDebtAtBeginningCustomers_byIDbranch=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("debt_at_beginning_customers",{id_branch:{$eq:t}},{}).then((function(t){n(t)})).catch((function(t){o(t)}))}))},t.prototype.getDebtAtBeginningCustomers_byIDcustomer_byIDbranch=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().getDocsByFields("debt_at_beginning_customers",{id_customer:{$eq:t},id_branch:{$eq:e}},{}).then((function(t){o(t)})).catch((function(t){i(t)}))}))},t.prototype.getDebtAtBeginningCustomers=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("debt_at_beginning_customers").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.updateDebtAtBeginningSupplier=function(t,e,n){var o=this;return new Promise((function(i,a){var s=o.getlocalSupplier(t),r={};null!=s[e]?r[e]=s[e]:r[e]={},r[e].debt_beginning=n,o.vhmongo_firebase.database().updateDoc("suppliers",t,Object.assign({},r)).then((function(t){i(t)}),(function(t){a(t)}))}))},t.prototype.getDebtAtBeginningSuppliers_byIDsupplier=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("debt_at_beginning_suppliers",{id_supplier:{$eq:t}},{}).then((function(t){n(t)})).catch((function(t){o(t)}))}))},t.prototype.getDebtAtBeginningSuppliers_byIDbranch=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("debt_at_beginning_suppliers",{id_branch:{$eq:t}},{}).then((function(t){n(t)})).catch((function(t){o(t)}))}))},t.prototype.getDebtAtBeginningSuppliers_byIDsupplier_byIDbranch=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().getDocsByFields("debt_at_beginning_suppliers",{id_supplier:{$eq:t},id_branch:{$eq:e}},{}).then((function(t){o(t)})).catch((function(t){i(t)}))}))},t.prototype.getDebtAtBeginningSuppliers=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("debt_at_beginning_suppliers").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.setDefaultBranch=function(t){for(var e=0;e<this.branchs.length;e++)if(this.branchs[e]._id===t){localStorage.setItem(this.vhmongo_firebase.auth().getProjectName()+"_default_branch",JSON.stringify(this.branchs[e]));break}},t.prototype.getDefaultBranch=function(){return 0==this.branchs.length?null:localStorage.getItem(this.vhmongo_firebase.auth().getProjectName()+"_default_branch")?JSON.parse(localStorage.getItem(this.vhmongo_firebase.auth().getProjectName()+"_default_branch")):null},t.prototype.clearDefaultBranch=function(){localStorage.setItem(this.vhmongo_firebase.auth().getProjectName()+"_default_branch",null)},t.prototype.isChains=function(){return 0==this.branchs.length?null:1!=this.branchs.length},t.prototype.publishObservableEventBranchs=function(){this.subjectbranchs.next(this.branchs)},t.prototype.observableLocalBranchs=function(){return this.subjectbranchs},t.prototype.getObservableLocalBranchs=function(){var t=this;return new c.Observable((function(e){t.observableLocalBranchs().subscribe((function(t){e.next(t)})),t.publishObservableEventBranchs()}))},t.prototype.getlocalBranch=function(t){for(var e=0;e<this.branchs.length;e++)if(this.branchs[e]._id===t)return this.branchs[e];return null},t.prototype.getlocalBranchs=function(){return this.branchs},t.prototype.refreshLocalBranchs=function(){var t=this;return new Promise((function(e){t.getBranchs().then((function(){e(null)}))}))},t.prototype.addBranch=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("branchs",t).then((function(t){var o=new Array,i=e.getlocalProducts(3),a=Object.assign(Object.assign({},t),{opentime:"8h:00 AM",closetime:"10h:00 PM",img:"",tax_number:""});a.appsetting_name="store_info",a.id_branch=t._id,delete a._id,o.push(e.vhmongo_firebase.database().addDoc("appsettingbranchs",a));for(var s=0;s<i.length;s++)i[s].quantity_branch[t._id]=0,o.push(e.updateProduct(i[s]._id,{quantity_branch:i[s].quantity_branch}));Promise.all(o).then((function(){n(t)}))}),(function(t){o(t)}))}))},t.prototype.updateBranch=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("branchs",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteBranch=function(t){var e=this;return new Promise((function(n,o){var i=new Array;i[0]=e.vhmongo_firebase.database().getDocsByFields("wallets",{id_branch:{$eq:t}},{},{},1),i[1]=e.vhmongo_firebase.database().getDocsByFields("bills",{id_branch:{$eq:t}},{},{},1),i[2]=e.vhmongo_firebase.database().getDocsByFields("bills",{id_branch_receive:{$eq:t}},{},{},1),Promise.all(i).then((function(i){0===i[0].length&&0===i[1].length&&0===i[2].length?e.vhmongo_firebase.database().deleteDoc("branchs",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getBranch=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("branchs",t).then((function(t){n(t)}))}))},t.prototype.getBranchs=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("branchs").then((function(n){t.branchs=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventPrinters=function(){this.subjectprinters.next(this.printers)},t.prototype.observableLocalPrinters=function(){return this.subjectprinters},t.prototype.getObservableLocalPrinters=function(){var t=this;return new c.Observable((function(e){t.observableLocalPrinters().subscribe((function(t){e.next(t)})),t.publishObservableEventPrinters()}))},t.prototype.getlocalPrinter=function(t){for(var e=0;e<this.printers.length;e++)if(this.printers[e]._id===t)return this.printers[e];return null},t.prototype.getlocalPrinters=function(){return this.printers},t.prototype.refreshLocalPrinters=function(){return new Promise((function(t,e){t(null)}))},t.prototype.addPrinter=function(t){var e=this;return new Promise((function(n,o){var i=Object.assign({},t);i.uuid=e.hwinfo.uuid,e.vhmongo_firebase.database().addDoc("printers",i).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updatePrinter=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("printers",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deletePrinter=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("printers",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPrinter=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("printers",t).then((function(t){t&&(null==t||delete t.uuid),n(t)}),(function(t){o(t)}))}))},t.prototype.getPrinters=function(){var t=this;return new Promise((function(e){t.vhmongo_firebase.database().getDocsByFields("printers",{uuid:{$eq:t.hwinfo.uuid}},{},{},0).then((function(n){t.printers=new Array,n.length>0&&n.forEach((function(e){null==e||delete e.uuid,t.printers.push(e)})),e(t.printers)}))}))},t.prototype.createBill_Billdetail=function(t,e){var n=this;return new Promise((function(o,i){n.sync_code=Math.random().toString(36).substr(2,10).toUpperCase(),t.sync_code=n.sync_code,t.bill_code=n.vhAlgorithm.createBillCode(null==t?void 0:t.date),n.vhmongo_firebase.database().addDoc("bills",t).then((function(a){if(a){for(var s=new Array,r=0;r<e.length;r++){var l=e[r];l.id_bill=a._id,t.bill_code&&(l.bill_code=t.bill_code),t.date&&(l.date=t.date),t.id_area&&(l.id_area=t.id_area),t.id_table&&(l.id_table=t.id_table),"number"==typeof t.tax&&(l.tax=t.tax),"number"==typeof t.bill_type&&(l.bill_type=t.bill_type),t.id_cashier&&(l.id_cashier=t.id_cashier),t.id_employee&&(l.id_employee=t.id_employee),t.id_supplier&&(l.id_supplier=t.id_supplier),t.id_customer&&(l.id_customer=t.id_customer),t.id_inventorytime&&(l.id_inventorytime=t.id_inventorytime),t.id_branch&&(l.id_branch=t.id_branch),s[r]=n.vhmongo_firebase.database().addDoc("vhbill_details",l)}n.vhQuery.asyncPromiseAll(s).then((function(i){if(1===t.bill_type||3===t.bill_type||10===t.bill_type){for(var s=new Array,r=function(o){s[o]=new Promise((function(i){if(3===e[o].ptype){var a=n.getlocalProduct(e[o].id_product),s={};null!=a.quantity_branch?(s=a.quantity_branch,null!=a.quantity_branch[t.id_branch]?s[t.id_branch]=s[t.id_branch]-e[o].quantity:s[t.id_branch]=-e[o].quantity):s[t.id_branch]=-e[o].quantity;var r=a.quantity-e[o].quantity;n.vhmongo_firebase.database().updateDoc("products",a._id,{quantity:r,quantity_branch:s}).then((function(){i(null)}))}else i(null)}))},l=0;l<e.length;l++)r(l);n.vhQuery.asyncPromiseAll(s).then((function(){o(a)}))}else if(2===t.bill_type||16===t.bill_type){s=new Array;var c=function(o){s[o]=new Promise((function(i){if(3===e[o].ptype){var a=n.getlocalProduct(e[o].id_product),s={};null!=a.quantity_branch?(s=a.quantity_branch,null!=a.quantity_branch[t.id_branch]?s[t.id_branch]=s[t.id_branch]+e[o].quantity:s[t.id_branch]=e[o].quantity):s[t.id_branch]=e[o].quantity;var r=a.quantity+e[o].quantity;n.vhmongo_firebase.database().updateDoc("products",a._id,{quantity:r,quantity_branch:s}).then((function(){i(null)}))}else i(null)}))};for(l=0;l<e.length;l++)c(l);n.vhQuery.asyncPromiseAll(s).then((function(){o(a)}))}else if(9===t.bill_type){s=new Array;var u=function(o){s[o]=new Promise((function(i){var a;if(3===e[o].ptype){var s=n.getlocalProduct(e[o].id_product),r={};null!=s.quantity_branch?(r=s.quantity_branch,null!=s.quantity_branch[t.id_branch]?r[t.id_branch]=r[t.id_branch]+e[o].quantity:r[t.id_branch]=e[o].quantity):r[t.id_branch]=e[o].quantity;var l=s.quantity+e[o].quantity,c={};null!=s[t.id_branch]&&null!=s[t.id_branch].inventory&&(c[t.id_branch]=s[t.id_branch],null===(a=c[t.id_branch])||void 0===a||delete a.inventory),n.vhmongo_firebase.database().updateDoc("products",s._id,Object.assign({quantity:l,quantity_branch:r},c)).then((function(){i(null)}))}else i(null)}))};for(l=0;l<e.length;l++)u(l);n.vhQuery.asyncPromiseAll(s).then((function(){o(a)}))}else 5!==t.bill_type&&6!==t.bill_type&&13!==t.bill_type&&14!==t.bill_type&&15!==t.bill_type&&17!==t.bill_type&&20!==t.bill_type&&29!==t.bill_type||o(a)}))}else i({message:"Invoice creation failed"})}),(function(t){i(t)}))}))},t.prototype.saveBill_Billdetail=function(t){var e=this;return new Promise((function(n,o){e.sync_code=Math.random().toString(36).substr(2,10).toUpperCase();var i=e.vhmongo_firebase.database().getDoc("bills",t),a=e.vhmongo_firebase.database().getDocsByFields("vhbill_details",{id_bill:{$eq:t}},{},{},0);Promise.all([i,a]).then((function(o){if(5===o[0].bill_type){for(var i=new Array,a=0;a<o[1].length;a++){var s=Object.assign({},o[1][a]);s.id_bill=o[0]._id,s.bill_type=1,o[0].id_area&&(s.id_area=o[0].id_area),o[0].id_table&&(s.id_table=o[0].id_table),o[0].date&&(s.date=o[0].date),"number"==typeof o[0].tax&&(s.tax=o[0].tax),"number"==typeof o[0].bill_type&&(s.bill_type=1),o[0].id_cashier&&(s.id_cashier=o[0].id_cashier),o[0].id_employee&&(s.id_employee=o[0].id_employee),o[0].id_supplier&&(s.id_supplier=o[0].id_supplier),o[0].id_customer&&(s.id_customer=o[0].id_customer),i[a]=e.vhmongo_firebase.database().updateDoc("vhbill_details",o[1][a]._id,s)}i[o[1].length]=e.vhmongo_firebase.database().updateDoc("bills",t,{bill_type:1,uuid:null,sync_code:e.sync_code}),Promise.all(i).then((function(){for(var t=new Array,i=function(n){t[n]=new Promise((function(t){if(3===o[1][n].ptype){var i=e.getlocalProduct(o[1][n].id_product),a={};null!=i.quantity_branch?(a=i.quantity_branch,null!=i.quantity_branch[o[0].id_branch]?a[o[0].id_branch]=a[o[0].id_branch]-o[1][n].quantity:a[o[0].id_branch]=-o[1][n].quantity):a[o[0].id_branch]=-o[1][n].quantity;var s=i.quantity-o[1][n].quantity;e.vhmongo_firebase.database().updateDoc("products",i._id,{quantity:s,quantity_branch:a}).then((function(){t(null)}))}else t(null)}))},a=0;a<o[1].length;a++)i(a);e.vhQuery.asyncPromiseAll(t).then((function(){n(o)}))}))}}))}))},t.prototype.updateBill_Billdetail=function(t,e,n){var o=this;return new Promise((function(i,a){o.sync_code=Math.random().toString(36).substr(2,10).toUpperCase(),e.sync_code=o.sync_code,new Promise((function(n){var i=o.vhmongo_firebase.database().getDoc("bills",t),a=o.vhmongo_firebase.database().getDocsByFields("vhbill_details",{id_bill:{$eq:t}},{},{},0);Promise.all([i,a]).then((function(t){if(1===t[0].bill_type||3===t[0].bill_type||10===t[0].bill_type){for(var i=new Array,a=0;a<t[1].length;a++)i[a]=o.vhmongo_firebase.database().deleteDoc("vhbill_details",t[1][a]._id);Promise.all(i).then((function(){for(var i=new Array,a=function(n){i[n]=new Promise((function(i){if(3===t[1][n].ptype){var a=o.getlocalProduct(t[1][n].id_product),s={};null!=a.quantity_branch?(s=a.quantity_branch,null!=a.quantity_branch[e.id_branch]?s[e.id_branch]=s[e.id_branch]+t[1][n].quantity:s[e.id_branch]=t[1][n].quantity):s[e.id_branch]=t[1][n].quantity;var r=a.quantity+t[1][n].quantity;o.vhmongo_firebase.database().updateDoc("products",a._id,{quantity:r,quantity_branch:s}).then((function(){i(null)}))}else i(null)}))},s=0;s<t[1].length;s++)a(s);o.vhQuery.asyncPromiseAll(i).then((function(){n(t)}))}))}else if(2===t[0].bill_type||16===t[0].bill_type){for(i=new Array,a=0;a<t[1].length;a++)i[a]=o.vhmongo_firebase.database().deleteDoc("vhbill_details",t[1][a]._id);Promise.all(i).then((function(){for(var i=new Array,a=function(n){i[n]=new Promise((function(i){if(3===t[1][n].ptype){var a=o.getlocalProduct(t[1][n].id_product),s={};null!=a.quantity_branch?(s=a.quantity_branch,null!=a.quantity_branch[e.id_branch]?s[e.id_branch]=s[e.id_branch]-t[1][n].quantity:s[e.id_branch]=-t[1][n].quantity):s[e.id_branch]=-t[1][n].quantity;var r=a.quantity-t[1][n].quantity;o.vhmongo_firebase.database().updateDoc("products",a._id,{quantity:r,quantity_branch:s}).then((function(){i(null)}))}else i(null)}))},s=0;s<t[1].length;s++)a(s);o.vhQuery.asyncPromiseAll(i).then((function(){n(t)}))}))}else if(9===t[0].bill_type){for(i=new Array,a=0;a<t[1].length;a++)i[a]=o.vhmongo_firebase.database().deleteDoc("vhbill_details",t[1][a]._id);Promise.all(i).then((function(){for(var i=new Array,a=function(n){i[n]=new Promise((function(i){var a;if(3===t[1][n].ptype){var s=o.getlocalProduct(t[1][n].id_product),r={};null!=s.quantity_branch?(r=s.quantity_branch,null!=s.quantity_branch[e.id_branch]?r[e.id_branch]=r[e.id_branch]-t[1][n].quantity:r[e.id_branch]=-t[1][n].quantity):r[e.id_branch]=-t[1][n].quantity;var l=s.quantity-t[1][n].quantity,c={};null!=s[e.id_branch]&&null!=s[e.id_branch].inventory&&(c[e.id_branch]=s[e.id_branch],null===(a=c[e.id_branch])||void 0===a||delete a.inventory),o.vhmongo_firebase.database().updateDoc("products",s._id,Object.assign({quantity:l,quantity_branch:r},c)).then((function(){i(null)}))}else i(null)}))},s=0;s<t[1].length;s++)a(s);o.vhQuery.asyncPromiseAll(i).then((function(){n(t)}))}))}else if(5===t[0].bill_type||6===t[0].bill_type||13===t[0].bill_type||14===t[0].bill_type||15===t[0].bill_type||17===t[0].bill_type||20===t[0].bill_type||29===t[0].bill_type){for(i=new Array,a=0;a<t[1].length;a++)i[a]=o.vhmongo_firebase.database().deleteDoc("vhbill_details",t[1][a]._id);Promise.all(i).then((function(){n(t)}))}}))})).then((function(a){if(1===e.bill_type||3===e.bill_type||10===e.bill_type){var s=new Array;(l=Object.assign({},e)).bill_code=a[0].bill_code,s[n.length]=o.vhmongo_firebase.database().updateDoc("bills",t,l);for(var r=0;r<n.length;r++){(_=Object.assign({},n[r])).id_bill=t,a[0].bill_code&&(_.bill_code=a[0].bill_code),e.date&&(_.date=e.date),e.id_area&&(_.id_area=e.id_area),e.id_table&&(_.id_table=e.id_table),"number"==typeof e.tax&&(_.tax=e.tax),"number"==typeof e.bill_type&&(_.bill_type=e.bill_type),e.id_cashier&&(_.id_cashier=e.id_cashier),e.id_employee&&(_.id_employee=e.id_employee),e.id_supplier&&(_.id_supplier=e.id_supplier),e.id_customer&&(_.id_customer=e.id_customer),e.id_inventorytime&&(_.id_inventorytime=e.id_inventorytime),e.id_branch&&(_.id_branch=e.id_branch),s[r]=o.vhmongo_firebase.database().addDoc("vhbill_details",_)}Promise.all(s).then((function(){for(var a=new Array,s=function(t){a[t]=new Promise((function(i){if(3===n[t].ptype){var a=o.getlocalProduct(n[t].id_product),s={};null!=a.quantity_branch?(s=a.quantity_branch,null!=a.quantity_branch[e.id_branch]?s[e.id_branch]=s[e.id_branch]-n[t].quantity:s[e.id_branch]=-n[t].quantity):s[e.id_branch]=-n[t].quantity;var r=a.quantity-n[t].quantity;o.vhmongo_firebase.database().updateDoc("products",a._id,{quantity:r,quantity_branch:s}).then((function(){i(null)}))}else i(null)}))},r=0;r<n.length;r++)s(r);o.vhQuery.asyncPromiseAll(a).then((function(){i(t)}))}))}else if(2===e.bill_type||16===e.bill_type){s=new Array;(l=Object.assign({},e)).bill_code=a[0].bill_code,l.date=a[0].date,s[n.length]=o.vhmongo_firebase.database().updateDoc("bills",t,l);for(r=0;r<n.length;r++){(_=Object.assign({},n[r])).id_bill=t,a[0].bill_code&&(_.bill_code=a[0].bill_code),a[0].date&&(_.date=a[0].date),e.id_area&&(_.id_area=e.id_area),e.id_table&&(_.id_table=e.id_table),"number"==typeof e.tax&&(_.tax=e.tax),"number"==typeof e.bill_type&&(_.bill_type=e.bill_type),e.id_cashier&&(_.id_cashier=e.id_cashier),e.id_employee&&(_.id_employee=e.id_employee),e.id_supplier&&(_.id_supplier=e.id_supplier),e.id_customer&&(_.id_customer=e.id_customer),e.id_inventorytime&&(_.id_inventorytime=e.id_inventorytime),e.id_branch&&(_.id_branch=e.id_branch),s[r]=o.vhmongo_firebase.database().addDoc("vhbill_details",_)}Promise.all(s).then((function(){for(var a=new Array,s=function(t){a[t]=new Promise((function(i){if(3===n[t].ptype){var a=o.getlocalProduct(n[t].id_product),s={};null!=a.quantity_branch?(s=a.quantity_branch,null!=a.quantity_branch[e.id_branch]?s[e.id_branch]=s[e.id_branch]+n[t].quantity:s[e.id_branch]=n[t].quantity):s[e.id_branch]=n[t].quantity;var r=a.quantity+n[t].quantity;o.vhmongo_firebase.database().updateDoc("products",a._id,{quantity:r,quantity_branch:s}).then((function(){i(null)}))}else i(null)}))},r=0;r<n.length;r++)s(r);o.vhQuery.asyncPromiseAll(a).then((function(){i(t)}))}))}else if(9===e.bill_type){s=new Array;(l=Object.assign({},e)).bill_code=a[0].bill_code,l.date=a[0].date,s[n.length]=o.vhmongo_firebase.database().updateDoc("bills",t,l);for(r=0;r<n.length;r++){(_=Object.assign({},n[r])).id_bill=t,a[0].bill_code&&(_.bill_code=a[0].bill_code),a[0].date&&(_.date=a[0].date),e.id_area&&(_.id_area=e.id_area),e.id_table&&(_.id_table=e.id_table),"number"==typeof e.tax&&(_.tax=e.tax),"number"==typeof e.bill_type&&(_.bill_type=e.bill_type),e.id_cashier&&(_.id_cashier=e.id_cashier),e.id_employee&&(_.id_employee=e.id_employee),e.id_supplier&&(_.id_supplier=e.id_supplier),e.id_customer&&(_.id_customer=e.id_customer),e.id_inventorytime&&(_.id_inventorytime=e.id_inventorytime),e.id_branch&&(_.id_branch=e.id_branch),s[r]=o.vhmongo_firebase.database().addDoc("vhbill_details",_)}Promise.all(s).then((function(){for(var a=new Array,s=function(t){a[t]=new Promise((function(i){var a;if(3===n[t].ptype){var s=o.getlocalProduct(n[t].id_product),r={};null!=s.quantity_branch?(r=s.quantity_branch,null!=s.quantity_branch[e.id_branch]?r[e.id_branch]=r[e.id_branch]+n[t].quantity:r[e.id_branch]=n[t].quantity):r[e.id_branch]=n[t].quantity;var l=s.quantity+n[t].quantity,c={};null!=s[e.id_branch]&&null!=s[e.id_branch].inventory&&(c[e.id_branch]=s[e.id_branch],null===(a=c[e.id_branch])||void 0===a||delete a.inventory),o.vhmongo_firebase.database().updateDoc("products",s._id,Object.assign({quantity:l,quantity_branch:r},c)).then((function(){i(null)}))}else i(null)}))},r=0;r<n.length;r++)s(r);o.vhQuery.asyncPromiseAll(a).then((function(){i(t)}))}))}else if(5===e.bill_type||6===e.bill_type||13===e.bill_type||14===e.bill_type||15===e.bill_type||17===e.bill_type||20===e.bill_type||29===e.bill_type){var l;s=new Array;(l=Object.assign({},e)).bill_code=a[0].bill_code,l.date=a[0].date,s[n.length]=o.vhmongo_firebase.database().updateDoc("bills",t,l);for(r=0;r<n.length;r++){(_=Object.assign({},n[r])).id_bill=t,a[0].bill_code&&(_.bill_code=a[0].bill_code),a[0].date&&(_.date=a[0].date),e.id_area&&(_.id_area=e.id_area),e.id_table&&(_.id_table=e.id_table),"number"==typeof e.tax&&(_.tax=e.tax),"number"==typeof e.bill_type&&(_.bill_type=e.bill_type),e.id_cashier&&(_.id_cashier=e.id_cashier),e.id_employee&&(_.id_employee=e.id_employee),e.id_supplier&&(_.id_supplier=e.id_supplier),e.id_customer&&(_.id_customer=e.id_customer),e.id_inventorytime&&(_.id_inventorytime=e.id_inventorytime),e.id_branch&&(_.id_branch=e.id_branch),s[r]=o.vhmongo_firebase.database().addDoc("vhbill_details",_)}Promise.all(s).then((function(){i(t)}))}else if(3031===e.bill_type){var c=new Array,u=new Array,d=Object.assign({},a[0]);d.bill_type=30,u[n.length]=o.vhmongo_firebase.database().updateDoc("bills",t,d);for(r=0;r<n.length;r++){var _;(_=Object.assign({},n[r])).id_bill=t,a[0].bill_code&&(_.bill_code=a[0].bill_code),a[0].date&&(_.date=a[0].date),a[0].id_branch&&(_.id_branch=a[0].id_branch),"number"==typeof e.tax&&(_.tax=e.tax),_.bill_type=30,e.id_cashier&&(_.id_cashier=e.id_cashier),e.id_employee&&(_.id_employee=e.id_employee),e.id_supplier&&(_.id_supplier=e.id_supplier),e.id_customer&&(_.id_customer=e.id_customer),e.id_inventorytime&&(_.id_inventorytime=e.id_inventorytime),u[r]=o.vhmongo_firebase.database().addDoc("vhbill_details",_)}o.vhQuery.asyncPromiseAll(u).then((function(){for(var t=new Array,i=function(i){t[i]=new Promise((function(t){if(3===n[i].ptype){var a=o.getlocalProduct(n[i].id_product),s={};null!=a.quantity_branch?(s=a.quantity_branch,null!=a.quantity_branch[e.id_branch]?s[e.id_branch]=s[e.id_branch]-n[i].quantity:s[e.id_branch]=-n[i].quantity):s[e.id_branch]=-n[i].quantity;var r=a.quantity-n[i].quantity;o.vhmongo_firebase.database().updateDoc("products",a._id,{quantity:r,quantity_branch:s}).then((function(){t(null)}))}else t(null)}))},a=0;a<n.length;a++)i(a);c[0]=o.vhQuery.asyncPromiseAll(t)}));var p=new Array,b=Object.assign({},e);null==b||delete b.id_branch_receive,b.bill_type=31,b.bill_code=a[0].bill_code,b.id_branch=a[0].id_branch_receive,b.id_branch_send=a[0].id_branch,b.date=a[0].date,o.vhmongo_firebase.database().addDoc("bills",b).then((function(t){for(var i=0;i<n.length;i++){var s=Object.assign({},n[i]);s.id_bill=t._id,a[0].bill_code&&(s.bill_code=a[0].bill_code),a[0].date&&(s.date=a[0].date),a[0].id_branch&&(s.id_branch=a[0].id_branch_receive),"number"==typeof e.tax&&(s.tax=e.tax),s.bill_type=31,e.id_cashier&&(s.id_cashier=e.id_cashier),e.id_employee&&(s.id_employee=e.id_employee),e.id_supplier&&(s.id_supplier=e.id_supplier),e.id_customer&&(s.id_customer=e.id_customer),e.id_inventorytime&&(s.id_inventorytime=e.id_inventorytime),p[i]=o.vhmongo_firebase.database().addDoc("vhbill_details",s)}o.vhQuery.asyncPromiseAll(p).then((function(){for(var t=new Array,i=function(i){t[i]=new Promise((function(t){if(3===n[i].ptype){var a=o.getlocalProduct(n[i].id_product),s={};null!=a.quantity_branch?(s=a.quantity_branch,null!=a.quantity_branch[e.id_branch]?s[e.id_branch]=s[e.id_branch]+n[i].quantity:s[e.id_branch]=n[i].quantity):s[e.id_branch]=n[i].quantity;var r=a.quantity+n[i].quantity;o.vhmongo_firebase.database().updateDoc("products",a._id,{quantity:r,quantity_branch:s}).then((function(){t(null)}))}else t(null)}))},a=0;a<n.length;a++)i(a);c[1]=o.vhQuery.asyncPromiseAll(t)}))}),(function(t){console.log("error",t)})),o.vhQuery.asyncPromiseAll(c).then((function(){i(t)}))}}))}))},t.prototype.deleteBill_Billdetail=function(t){var e=this;return new Promise((function(n,o){var i=e.vhmongo_firebase.database().getDoc("bills",t),a=e.vhmongo_firebase.database().getDocsByFields("vhbill_details",{id_bill:{$eq:t}},{},{},0);e.vhQuery.asyncPromiseAll([i,a]).then((function(i){var a=new Array;if(!i[0])return o({message:"id_bill "+t+" không tồn tại"});if(1===i[0].bill_type){for(var s=0;s<i[1].length;s++)a[s]=e.vhmongo_firebase.database().deleteDoc("vhbill_details",i[1][s]._id);a[i[1].length]=e.vhmongo_firebase.database().deleteDoc("bills",t)}else if(2===i[0].bill_type){for(s=0;s<i[1].length;s++)a[s]=e.vhmongo_firebase.database().deleteDoc("vhbill_details",i[1][s]._id);a[i[1].length]=e.vhmongo_firebase.database().deleteDoc("bills",t)}else if(3===i[0].bill_type){for(s=0;s<i[1].length;s++)a[s]=e.vhmongo_firebase.database().deleteDoc("vhbill_details",i[1][s]._id);a[i[1].length]=e.vhmongo_firebase.database().deleteDoc("bills",t)}else if(9===i[0].bill_type){for(s=0;s<i[1].length;s++)a[s]=e.vhmongo_firebase.database().deleteDoc("vhbill_details",i[1][s]._id);a[i[1].length]=e.vhmongo_firebase.database().deleteDoc("bills",t)}else if(10===i[0].bill_type){for(s=0;s<i[1].length;s++)a[s]=e.vhmongo_firebase.database().deleteDoc("vhbill_details",i[1][s]._id);a[i[1].length]=e.vhmongo_firebase.database().deleteDoc("bills",t)}else if(16===i[0].bill_type){for(s=0;s<i[1].length;s++)a[s]=e.vhmongo_firebase.database().deleteDoc("vhbill_details",i[1][s]._id);a[i[1].length]=e.vhmongo_firebase.database().deleteDoc("bills",t)}else{if(5!==i[0].bill_type&&6!==i[0].bill_type&&13!==i[0].bill_type&&14!==i[0].bill_type&&15!==i[0].bill_type&&17!==i[0].bill_type&&20!==i[0].bill_type&&29!==i[0].bill_type)return 7===i[0].bill_type||8===i[0].bill_type||11===i[0].bill_type||12===i[0].bill_type?o({message:"Loại bill_type "+i[0].bill_type+"này không phát sinh bill_detail dùng hàm deleteBill xóa"}):o({message:"Loại bill_type "+i[0].bill_type+" này không thể xóa hoặc liên hệ anh Huy"});for(s=0;s<i[1].length;s++)a[s]=e.vhmongo_firebase.database().deleteDoc("vhbill_details",i[1][s]._id);a[i[1].length]=e.vhmongo_firebase.database().deleteDoc("bills",t)}1===i[0].bill_type||3===i[0].bill_type||10===i[0].bill_type?e.vhQuery.asyncPromiseAll(a).then((function(){for(var t=new Array,o=function(n){t[n]=new Promise((function(t){if(3===i[1][n].ptype){var o=e.getlocalProduct(i[1][n].id_product),a={};null!=o.quantity_branch?(a=o.quantity_branch,null!=o.quantity_branch[i[0].id_branch]?a[i[0].id_branch]=a[i[0].id_branch]+i[1][n].quantity:a[i[0].id_branch]=i[1][n].quantity):a[i[0].id_branch]=i[1][n].quantity;var s=o.quantity+i[1][n].quantity;e.vhmongo_firebase.database().updateDoc("products",o._id,{quantity:s,quantity_branch:a}).then((function(){t(null)}))}else t(null)}))},a=0;a<i[1].length;a++)o(a);e.vhQuery.asyncPromiseAll(t).then((function(){n(!0)}))})):2===i[0].bill_type||14===i[0].bill_type?e.vhQuery.asyncPromiseAll(a).then((function(){for(var t=new Array,o=function(n){t[n]=new Promise((function(t){if(3===i[1][n].ptype){var o=e.getlocalProduct(i[1][n].id_product),a={};null!=o.quantity_branch?(a=o.quantity_branch,null!=o.quantity_branch[i[0].id_branch]?a[i[0].id_branch]=a[i[0].id_branch]-i[1][n].quantity:a[i[0].id_branch]=-i[1][n].quantity):a[i[0].id_branch]=-i[1][n].quantity;var s=o.quantity-i[1][n].quantity;e.vhmongo_firebase.database().updateDoc("products",o._id,{quantity:s,quantity_branch:a}).then((function(){t(null)}))}else t(null)}))},a=0;a<i[1].length;a++)o(a);e.vhQuery.asyncPromiseAll(t).then((function(){n(null)}))})):9===i[0].bill_type?e.vhQuery.asyncPromiseAll(a).then((function(){for(var t=new Array,o=function(n){t[n]=new Promise((function(t){var o;if(3===i[1][n].ptype){var a=e.getlocalProduct(i[1][n].id_product),s={};null!=a.quantity_branch?(s=a.quantity_branch,null!=a.quantity_branch[i[0].id_branch]?s[i[0].id_branch]=s[i[0].id_branch]-i[1][n].quantity:s[i[0].id_branch]=-i[1][n].quantity):s[i[0].id_branch]=-i[1][n].quantity;var r=a.quantity-i[1][n].quantity,l={};null!=a[i[0].id_branch]&&null!=a[i[0].id_branch].inventory&&(l[i[0].id_branch]=a[i[0].id_branch],null===(o=l[i[0].id_branch])||void 0===o||delete o.inventory),e.vhmongo_firebase.database().updateDoc("products",a._id,Object.assign({quantity:r,quantity_branch:s},l)).then((function(){t(null)}))}else t(null)}))},a=0;a<i[1].length;a++)o(a);e.vhQuery.asyncPromiseAll(t).then((function(){n(null)}))})):e.vhQuery.asyncPromiseAll(a).then((function(){n(!0)}))}),(function(t){console.log("error",t),o(t)}))}))},t.prototype.getBill_details=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("vhbill_details",{id_bill:{$eq:t}},{},{},0).then((function(t){var e=new Array;if(t.length>0)for(var o=0;o<t.length;o++){var i=Object.assign({},t[o]);null==i||delete i.bill_code,null==i||delete i.date,null==i||delete i.tax,null==i||delete i.bill_type,null==i||delete i.id_cashier,null==i||delete i.id_employee,null==i||delete i.id_supplier,null==i||delete i.id_customer,null==i||delete i.id_inventorytime,null==i||delete i.id_branch,e.push(i)}n(e)}),(function(t){o(t)}))}))},t.prototype.getBill_detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("vhbill_details",t).then((function(t){if(t){var e=Object.assign({},t);null==e||delete e.bill_code,null==e||delete e.date,null==e||delete e.id_area,null==e||delete e.id_table,null==e||delete e.tax,null==e||delete e.bill_type,null==e||delete e.id_cashier,null==e||delete e.id_employee,null==e||delete e.id_supplier,null==e||delete e.id_customer,null==e||delete e.id_inventorytime,null==e||delete e.id_branch,n(e)}else n(t)}),(function(t){o(t)}))}))},t.prototype.createBill_Detail=function(t){var e=this;return new Promise((function(n,o){t.id_bill?e.vhmongo_firebase.database().getDoc("bills",t.id_bill).then((function(i){var a=t;i.bill_code&&(a.bill_code=i.bill_code),i.id_table&&(a.id_table=i.id_table),i.id_branch&&(a.id_branch=i.id_branch),"number"==typeof i.bill_type&&(a.bill_type=i.bill_type),e.vhmongo_firebase.database().addDoc("vhbill_details",a).then((function(t){n(t)}),(function(t){o(t)}))}),(function(t){console.log("error",t)})):console.log("error","không tồn tại id_bill trong data")}))},t.prototype.updateBill_Detail=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("vhbill_details",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteBill_Detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("vhbill_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getBill=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("bills",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getBills=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.database().getDocsByFields("bills",t,{},n,o).then((function(t){e(t)})).catch((function(t){a(t)}))}))},t.prototype.getBills_byFields=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.database().getDocsByFields("bills",t,{},n,o).then((function(t){e(t)})).catch((function(t){a(t)}))}))},t.prototype.createBill=function(t){var e=this;return new Promise((function(n,o){e.sync_code=Math.random().toString(36).substr(2,10).toUpperCase(),t.sync_code=e.sync_code,e.vhmongo_firebase.database().addDoc("bills",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateBill=function(t,e){var n=this;return new Promise((function(o,i){n.sync_code=Math.random().toString(36).substr(2,10).toUpperCase(),e.sync_code=n.sync_code,"3334"===(null==e?void 0:e.bill_type)?n.vhmongo_firebase.database().getDoc("bills",t).then((function(a){32===a.bill_type?n.vhmongo_firebase.database().getDoc("bills",t).then((function(a){var s=new Array;s[0]=n.vhmongo_firebase.database().updateDoc("bills",t,{bill_type:33,sync_code:n.sync_code});var r=Object.assign({},e);null==r||delete r.id_branch_receive,r.bill_type=34,r.bill_code=a.bill_code,r.id_branch=a.id_branch_receive,r.id_branch_send=a.id_branch,r.date=a.date,s[1]=n.vhmongo_firebase.database().addDoc("bills",r),Promise.all(s).then((function(){o(!0)})).catch((function(t){i(t)}))})):i("Lưu không thành công, vui lòng kiểm tra lại.")})):n.vhmongo_firebase.database().updateDoc("bills",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteBill=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("bills",t).then((function(i){if(i){var a=void 0;(7===i.bill_type||8===i.bill_type||11===i.bill_type||12===i.bill_type||32===i.bill_type)&&(a=e.vhmongo_firebase.database().deleteDoc("bills",t)),a.then((function(t){return n(t)}))}else o({message:t+" no exist"})}))}))},t.prototype.observableSyncOpeningBill=function(t,e){var n=this;return new c.Observable((function(o){var i=0;n.callbacksyncopeningbill=n.vhmongo_firebase.socketMongoDB().initSyncOpeningBill(t).subscribe((function(t){if(t.exists)if(t.data().sync_code!=n.sync_code)if(t.data().bill_type===e){if(i++){var a=Object.assign(Object.assign({},n.vhmongo_firebase.database().cvtDataFB2MG(t.data())),{_id:t.id});o.next({vcode:0,message:"repaired bill",data:a})}}else o.next({vcode:1,message:"changed bill_type"});else i++;else o.next({vcode:2,message:"deleted bill by unknown device"})}))}))},t.prototype.closeSyncOpeningBill=function(){this.callbacksyncopeningbill.unsubscribe(),this.vhmongo_firebase.socketMongoDB().closeSyncOpeningBill()},t.prototype.createPaymentVnpay=function(t,e,n,o){this.vhmongo_firebase.paymentVNPAY().createPaymentVnpay(t,e,n,o).then((function(t){window.location=t.data}),(function(t){console.log("error",t)}))},t.prototype.createPaymentVnpay_Mobile=function(t,e,n,o,i){var a=this;return new Promise((function(i,s){a.vhmongo_firebase.paymentVNPAY().createPaymentVnpay(t,e,n,o).then((function(t){i(t.data)}),(function(t){console.log("error",t),s(t)}))}))},t.prototype.createPayment=function(t){var e=this;return new Promise((function(n,o){t.payment_code=e.vhAlgorithm.createPaymentCode(null==t?void 0:t.date),t.id_store=e.vhmongo_firebase.auth().getDatabase(),e.vhmongo_firebase.rootdatabase().addDoc("payments",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updatePayment=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.rootdatabase().updateDoc("payments",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deletePayment=function(t){var e=this;return new Promise((function(n,o){var i={id_payment:{$eq:t}};e.vhmongo_firebase.rootdatabase().getDocsByFields("payment_details",i,{},{},0).then((function(t){if(t.length>0)for(var n=0;n<t.length;n++)e.vhmongo_firebase.rootdatabase().deleteDoc("payment_details",t[n]._id)}),(function(t){console.log(t,t)})),e.vhmongo_firebase.rootdatabase().deleteDoc("payments",t).then((function(t){n(t)}),(function(t){console.log(t,t)}))}))},t.prototype.getPayments=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.rootdatabase().getDocsByFields("payments",t,{},n,o).then((function(t){e(t)}),(function(t){console.log(t,t)}))}))},t.prototype.getPayment=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.rootdatabase().getDoc("payments",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.createPayment_Detail=function(t){var e=this;return new Promise((function(n,o){null!=t.id_payment&&null!=t.id_payment?e.vhmongo_firebase.rootdatabase().getDoc("payments",t.id_payment).then((function(i){var a=t;a.activating=!1,a.invalid=!1,a.date=i.date,i.id_store&&(a.id_store=i.id_store),"number"==typeof i.payment_type&&(a.payment_type=i.payment_type),e.vhmongo_firebase.rootdatabase().addDoc("payment_details",a).then((function(t){n(t)}),(function(t){o(t)}))}),(function(t){console.log("error",t)})):console.log("error","không tồn tại id_bill trong data")}))},t.prototype.updatePayment_Detail=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.rootdatabase().updateDoc("payment_details",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.getPayment_details=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.rootdatabase().getDocsByFields("payment_details",t,{},n,o).then((function(t){e(t)}),(function(t){console.log(t,t)}))}))},t.prototype.getPayment_detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.rootdatabase().getDoc("payment_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.deletePayment_Detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.rootdatabase().deleteDoc("payment_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPackage=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.rootdatabase().getDoc("packages",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.publishObservableEventPromotions=function(){this.subjectpromotions.next(this.promotions)},t.prototype.observableLocalPromotions=function(){return this.subjectpromotions},t.prototype.getObservableLocalPromotions=function(){var t=this;return new c.Observable((function(e){t.observableLocalPromotions().subscribe((function(t){e.next(t)})),t.publishObservableEventPromotions()}))},t.prototype.getlocalPromotion=function(t){for(var e=0;e<this.promotions.length;e++)if(this.promotions[e]._id===t)return this.suppliers[e];return null},t.prototype.getlocalPromotions=function(){return this.promotions},t.prototype.refreshLocalPromotions=function(){return new Promise((function(t,e){t(null)}))},t.prototype.addPromotion=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("promotions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updatePromotion=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("promotions",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deletePromotion=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("promotions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPromotion=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("promotions",t).then((function(t){n(t)}))}))},t.prototype.getPromotions=function(){var t=this;return new Promise((function(e){t.vhmongo_firebase.database().getDocs("promotions").then((function(n){t.promotions=n,e(n)}))}))},t.prototype.addPromotion_detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("promotion_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updatePromotion_detail=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("promotion_details",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deletePromotion_detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("promotion_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPromotion_detail=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("promotion_details",t).then((function(t){n(t)}))}))},t.prototype.getPromotion_details=function(){var t=this;return new Promise((function(e){t.vhmongo_firebase.database().getDocs("promotion_details").then((function(t){e(t)}))}))},t.prototype.addPromotion_Promotiondetail=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().addDoc("promotions",t).then((function(t){for(var a=new Array,s=0;s<e.length;s++){var r=e[s];r.id_promotion=t._id,a[s]=n.vhmongo_firebase.database().addDoc("promotion_details",r)}Promise.all(a).then((function(){o(t)})).catch((function(t){i(t)}))}),(function(t){i(t)}))}))},t.prototype.updatePromotion_Promotiondetail=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.database().getDocsByFields("promotion_details",{id_promotion:{$eq:t}},{},{},0).then((function(s){for(var r=new Array,l=0;l<s.length;l++)r[l]=o.vhmongo_firebase.database().deleteDoc("promotion_details",s[l]._id);var c=Object.assign({},e);r[s.length]=o.vhmongo_firebase.database().updateDoc("promotions",t,c);for(l=0;l<n.length;l++){var u=n[l];u.id_promotion=t,r[l+s.length+1]=o.vhmongo_firebase.database().addDoc("promotion_details",u)}Promise.all(r).then((function(){i(!0)})).catch((function(t){a(t)}))})).catch((function(){i(!1)}))}))},t.prototype.deletePromotion_Promotiondetail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("promotion_details",{id_promotion:{$eq:t}},{},{},0).then((function(i){for(var a=new Array,s=0;s<i.length;s++)a[s]=e.vhmongo_firebase.database().deleteDoc("promotion_details",i[s]._id);a[i.length]=e.vhmongo_firebase.database().deleteDoc("promotions",t),Promise.all(a).then((function(){n(!0)})).catch((function(t){o(t)}))})).catch((function(){n(!1)}))}))},t.prototype.getPromotion_details_byId_promotion=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDocsByFields("promotion_details",{id_promotion:{$eq:t}},{},{},0).then((function(t){n(t)})).catch((function(){n(!1)}))}))},t.prototype.checkNewPromotion=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.database().getDocs("promotions").then((function(s){var r=new Array,l=new Array;if(s.length>0){for(var c=0;c<s.length;c++)new Date(t)<new Date(s[c].date_start)?new Date(e)>=new Date(s[c].date_start)&&r.push(s[c]._id):new Date(t)>=new Date(s[c].date_start)&&new Date(t)<=new Date(s[c].date_end)&&r.push(s[c]._id);r.length>0?o.vhmongo_firebase.database().getDocsByFields("promotion_details",{id_promotion:{$in:r}},{},{},0).then((function(t){if(t.length){for(var e=0;e<n.length;e++)for(var o=0;o<t.length;o++)if(n[e]===t[o].id_product){l.push(n[e]);break}i(l)}else i(l)})).catch((function(t){a(t)})):i(l)}else i(l)}),(function(t){console.log("error",t)}))}))},t.prototype.checkOldPromotion=function(t,e,n,o){var i=this;return new Promise((function(a,s){i.vhmongo_firebase.database().getDocs("promotions").then((function(s){var r=new Array,l=new Array;if(s.length>0){for(var c=0;c<s.length;c++)new Date(t)<new Date(s[c].date_start)?new Date(e)>=new Date(s[c].date_start)&&s[c]._id!=o&&r.push(s[c]._id):new Date(t)>=new Date(s[c].date_start)&&new Date(t)<=new Date(s[c].date_end)&&s[c]._id!=o&&r.push(s[c]._id);r.length>0?i.vhmongo_firebase.database().getDocsByFields("promotion_details",{id_promotion:{$in:r}},{},{},0).then((function(t){if(t.length>0){for(var e=0;e<n.length;e++)for(var o=0;o<t.length;o++)if(n[e]===t[o].id_product){l.push(n[e]);break}a(l)}else a(l)}),(function(t){console.log("error",t)})):a(l)}else a(l)}))}))},t.prototype.publishObservableEventAppSettingNameStations=function(){this.subjectappsettingstations.next()},t.prototype.observableLocalAppSettingNameStations=function(){return this.subjectappsettingstations},t.prototype.getObservableLocalAppSettingNameStations=function(){var t=this;return new c.Observable((function(e){t.observableLocalAppSettingNameStations().subscribe((function(){e.next(null)})),t.publishObservableEventAppSettingNameStations()}))},t.prototype.getLocalAppSettingNameStations=function(){for(var t=new Array,e=0;e<this.appsettingstations.length;e++)t.push(this.appsettingstations[e].appsetting_name);return t},t.prototype.getLocalAppSettingNameStation=function(t){for(var e={},n=0;n<this.appsettingstations.length;n++)if(this.appsettingstations[n].appsetting_name===t){delete(e=Object.assign({},this.appsettingstations[n]))._id,delete e.appsetting_name;break}return e},t.prototype.getLocalAppSettingStation=function(t){for(var e=0;e<this.appsettingstations.length;e++)if(this.appsettingstations[e]._id===t)return this.appsettingstations[e];return null},t.prototype.refreshLocalAppSettingNameStations=function(){return new Promise((function(t,e){t(null)}))},t.prototype.getAppSettingStations=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocsByFields("appsettingstations",{uuid:{$eq:t.hwinfo.uuid}},{},{},0).then((function(n){n.length>0&&(t.appsettingstations=n),e(null)}),(function(t){n(t)}))}))},t.prototype.updateAppSettingNameStation=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().getDocsByFields("appsettingstations",{appsetting_name:{$eq:t},uuid:{$eq:n.hwinfo.uuid}},{},{},0).then((function(a){if(a.length>0)n.vhmongo_firebase.database().updateDoc("appsettingstations",a[0]._id,e).then((function(t){o(t)}),(function(t){i(t)}));else{var s=Object.assign({},e);s.appsetting_name=t,s.uuid=n.hwinfo.uuid,n.vhmongo_firebase.database().addDoc("appsettingstations",s).then((function(){o(!0)}),(function(t){i(t)}))}}))}))},t.prototype.deleteAppSettingNameStation=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("appsettingstations",{appsetting_name:{$eq:t},uuid:{$eq:e.hwinfo.uuid}},{},{},0).then((function(t){t.length>0?e.vhmongo_firebase.database().deleteDoc("appsettingstations",t[0]._id).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}))}))},t.prototype.publishObservableEventAppSettingNameBranchs=function(){this.subjectappsettingbranchs.next()},t.prototype.observableLocalAppSettingNameBranchs=function(){return this.subjectappsettingbranchs},t.prototype.getObservableLocalAppSettingNameBranchs=function(){var t=this;return new c.Observable((function(e){t.observableLocalAppSettingNameBranchs().subscribe((function(){e.next(null)})),t.publishObservableEventAppSettingNameBranchs()}))},t.prototype.getLocalAppSettingNameBranchs=function(){for(var t=new Array,e=0;e<this.appsettingbranchs.length;e++)t.push(this.appsettingbranchs[e].appsetting_name);return t},t.prototype.getLocalAppSettingNameBranch=function(t){for(var e={},n=0;n<this.appsettingbranchs.length;n++)if(this.appsettingbranchs[n].appsetting_name===t){delete(e=Object.assign({},this.appsettingbranchs[n]))._id,delete e.appsetting_name;break}return e},t.prototype.getLocalAppSettingBranch=function(t){for(var e=0;e<this.appsettingbranchs.length;e++)if(this.appsettingbranchs[e]._id===t)return this.appsettingbranchs[e];return null},t.prototype.updateAppSettingNameBranch=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().getDocsByFields("appsettingbranchs",{appsetting_name:{$eq:t},id_branch:{$eq:n.getDefaultBranch()._id}},{},{},1).then((function(a){if(a.length>0)n.vhmongo_firebase.database().updateDoc("appsettingbranchs",a[0]._id,e).then((function(t){o(t)}),(function(t){i(t)}));else{var s=Object.assign({},e);s.appsetting_name=t,s.id_branch=n.getDefaultBranch()._id,n.vhmongo_firebase.database().addDoc("appsettingbranchs",s).then((function(){o(!0)}),(function(t){i(t)}))}}))}))},t.prototype.deleteAppSettingNameBranch=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("appsettingbranchs",{appsetting_name:{$eq:t},id_branch:{$eq:e.getDefaultBranch()._id}},{},{},0).then((function(t){t.length>0?e.vhmongo_firebase.database().deleteDoc("appsettingbranchs",t[0]._id).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}))}))},t.prototype.getDiscount_bill_byCustomer=function(t,e){for(var n=this.getlocalCustomer(e),o=this.getlocalDiscount_bills(),i=null,a=0;a<o.length;a++)if(o[a]._id===n.id_discount_bill){i={discount:0},1===o[a].method?(0!=o[a].level5.sales||0!=o[a].level5.discount)&&t>=o[a].level5.sales?1===o[a].type?(i.discount=i.discount+(o[a].level2.sales-o[a].level1.sales)*o[a].level1.discount/100,i.discount=i.discount+(o[a].level3.sales-o[a].level2.sales)*o[a].level2.discount/100,i.discount=i.discount+(o[a].level4.sales-o[a].level3.sales)*o[a].level3.discount/100,i.discount=i.discount+(o[a].level5.sales-o[a].level4.sales)*o[a].level4.discount/100,i.discount=i.discount+(t-o[a].level5.sales)*o[a].level5.discount/100):2===o[a].type&&(i.discount=o[a].level1.discount,i.discount=i.discount+o[a].level2.discount,i.discount=i.discount+o[a].level3.discount,i.discount=i.discount+o[a].level4.discount,i.discount=i.discount+o[a].level5.discount):(0!=o[a].level4.sales||0!=o[a].level4.discount)&&t>=o[a].level4.sales?1===o[a].type?(i.discount=i.discount+(o[a].level2.sales-o[a].level1.sales)*o[a].level1.discount/100,i.discount=i.discount+(o[a].level3.sales-o[a].level2.sales)*o[a].level2.discount/100,i.discount=i.discount+(o[a].level4.sales-o[a].level3.sales)*o[a].level3.discount/100,i.discount=i.discount+(t-o[a].level4.sales)*o[a].level4.discount/100):2===o[a].type&&(i.discount=o[a].level1.discount,i.discount=i.discount+o[a].level2.discount,i.discount=i.discount+o[a].level3.discount,i.discount=i.discount+o[a].level4.discount):(0!=o[a].level3.sales||0!=o[a].level3.discount)&&t>=o[a].level3.sales?1===o[a].type?(i.discount=i.discount+(o[a].level2.sales-o[a].level1.sales)*o[a].level1.discount/100,i.discount=i.discount+(o[a].level3.sales-o[a].level2.sales)*o[a].level2.discount/100,i.discount=i.discount+(t-o[a].level3.sales)*o[a].level3.discount/100):2===o[a].type&&(i.discount=o[a].level1.discount,i.discount=i.discount+o[a].level2.discount,i.discount=i.discount+o[a].level3.discount):(0!=o[a].level2.sales||0!=o[a].level2.discount)&&t>=o[a].level2.sales?1===o[a].type?(i.discount=i.discount+(o[a].level2.sales-o[a].level1.sales)*o[a].level1.discount/100,i.discount=i.discount+(t-o[a].level2.sales)*o[a].level2.discount/100):2===o[a].type&&(i.discount=o[a].level1.discount,i.discount=i.discount+o[a].level2.discount):(0!=o[a].level1.sales||0!=o[a].level1.discount)&&t>=o[a].level1.sales&&(1===o[a].type?i.discount=i.discount+(t-o[a].level1.sales)*o[a].level1.discount/100:2===o[a].type&&(i.discount=o[a].level1.discount)):2===o[a].method&&((0!=o[a].level5.sales||0!=o[a].level5.discount)&&t>=o[a].level5.sales?1===o[a].type?i.discount=t*o[a].level5.discount/100:2===o[a].type&&(i.discount=o[a].level5.discount):(0!=o[a].level4.sales||0!=o[a].level4.discount)&&t>=o[a].level4.sales?1===o[a].type?i.discount=t*o[a].level4.discount/100:2===o[a].type&&(i.discount=o[a].level4.discount):(0!=o[a].level3.sales||0!=o[a].level3.discount)&&t>=o[a].level3.sales?1===o[a].type?i.discount=t*o[a].level3.discount/100:2===o[a].type&&(i.discount=o[a].level3.discount):(0!=o[a].level2.sales||0!=o[a].level2.discount)&&t>=o[a].level2.sales?1===o[a].type?i.discount=t*o[a].level2.discount/100:2===o[a].type&&(i.discount=o[a].level2.discount):(0!=o[a].level1.sales||0!=o[a].level1.discount)&&t>=o[a].level1.sales&&(1===o[a].type?i.discount=t*o[a].level1.discount/100:2===o[a].type&&(i.discount=o[a].level1.discount)));break}return i},t.prototype.getDiscount_bill_byCustomer_new=function(t,e){for(var n=this.getlocalCustomer(e),o=this.getlocalDiscount_bills(),i=this.getlocalCustomerClasss(),a=null,s=0;s<i.length;s++)if(i[s]._id===n.id_customer_class&&null!=i[s].id_discount_bill&&null!=i[s].id_discount_bill)for(var r=0;r<o.length;r++)if(o[r]._id===i[s].id_discount_bill){a={discount:0},1===o[r].method?(0!=o[r].level5.sales||0!=o[r].level5.discount)&&t>=o[r].level5.sales?1===o[r].type?(a.discount=a.discount+(o[r].level2.sales-o[r].level1.sales)*o[r].level1.discount/100,a.discount=a.discount+(o[r].level3.sales-o[r].level2.sales)*o[r].level2.discount/100,a.discount=a.discount+(o[r].level4.sales-o[r].level3.sales)*o[r].level3.discount/100,a.discount=a.discount+(o[r].level5.sales-o[r].level4.sales)*o[r].level4.discount/100,a.discount=a.discount+(t-o[r].level5.sales)*o[r].level5.discount/100):2===o[r].type&&(a.discount=o[r].level1.discount,a.discount=a.discount+o[r].level2.discount,a.discount=a.discount+o[r].level3.discount,a.discount=a.discount+o[r].level4.discount,a.discount=a.discount+o[r].level5.discount):(0!=o[r].level4.sales||0!=o[r].level4.discount)&&t>=o[r].level4.sales?1===o[r].type?(a.discount=a.discount+(o[r].level2.sales-o[r].level1.sales)*o[r].level1.discount/100,a.discount=a.discount+(o[r].level3.sales-o[r].level2.sales)*o[r].level2.discount/100,a.discount=a.discount+(o[r].level4.sales-o[r].level3.sales)*o[r].level3.discount/100,a.discount=a.discount+(t-o[r].level4.sales)*o[r].level4.discount/100):2===o[r].type&&(a.discount=o[r].level1.discount,a.discount=a.discount+o[r].level2.discount,a.discount=a.discount+o[r].level3.discount,a.discount=a.discount+o[r].level4.discount):(0!=o[r].level3.sales||0!=o[r].level3.discount)&&t>=o[r].level3.sales?1===o[r].type?(a.discount=a.discount+(o[r].level2.sales-o[r].level1.sales)*o[r].level1.discount/100,a.discount=a.discount+(o[r].level3.sales-o[r].level2.sales)*o[r].level2.discount/100,a.discount=a.discount+(t-o[r].level3.sales)*o[r].level3.discount/100):2===o[r].type&&(a.discount=o[r].level1.discount,a.discount=a.discount+o[r].level2.discount,a.discount=a.discount+o[r].level3.discount):(0!=o[r].level2.sales||0!=o[r].level2.discount)&&t>=o[r].level2.sales?1===o[r].type?(a.discount=a.discount+(o[r].level2.sales-o[r].level1.sales)*o[r].level1.discount/100,a.discount=a.discount+(t-o[r].level2.sales)*o[r].level2.discount/100):2===o[r].type&&(a.discount=o[r].level1.discount,a.discount=a.discount+o[r].level2.discount):(0!=o[r].level1.sales||0!=o[r].level1.discount)&&t>=o[r].level1.sales&&(1===o[r].type?a.discount=a.discount+(t-o[r].level1.sales)*o[r].level1.discount/100:2===o[r].type&&(a.discount=o[r].level1.discount)):2===o[r].method&&((0!=o[r].level5.sales||0!=o[r].level5.discount)&&t>=o[r].level5.sales?1===o[r].type?a.discount=t*o[r].level5.discount/100:2===o[r].type&&(a.discount=o[r].level5.discount):(0!=o[r].level4.sales||0!=o[r].level4.discount)&&t>=o[r].level4.sales?1===o[r].type?a.discount=t*o[r].level4.discount/100:2===o[r].type&&(a.discount=o[r].level4.discount):(0!=o[r].level3.sales||0!=o[r].level3.discount)&&t>=o[r].level3.sales?1===o[r].type?a.discount=t*o[r].level3.discount/100:2===o[r].type&&(a.discount=o[r].level3.discount):(0!=o[r].level2.sales||0!=o[r].level2.discount)&&t>=o[r].level2.sales?1===o[r].type?a.discount=t*o[r].level2.discount/100:2===o[r].type&&(a.discount=o[r].level2.discount):(0!=o[r].level1.sales||0!=o[r].level1.discount)&&t>=o[r].level1.sales&&(1===o[r].type?a.discount=t*o[r].level1.discount/100:2===o[r].type&&(a.discount=o[r].level1.discount)));break}return a},t.prototype.getReportDiscount_sales_Customers=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Array;if("all"===n)r=i.getlocalCustomers();else{var l=i.getlocalCustomer(n);r.push(l)}var c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,discount_btax:0,discount_atax:0};if(r.length>0){var u=void 0;u="all"===n?"all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$gte:t,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1]},id_branch:{$eq:o}};var d=i.vhmongo_firebase.database().getDocsByFields("discount_saless",{},{},{},0),_=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0);Promise.all([d,_]).then((function(t){var e,n=t[0],o=t[1];if(o.length>0)for(var i=0;i<r.length;i++){for(var s=!1,l={id_customer:r[i]._id,name:r[i].name,img:null===(e=r[i])||void 0===e?void 0:e.img,sales_btax:0,sales_atax:0,quantity:0,discount_btax:0,discount_atax:0,discount_name:""},u=0;u<o.length;u++)if(r[i]._id===o[u].id_customer)if(s=!0,5===o[u].ptype){if(null!=o[u].combos)for(var d=0;d<o[u].combos.length;d++)l.quantity=l.quantity+o[u].combos[d].quantity*o[u].quantity,l.sales_btax=l.sales_btax+o[u].combos[d].price*o[u].combos[d].quantity*o[u].quantity,l.sales_atax=l.sales_atax+o[u].combos[d].price*o[u].combos[d].quantity*o[u].quantity*(1+o[u].tax/100)}else l.quantity=l.quantity+o[u].quantity,l.sales_btax=l.sales_btax+o[u].price*o[u].quantity,l.sales_atax=l.sales_atax+o[u].price*o[u].quantity*(1+o[u].tax/100);if(s&&null!=r[i].id_discount_sales&&null!=r[i].id_discount_sales)for(var _=0;_<n.length;_++)if(n[_]._id===r[i].id_discount_sales){l.discount_name=n[_].name,1===n[_].method?(0!=n[_].level5.sales||0!=n[_].level5.discount)&&l.sales_btax>=n[_].level5.sales?1===n[_].type?(l.discount_btax=l.discount_btax+(n[_].level2.sales-n[_].level1.sales)*n[_].level1.discount/100,l.discount_btax=l.discount_btax+(n[_].level3.sales-n[_].level2.sales)*n[_].level2.discount/100,l.discount_btax=l.discount_btax+(n[_].level4.sales-n[_].level3.sales)*n[_].level3.discount/100,l.discount_btax=l.discount_btax+(n[_].level5.sales-n[_].level4.sales)*n[_].level4.discount/100,l.discount_btax=l.discount_btax+(l.sales_btax-n[_].level5.sales)*n[_].level5.discount/100):2===n[_].type&&(l.discount_btax=n[_].level1.discount,l.discount_btax=l.discount_btax+n[_].level2.discount,l.discount_btax=l.discount_btax+n[_].level3.discount,l.discount_btax=l.discount_btax+n[_].level4.discount,l.discount_btax=l.discount_btax+n[_].level5.discount):(0!=n[_].level4.sales||0!=n[_].level4.discount)&&l.sales_btax>=n[_].level4.sales?1===n[_].type?(l.discount_btax=l.discount_btax+(n[_].level2.sales-n[_].level1.sales)*n[_].level1.discount/100,l.discount_btax=l.discount_btax+(n[_].level3.sales-n[_].level2.sales)*n[_].level2.discount/100,l.discount_btax=l.discount_btax+(n[_].level4.sales-n[_].level3.sales)*n[_].level3.discount/100,l.discount_btax=l.discount_btax+(l.sales_btax-n[_].level4.sales)*n[_].level4.discount/100):2===n[_].type&&(l.discount_btax=n[_].level1.discount,l.discount_btax=l.discount_btax+n[_].level2.discount,l.discount_btax=l.discount_btax+n[_].level3.discount,l.discount_btax=l.discount_btax+n[_].level4.discount):(0!=n[_].level3.sales||0!=n[_].level3.discount)&&l.sales_btax>=n[_].level3.sales?1===n[_].type?(l.discount_btax=l.discount_btax+(n[_].level2.sales-n[_].level1.sales)*n[_].level1.discount/100,l.discount_btax=l.discount_btax+(n[_].level3.sales-n[_].level2.sales)*n[_].level2.discount/100,l.discount_btax=l.discount_btax+(l.sales_btax-n[_].level3.sales)*n[_].level3.discount/100):2===n[_].type&&(l.discount_btax=n[_].level1.discount,l.discount_btax=l.discount_btax+n[_].level2.discount,l.discount_btax=l.discount_btax+n[_].level3.discount):(0!=n[_].level2.sales||0!=n[_].level2.discount)&&l.sales_btax>=n[_].level2.sales?1===n[_].type?(l.discount_btax=l.discount_btax+(n[_].level2.sales-n[_].level1.sales)*n[_].level1.discount/100,l.discount_btax=l.discount_btax+(l.sales_btax-n[_].level2.sales)*n[_].level2.discount/100):2===n[_].type&&(l.discount_btax=n[_].level1.discount,l.discount_btax=l.discount_btax+n[_].level2.discount):(0!=n[_].level1.sales||0!=n[_].level1.discount)&&l.sales_btax>=n[_].level1.sales&&(1===n[_].type?l.discount_btax=l.discount_btax+(l.sales_btax-n[_].level1.sales)*n[_].level1.discount/100:2===n[_].type&&(l.discount_btax=n[_].level1.discount)):2===n[_].method&&((0!=n[_].level5.sales||0!=n[_].level5.discount)&&l.sales_btax>=n[_].level5.sales?1===n[_].type?l.discount_btax=l.sales_btax*n[_].level5.discount/100:2===n[_].type&&(l.discount_btax=n[_].level5.discount):(0!=n[_].level4.sales||0!=n[_].level4.discount)&&l.sales_btax>=n[_].level4.sales?1===n[_].type?l.discount_btax=l.sales_btax*n[_].level4.discount/100:2===n[_].type&&(l.discount_btax=n[_].level4.discount):(0!=n[_].level3.sales||0!=n[_].level3.discount)&&l.sales_btax>=n[_].level3.sales?1===n[_].type?l.discount_btax=l.sales_btax*n[_].level3.discount/100:2===n[_].type&&(l.discount_btax=n[_].level3.discount):(0!=n[_].level2.sales||0!=n[_].level2.discount)&&l.sales_btax>=n[_].level2.sales?1===n[_].type?l.discount_btax=l.sales_btax*n[_].level2.discount/100:2===n[_].type&&(l.discount_btax=n[_].level2.discount):(0!=n[_].level1.sales||0!=n[_].level1.discount)&&l.sales_btax>=n[_].level1.sales&&(1===n[_].type?l.discount_btax=l.sales_btax*n[_].level1.discount/100:2===n[_].type&&(l.discount_btax=n[_].level1.discount))),1===n[_].method?(0!=n[_].level5.sales||0!=n[_].level5.discount)&&l.sales_atax>=n[_].level5.sales?1===n[_].type?(l.discount_atax=l.discount_atax+(n[_].level2.sales-n[_].level1.sales)*n[_].level1.discount/100,l.discount_atax=l.discount_atax+(n[_].level3.sales-n[_].level2.sales)*n[_].level2.discount/100,l.discount_atax=l.discount_atax+(n[_].level4.sales-n[_].level3.sales)*n[_].level3.discount/100,l.discount_atax=l.discount_atax+(n[_].level5.sales-n[_].level4.sales)*n[_].level4.discount/100,l.discount_atax=l.discount_atax+(l.sales_atax-n[_].level5.sales)*n[_].level5.discount/100):2===n[_].type&&(l.discount_atax=n[_].level1.discount,l.discount_atax=l.discount_atax+n[_].level2.discount,l.discount_atax=l.discount_atax+n[_].level3.discount,l.discount_atax=l.discount_atax+n[_].level4.discount,l.discount_atax=l.discount_atax+n[_].level5.discount):(0!=n[_].level4.sales||0!=n[_].level4.discount)&&l.sales_atax>=n[_].level4.sales?1===n[_].type?(l.discount_atax=l.discount_atax+(n[_].level2.sales-n[_].level1.sales)*n[_].level1.discount/100,l.discount_atax=l.discount_atax+(n[_].level3.sales-n[_].level2.sales)*n[_].level2.discount/100,l.discount_atax=l.discount_atax+(n[_].level4.sales-n[_].level3.sales)*n[_].level3.discount/100,l.discount_atax=l.discount_atax+(l.sales_atax-n[_].level4.sales)*n[_].level4.discount/100):2===n[_].type&&(l.discount_atax=n[_].level1.discount,l.discount_atax=l.discount_atax+n[_].level2.discount,l.discount_atax=l.discount_atax+n[_].level3.discount,l.discount_atax=l.discount_atax+n[_].level4.discount):(0!=n[_].level3.sales||0!=n[_].level3.discount)&&l.sales_atax>=n[_].level3.sales?1===n[_].type?(l.discount_atax=l.discount_atax+(n[_].level2.sales-n[_].level1.sales)*n[_].level1.discount/100,l.discount_atax=l.discount_atax+(n[_].level3.sales-n[_].level2.sales)*n[_].level2.discount/100,l.discount_atax=l.discount_atax+(l.sales_atax-n[_].level3.sales)*n[_].level3.discount/100):2===n[_].type&&(l.discount_atax=n[_].level1.discount,l.discount_atax=l.discount_atax+n[_].level2.discount,l.discount_atax=l.discount_atax+n[_].level3.discount):(0!=n[_].level2.sales||0!=n[_].level2.discount)&&l.sales_atax>=n[_].level2.sales?1===n[_].type?(l.discount_atax=l.discount_atax+(n[_].level2.sales-n[_].level1.sales)*n[_].level1.discount/100,l.discount_atax=l.discount_atax+(l.sales_atax-n[_].level2.sales)*n[_].level2.discount/100):2===n[_].type&&(l.discount_atax=n[_].level1.discount,l.discount_atax=l.discount_atax+n[_].level2.discount):(0!=n[_].level1.sales||0!=n[_].level1.discount)&&l.sales_atax>=n[_].level1.sales&&(1===n[_].type?l.discount_atax=l.discount_atax+(l.sales_atax-n[_].level1.sales)*n[_].level1.discount/100:2===n[_].type&&(l.discount_atax=n[_].level1.discount)):2===n[_].method&&((0!=n[_].level5.sales||0!=n[_].level5.discount)&&l.sales_atax>=n[_].level5.sales?1===n[_].type?l.discount_atax=l.sales_atax*n[_].level5.discount/100:2===n[_].type&&(l.discount_atax=n[_].level5.discount):(0!=n[_].level4.sales||0!=n[_].level4.discount)&&l.sales_atax>=n[_].level4.sales?1===n[_].type?l.discount_atax=l.sales_atax*n[_].level4.discount/100:2===n[_].type&&(l.discount_atax=n[_].level4.discount):(0!=n[_].level3.sales||0!=n[_].level3.discount)&&l.sales_atax>=n[_].level3.sales?1===n[_].type?l.discount_atax=l.sales_atax*n[_].level3.discount/100:2===n[_].type&&(l.discount_atax=n[_].level3.discount):(0!=n[_].level2.sales||0!=n[_].level2.discount)&&l.sales_atax>=n[_].level2.sales?1===n[_].type?l.discount_atax=l.sales_atax*n[_].level2.discount/100:2===n[_].type&&(l.discount_atax=n[_].level2.discount):(0!=n[_].level1.sales||0!=n[_].level1.discount)&&l.sales_atax>=n[_].level1.sales&&(1===n[_].type?l.discount_atax=l.sales_atax*n[_].level1.discount/100:2===n[_].type&&(l.discount_atax=n[_].level1.discount))),c.sales_btax=c.sales_btax+l.sales_btax,c.sales_atax=c.sales_atax+l.sales_atax,c.discount_btax=c.discount_btax+l.discount_btax,c.discount_atax=c.discount_atax+l.discount_atax,l.index=c.size+1,c.docs.push(l),c.size++,c.empty=!1;break}}console.log("getReportDiscount_Customers",c),a(c)}))}else a(c)}))},t.prototype.getReportDiscount_sales_Customers_new=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Array;if("all"===n)r=i.getlocalCustomers();else{var l=i.getlocalCustomer(n);r.push(l)}var c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,discount_btax:0,discount_atax:0};if(r.length>0){var u=void 0;u="all"===n?"all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$gte:t,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1]},id_branch:{$eq:o}};var d=i.vhmongo_firebase.database().getDocsByFields("discount_saless",{},{},{},0),_=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0),p=i.vhmongo_firebase.database().getDocsByFields("customer_classs",{},{},{},0);Promise.all([d,_,p]).then((function(t){var e,n=t[0],o=t[1],i=t[2];if(o.length>0)for(var s=0;s<r.length;s++){for(var l=!1,u={id_customer:r[s]._id,name:r[s].name,img:null===(e=r[s])||void 0===e?void 0:e.img,sales_btax:0,sales_atax:0,quantity:0,discount_btax:0,discount_atax:0,discount_name:""},d=0;d<o.length;d++)if(r[s]._id===o[d].id_customer)if(l=!0,5===o[d].ptype){if(null!=o[d].combos)for(var _=0;_<o[d].combos.length;_++)u.quantity=u.quantity+o[d].combos[_].quantity*o[d].quantity,u.sales_btax=u.sales_btax+o[d].combos[_].price*o[d].combos[_].quantity*o[d].quantity,u.sales_atax=u.sales_atax+o[d].combos[_].price*o[d].combos[_].quantity*o[d].quantity*(1+o[d].tax/100)}else u.quantity=u.quantity+o[d].quantity,u.sales_btax=u.sales_btax+o[d].price*o[d].quantity,u.sales_atax=u.sales_atax+o[d].price*o[d].quantity*(1+o[d].tax/100);if(l&&null!=r[s].id_discount_sales&&null!=r[s].id_discount_sales)for(d=0;d<i.length;d++)if(i[d]._id===r[s].id_customer_class&&null!=i[d].id_discount_sales&&null!=i[d].id_discount_sales)for(var p=0;p<n.length;p++)if(n[p]._id===i[d].id_discount_sales){u.discount_name=n[p].name,1===n[p].method?(0!=n[p].level5.sales||0!=n[p].level5.discount)&&u.sales_btax>=n[p].level5.sales?1===n[p].type?(u.discount_btax=u.discount_btax+(n[p].level2.sales-n[p].level1.sales)*n[p].level1.discount/100,u.discount_btax=u.discount_btax+(n[p].level3.sales-n[p].level2.sales)*n[p].level2.discount/100,u.discount_btax=u.discount_btax+(n[p].level4.sales-n[p].level3.sales)*n[p].level3.discount/100,u.discount_btax=u.discount_btax+(n[p].level5.sales-n[p].level4.sales)*n[p].level4.discount/100,u.discount_btax=u.discount_btax+(u.sales_btax-n[p].level5.sales)*n[p].level5.discount/100):2===n[p].type&&(u.discount_btax=n[p].level1.discount,u.discount_btax=u.discount_btax+n[p].level2.discount,u.discount_btax=u.discount_btax+n[p].level3.discount,u.discount_btax=u.discount_btax+n[p].level4.discount,u.discount_btax=u.discount_btax+n[p].level5.discount):(0!=n[p].level4.sales||0!=n[p].level4.discount)&&u.sales_btax>=n[p].level4.sales?1===n[p].type?(u.discount_btax=u.discount_btax+(n[p].level2.sales-n[p].level1.sales)*n[p].level1.discount/100,u.discount_btax=u.discount_btax+(n[p].level3.sales-n[p].level2.sales)*n[p].level2.discount/100,u.discount_btax=u.discount_btax+(n[p].level4.sales-n[p].level3.sales)*n[p].level3.discount/100,u.discount_btax=u.discount_btax+(u.sales_btax-n[p].level4.sales)*n[p].level4.discount/100):2===n[p].type&&(u.discount_btax=n[p].level1.discount,u.discount_btax=u.discount_btax+n[p].level2.discount,u.discount_btax=u.discount_btax+n[p].level3.discount,u.discount_btax=u.discount_btax+n[p].level4.discount):(0!=n[p].level3.sales||0!=n[p].level3.discount)&&u.sales_btax>=n[p].level3.sales?1===n[p].type?(u.discount_btax=u.discount_btax+(n[p].level2.sales-n[p].level1.sales)*n[p].level1.discount/100,u.discount_btax=u.discount_btax+(n[p].level3.sales-n[p].level2.sales)*n[p].level2.discount/100,u.discount_btax=u.discount_btax+(u.sales_btax-n[p].level3.sales)*n[p].level3.discount/100):2===n[p].type&&(u.discount_btax=n[p].level1.discount,u.discount_btax=u.discount_btax+n[p].level2.discount,u.discount_btax=u.discount_btax+n[p].level3.discount):(0!=n[p].level2.sales||0!=n[p].level2.discount)&&u.sales_btax>=n[p].level2.sales?1===n[p].type?(u.discount_btax=u.discount_btax+(n[p].level2.sales-n[p].level1.sales)*n[p].level1.discount/100,u.discount_btax=u.discount_btax+(u.sales_btax-n[p].level2.sales)*n[p].level2.discount/100):2===n[p].type&&(u.discount_btax=n[p].level1.discount,u.discount_btax=u.discount_btax+n[p].level2.discount):(0!=n[p].level1.sales||0!=n[p].level1.discount)&&u.sales_btax>=n[p].level1.sales&&(1===n[p].type?u.discount_btax=u.discount_btax+(u.sales_btax-n[p].level1.sales)*n[p].level1.discount/100:2===n[p].type&&(u.discount_btax=n[p].level1.discount)):2===n[p].method&&((0!=n[p].level5.sales||0!=n[p].level5.discount)&&u.sales_btax>=n[p].level5.sales?1===n[p].type?u.discount_btax=u.sales_btax*n[p].level5.discount/100:2===n[p].type&&(u.discount_btax=n[p].level5.discount):(0!=n[p].level4.sales||0!=n[p].level4.discount)&&u.sales_btax>=n[p].level4.sales?1===n[p].type?u.discount_btax=u.sales_btax*n[p].level4.discount/100:2===n[p].type&&(u.discount_btax=n[p].level4.discount):(0!=n[p].level3.sales||0!=n[p].level3.discount)&&u.sales_btax>=n[p].level3.sales?1===n[p].type?u.discount_btax=u.sales_btax*n[p].level3.discount/100:2===n[p].type&&(u.discount_btax=n[p].level3.discount):(0!=n[p].level2.sales||0!=n[p].level2.discount)&&u.sales_btax>=n[p].level2.sales?1===n[p].type?u.discount_btax=u.sales_btax*n[p].level2.discount/100:2===n[p].type&&(u.discount_btax=n[p].level2.discount):(0!=n[p].level1.sales||0!=n[p].level1.discount)&&u.sales_btax>=n[p].level1.sales&&(1===n[p].type?u.discount_btax=u.sales_btax*n[p].level1.discount/100:2===n[p].type&&(u.discount_btax=n[p].level1.discount))),1===n[p].method?(0!=n[p].level5.sales||0!=n[p].level5.discount)&&u.sales_atax>=n[p].level5.sales?1===n[p].type?(u.discount_atax=u.discount_atax+(n[p].level2.sales-n[p].level1.sales)*n[p].level1.discount/100,u.discount_atax=u.discount_atax+(n[p].level3.sales-n[p].level2.sales)*n[p].level2.discount/100,u.discount_atax=u.discount_atax+(n[p].level4.sales-n[p].level3.sales)*n[p].level3.discount/100,u.discount_atax=u.discount_atax+(n[p].level5.sales-n[p].level4.sales)*n[p].level4.discount/100,u.discount_atax=u.discount_atax+(u.sales_atax-n[p].level5.sales)*n[p].level5.discount/100):2===n[p].type&&(u.discount_atax=n[p].level1.discount,u.discount_atax=u.discount_atax+n[p].level2.discount,u.discount_atax=u.discount_atax+n[p].level3.discount,u.discount_atax=u.discount_atax+n[p].level4.discount,u.discount_atax=u.discount_atax+n[p].level5.discount):(0!=n[p].level4.sales||0!=n[p].level4.discount)&&u.sales_atax>=n[p].level4.sales?1===n[p].type?(u.discount_atax=u.discount_atax+(n[p].level2.sales-n[p].level1.sales)*n[p].level1.discount/100,u.discount_atax=u.discount_atax+(n[p].level3.sales-n[p].level2.sales)*n[p].level2.discount/100,u.discount_atax=u.discount_atax+(n[p].level4.sales-n[p].level3.sales)*n[p].level3.discount/100,u.discount_atax=u.discount_atax+(u.sales_atax-n[p].level4.sales)*n[p].level4.discount/100):2===n[p].type&&(u.discount_atax=n[p].level1.discount,u.discount_atax=u.discount_atax+n[p].level2.discount,u.discount_atax=u.discount_atax+n[p].level3.discount,u.discount_atax=u.discount_atax+n[p].level4.discount):(0!=n[p].level3.sales||0!=n[p].level3.discount)&&u.sales_atax>=n[p].level3.sales?1===n[p].type?(u.discount_atax=u.discount_atax+(n[p].level2.sales-n[p].level1.sales)*n[p].level1.discount/100,u.discount_atax=u.discount_atax+(n[p].level3.sales-n[p].level2.sales)*n[p].level2.discount/100,u.discount_atax=u.discount_atax+(u.sales_atax-n[p].level3.sales)*n[p].level3.discount/100):2===n[p].type&&(u.discount_atax=n[p].level1.discount,u.discount_atax=u.discount_atax+n[p].level2.discount,u.discount_atax=u.discount_atax+n[p].level3.discount):(0!=n[p].level2.sales||0!=n[p].level2.discount)&&u.sales_atax>=n[p].level2.sales?1===n[p].type?(u.discount_atax=u.discount_atax+(n[p].level2.sales-n[p].level1.sales)*n[p].level1.discount/100,u.discount_atax=u.discount_atax+(u.sales_atax-n[p].level2.sales)*n[p].level2.discount/100):2===n[p].type&&(u.discount_atax=n[p].level1.discount,u.discount_atax=u.discount_atax+n[p].level2.discount):(0!=n[p].level1.sales||0!=n[p].level1.discount)&&u.sales_atax>=n[p].level1.sales&&(1===n[p].type?u.discount_atax=u.discount_atax+(u.sales_atax-n[p].level1.sales)*n[p].level1.discount/100:2===n[p].type&&(u.discount_atax=n[p].level1.discount)):2===n[p].method&&((0!=n[p].level5.sales||0!=n[p].level5.discount)&&u.sales_atax>=n[p].level5.sales?1===n[p].type?u.discount_atax=u.sales_atax*n[p].level5.discount/100:2===n[p].type&&(u.discount_atax=n[p].level5.discount):(0!=n[p].level4.sales||0!=n[p].level4.discount)&&u.sales_atax>=n[p].level4.sales?1===n[p].type?u.discount_atax=u.sales_atax*n[p].level4.discount/100:2===n[p].type&&(u.discount_atax=n[p].level4.discount):(0!=n[p].level3.sales||0!=n[p].level3.discount)&&u.sales_atax>=n[p].level3.sales?1===n[p].type?u.discount_atax=u.sales_atax*n[p].level3.discount/100:2===n[p].type&&(u.discount_atax=n[p].level3.discount):(0!=n[p].level2.sales||0!=n[p].level2.discount)&&u.sales_atax>=n[p].level2.sales?1===n[p].type?u.discount_atax=u.sales_atax*n[p].level2.discount/100:2===n[p].type&&(u.discount_atax=n[p].level2.discount):(0!=n[p].level1.sales||0!=n[p].level1.discount)&&u.sales_atax>=n[p].level1.sales&&(1===n[p].type?u.discount_atax=u.sales_atax*n[p].level1.discount/100:2===n[p].type&&(u.discount_atax=n[p].level1.discount))),c.sales_btax=c.sales_btax+u.sales_btax,c.sales_atax=c.sales_atax+u.sales_atax,c.discount_btax=c.discount_btax+u.discount_btax,c.discount_atax=c.discount_atax+u.discount_atax,u.index=c.size+1,c.docs.push(u),c.size++,c.empty=!1;break}}console.log("getReportDiscount_Customers",c),a(c)}))}else a(c)}))},t.prototype.getReportCommission_Employees=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Array;if("all"===n)r=i.vhAuth.getlocalEmployees();else{var l=i.vhAuth.getlocalEmployee(n);r.push(l)}var c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,commission_btax:0,commission_atax:0};if(r.length>0){var u=void 0;u="all"===n?"all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$gte:t,$lte:e},id_employee:{$eq:n},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},id_employee:{$eq:n},bill_type:{$in:[1]},id_branch:{$eq:o}};var d=i.vhmongo_firebase.database().getDocsByFields("commissions",{},{},{},0),_=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0);Promise.all([d,_]).then((function(t){var e=t[0],n=t[1];if(n.length>0)for(var o=0;o<r.length;o++){for(var i=!1,s={id_employee:r[o]._id,name:r[o].name,sales_btax:0,sales_atax:0,quantity:0,commission_btax:0,commission_atax:0,commission_name:""},l=0;l<n.length;l++)if(r[o]._id===n[l].id_employee)if(i=!0,5===n[l].ptype){if(null!=n[l].combos)for(var u=0;u<n[l].combos.length;u++)s.quantity=s.quantity+n[l].combos[u].quantity*n[l].quantity,s.sales_btax=s.sales_btax+n[l].combos[u].price*n[l].combos[u].quantity*n[l].quantity,s.sales_atax=s.sales_atax+n[l].combos[u].price*n[l].combos[u].quantity*n[l].quantity*(1+n[l].tax/100)}else s.quantity=s.quantity+n[l].quantity,s.sales_btax=s.sales_btax+n[l].price*n[l].quantity,s.sales_atax=s.sales_atax+n[l].price*n[l].quantity*(1+n[l].tax/100);if(i&&null!=r[o].id_commission&&null!=r[o].id_commission)for(var d=0;d<e.length;d++)if(e[d]._id===r[o].id_commission){s.commission_name=e[d].name,1===e[d].method?(0!=e[d].level5.sales||0!=e[d].level5.commission)&&s.sales_btax>=e[d].level5.sales?1===e[d].type?(s.commission_btax=s.commission_btax+(e[d].level2.sales-e[d].level1.sales)*e[d].level1.commission/100,s.commission_btax=s.commission_btax+(e[d].level3.sales-e[d].level2.sales)*e[d].level2.commission/100,s.commission_btax=s.commission_btax+(e[d].level4.sales-e[d].level3.sales)*e[d].level3.commission/100,s.commission_btax=s.commission_btax+(e[d].level5.sales-e[d].level4.sales)*e[d].level4.commission/100,s.commission_btax=s.commission_btax+(s.sales_btax-e[d].level5.sales)*e[d].level5.commission/100):2===e[d].type&&(s.commission_btax=e[d].level1.commission,s.commission_btax=s.commission_btax+e[d].level2.commission,s.commission_btax=s.commission_btax+e[d].level3.commission,s.commission_btax=s.commission_btax+e[d].level4.commission,s.commission_btax=s.commission_btax+e[d].level5.commission):(0!=e[d].level4.sales||0!=e[d].level4.commission)&&s.sales_btax>=e[d].level4.sales?1===e[d].type?(s.commission_btax=s.commission_btax+(e[d].level2.sales-e[d].level1.sales)*e[d].level1.commission/100,s.commission_btax=s.commission_btax+(e[d].level3.sales-e[d].level2.sales)*e[d].level2.commission/100,s.commission_btax=s.commission_btax+(e[d].level4.sales-e[d].level3.sales)*e[d].level3.commission/100,s.commission_btax=s.commission_btax+(s.sales_btax-e[d].level4.sales)*e[d].level4.commission/100):2===e[d].type&&(s.commission_btax=e[d].level1.commission,s.commission_btax=s.commission_btax+e[d].level2.commission,s.commission_btax=s.commission_btax+e[d].level3.commission,s.commission_btax=s.commission_btax+e[d].level4.commission):(0!=e[d].level3.sales||0!=e[d].level3.commission)&&s.sales_btax>=e[d].level3.sales?1===e[d].type?(s.commission_btax=s.commission_btax+(e[d].level2.sales-e[d].level1.sales)*e[d].level1.commission/100,s.commission_btax=s.commission_btax+(e[d].level3.sales-e[d].level2.sales)*e[d].level2.commission/100,s.commission_btax=s.commission_btax+(s.sales_btax-e[d].level3.sales)*e[d].level3.commission/100):2===e[d].type&&(s.commission_btax=e[d].level1.commission,s.commission_btax=s.commission_btax+e[d].level2.commission,s.commission_btax=s.commission_btax+e[d].level3.commission):(0!=e[d].level2.sales||0!=e[d].level2.commission)&&s.sales_btax>=e[d].level2.sales?1===e[d].type?(s.commission_btax=s.commission_btax+(e[d].level2.sales-e[d].level1.sales)*e[d].level1.commission/100,s.commission_btax=s.commission_btax+(s.sales_btax-e[d].level2.sales)*e[d].level2.commission/100):2===e[d].type&&(s.commission_btax=e[d].level1.commission,s.commission_btax=s.commission_btax+e[d].level2.commission):(0!=e[d].level1.sales||0!=e[d].level1.commission)&&s.sales_btax>=e[d].level1.sales&&(1===e[d].type?s.commission_btax=s.commission_btax+(s.sales_btax-e[d].level1.sales)*e[d].level1.commission/100:2===e[d].type&&(s.commission_btax=e[d].level1.commission)):2===e[d].method&&((0!=e[d].level5.sales||0!=e[d].level5.commission)&&s.sales_btax>=e[d].level5.sales?1===e[d].type?s.commission_btax=s.sales_btax*e[d].level5.commission/100:2===e[d].type&&(s.commission_btax=e[d].level5.commission):(0!=e[d].level4.sales||0!=e[d].level4.commission)&&s.sales_btax>=e[d].level4.sales?1===e[d].type?s.commission_btax=s.sales_btax*e[d].level4.commission/100:2===e[d].type&&(s.commission_btax=e[d].level4.commission):(0!=e[d].level3.sales||0!=e[d].level3.commission)&&s.sales_btax>=e[d].level3.sales?1===e[d].type?s.commission_btax=s.sales_btax*e[d].level3.commission/100:2===e[d].type&&(s.commission_btax=e[d].level3.commission):(0!=e[d].level2.sales||0!=e[d].level2.commission)&&s.sales_btax>=e[d].level2.sales?1===e[d].type?s.commission_btax=s.sales_btax*e[d].level2.commission/100:2===e[d].type&&(s.commission_btax=e[d].level2.commission):(0!=e[d].level1.sales||0!=e[d].level1.commission)&&s.sales_btax>=e[d].level1.sales&&(1===e[d].type?s.commission_btax=s.sales_btax*e[d].level1.commission/100:2===e[d].type&&(s.commission_btax=e[d].level1.commission))),1===e[d].method?(0!=e[d].level5.sales||0!=e[d].level5.commission)&&s.sales_atax>=e[d].level5.sales?1===e[d].type?(s.commission_atax=s.commission_atax+(e[d].level2.sales-e[d].level1.sales)*e[d].level1.commission/100,s.commission_atax=s.commission_atax+(e[d].level3.sales-e[d].level2.sales)*e[d].level2.commission/100,s.commission_atax=s.commission_atax+(e[d].level4.sales-e[d].level3.sales)*e[d].level3.commission/100,s.commission_atax=s.commission_atax+(e[d].level5.sales-e[d].level4.sales)*e[d].level4.commission/100,s.commission_atax=s.commission_atax+(s.sales_atax-e[d].level5.sales)*e[d].level5.commission/100):2===e[d].type&&(s.commission_atax=e[d].level1.commission,s.commission_atax=s.commission_atax+e[d].level2.commission,s.commission_atax=s.commission_atax+e[d].level3.commission,s.commission_atax=s.commission_atax+e[d].level4.commission,s.commission_atax=s.commission_atax+e[d].level5.commission):(0!=e[d].level4.sales||0!=e[d].level4.commission)&&s.sales_atax>=e[d].level4.sales?1===e[d].type?(s.commission_atax=s.commission_atax+(e[d].level2.sales-e[d].level1.sales)*e[d].level1.commission/100,s.commission_atax=s.commission_atax+(e[d].level3.sales-e[d].level2.sales)*e[d].level2.commission/100,s.commission_atax=s.commission_atax+(e[d].level4.sales-e[d].level3.sales)*e[d].level3.commission/100,s.commission_atax=s.commission_atax+(s.sales_atax-e[d].level4.sales)*e[d].level4.commission/100):2===e[d].type&&(s.commission_atax=e[d].level1.commission,s.commission_atax=s.commission_atax+e[d].level2.commission,s.commission_atax=s.commission_atax+e[d].level3.commission,s.commission_atax=s.commission_atax+e[d].level4.commission):(0!=e[d].level3.sales||0!=e[d].level3.commission)&&s.sales_atax>=e[d].level3.sales?1===e[d].type?(s.commission_atax=s.commission_atax+(e[d].level2.sales-e[d].level1.sales)*e[d].level1.commission/100,s.commission_atax=s.commission_atax+(e[d].level3.sales-e[d].level2.sales)*e[d].level2.commission/100,s.commission_atax=s.commission_atax+(s.sales_atax-e[d].level3.sales)*e[d].level3.commission/100):2===e[d].type&&(s.commission_atax=e[d].level1.commission,s.commission_atax=s.commission_atax+e[d].level2.commission,s.commission_atax=s.commission_atax+e[d].level3.commission):(0!=e[d].level2.sales||0!=e[d].level2.commission)&&s.sales_atax>=e[d].level2.sales?1===e[d].type?(s.commission_atax=s.commission_atax+(e[d].level2.sales-e[d].level1.sales)*e[d].level1.commission/100,s.commission_atax=s.commission_atax+(s.sales_atax-e[d].level2.sales)*e[d].level2.commission/100):2===e[d].type&&(s.commission_atax=e[d].level1.commission,s.commission_atax=s.commission_atax+e[d].level2.commission):(0!=e[d].level1.sales||0!=e[d].level1.commission)&&s.sales_atax>=e[d].level1.sales&&(1===e[d].type?s.commission_atax=s.commission_atax+(s.sales_atax-e[d].level1.sales)*e[d].level1.commission/100:2===e[d].type&&(s.commission_atax=e[d].level1.commission)):2===e[d].method&&((0!=e[d].level5.sales||0!=e[d].level5.commission)&&s.sales_atax>=e[d].level5.sales?1===e[d].type?s.commission_atax=s.sales_atax*e[d].level5.commission/100:2===e[d].type&&(s.commission_atax=e[d].level5.commission):(0!=e[d].level4.sales||0!=e[d].level4.commission)&&s.sales_atax>=e[d].level4.sales?1===e[d].type?s.commission_atax=s.sales_atax*e[d].level4.commission/100:2===e[d].type&&(s.commission_atax=e[d].level4.commission):(0!=e[d].level3.sales||0!=e[d].level3.commission)&&s.sales_atax>=e[d].level3.sales?1===e[d].type?s.commission_atax=s.sales_atax*e[d].level3.commission/100:2===e[d].type&&(s.commission_atax=e[d].level3.commission):(0!=e[d].level2.sales||0!=e[d].level2.commission)&&s.sales_atax>=e[d].level2.sales?1===e[d].type?s.commission_atax=s.sales_atax*e[d].level2.commission/100:2===e[d].type&&(s.commission_atax=e[d].level2.commission):(0!=e[d].level1.sales||0!=e[d].level1.commission)&&s.sales_atax>=e[d].level1.sales&&(1===e[d].type?s.commission_atax=s.sales_atax*e[d].level1.commission/100:2===e[d].type&&(s.commission_atax=e[d].level1.commission))),c.sales_btax=c.sales_btax+s.sales_btax,c.sales_atax=c.sales_atax+s.sales_atax,c.commission_btax=c.commission_btax+s.commission_btax,c.commission_atax=c.commission_atax+s.commission_atax,s.index=c.size+1,c.docs.push(s),c.size++,c.empty=!1;break}}console.log("getReportCommission_Employees",c),a(c)}))}else a(c)}))},t.prototype.getReportCommission_Employees_new=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Array;if("all"===n)r=i.vhAuth.getlocalEmployees();else{var l=i.vhAuth.getlocalEmployee(n);r.push(l)}var c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,commission_btax:0,commission_atax:0};if(r.length>0){var u=void 0;u="all"===n?"all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$gte:t,$lte:e},id_employee:{$eq:n},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},id_employee:{$eq:n},bill_type:{$in:[1]},id_branch:{$eq:o}};var d=i.vhmongo_firebase.database().getDocsByFields("commissions",{},{},{},0),_=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0),p=i.vhmongo_firebase.database().getDocsByFields("employee_classs",{},{},{},0);Promise.all([d,_,p]).then((function(t){var e=t[0],n=t[1],o=t[2];if(n.length>0)for(var i=0;i<r.length;i++){for(var s=!1,l={id_employee:r[i]._id,name:r[i].name,sales_btax:0,sales_atax:0,quantity:0,commission_btax:0,commission_atax:0,commission_name:""},u=0;u<n.length;u++)if(r[i]._id===n[u].id_employee)if(s=!0,5===n[u].ptype){if(null!=n[u].combos)for(var d=0;d<n[u].combos.length;d++)l.quantity=l.quantity+n[u].combos[d].quantity*n[u].quantity,l.sales_btax=l.sales_btax+n[u].combos[d].price*n[u].combos[d].quantity*n[u].quantity,l.sales_atax=l.sales_atax+n[u].combos[d].price*n[u].combos[d].quantity*n[u].quantity*(1+n[u].tax/100)}else l.quantity=l.quantity+n[u].quantity,l.sales_btax=l.sales_btax+n[u].price*n[u].quantity,l.sales_atax=l.sales_atax+n[u].price*n[u].quantity*(1+n[u].tax/100);if(s&&null!=r[i].id_employee_class&&null!=r[i].id_employee_class)for(u=0;u<o.length;u++)if(o[u]._id===r[i].id_employee_class&&null!=o[u].id_commission&&null!=o[u].id_commission)for(var _=0;_<e.length;_++)if(e[_]._id===o[u].id_commission){l.commission_name=e[_].name,1===e[_].method?(0!=e[_].level5.sales||0!=e[_].level5.commission)&&l.sales_btax>=e[_].level5.sales?1===e[_].type?(l.commission_btax=l.commission_btax+(e[_].level2.sales-e[_].level1.sales)*e[_].level1.commission/100,l.commission_btax=l.commission_btax+(e[_].level3.sales-e[_].level2.sales)*e[_].level2.commission/100,l.commission_btax=l.commission_btax+(e[_].level4.sales-e[_].level3.sales)*e[_].level3.commission/100,l.commission_btax=l.commission_btax+(e[_].level5.sales-e[_].level4.sales)*e[_].level4.commission/100,l.commission_btax=l.commission_btax+(l.sales_btax-e[_].level5.sales)*e[_].level5.commission/100):2===e[_].type&&(l.commission_btax=e[_].level1.commission,l.commission_btax=l.commission_btax+e[_].level2.commission,l.commission_btax=l.commission_btax+e[_].level3.commission,l.commission_btax=l.commission_btax+e[_].level4.commission,l.commission_btax=l.commission_btax+e[_].level5.commission):(0!=e[_].level4.sales||0!=e[_].level4.commission)&&l.sales_btax>=e[_].level4.sales?1===e[_].type?(l.commission_btax=l.commission_btax+(e[_].level2.sales-e[_].level1.sales)*e[_].level1.commission/100,l.commission_btax=l.commission_btax+(e[_].level3.sales-e[_].level2.sales)*e[_].level2.commission/100,l.commission_btax=l.commission_btax+(e[_].level4.sales-e[_].level3.sales)*e[_].level3.commission/100,l.commission_btax=l.commission_btax+(l.sales_btax-e[_].level4.sales)*e[_].level4.commission/100):2===e[_].type&&(l.commission_btax=e[_].level1.commission,l.commission_btax=l.commission_btax+e[_].level2.commission,l.commission_btax=l.commission_btax+e[_].level3.commission,l.commission_btax=l.commission_btax+e[_].level4.commission):(0!=e[_].level3.sales||0!=e[_].level3.commission)&&l.sales_btax>=e[_].level3.sales?1===e[_].type?(l.commission_btax=l.commission_btax+(e[_].level2.sales-e[_].level1.sales)*e[_].level1.commission/100,l.commission_btax=l.commission_btax+(e[_].level3.sales-e[_].level2.sales)*e[_].level2.commission/100,l.commission_btax=l.commission_btax+(l.sales_btax-e[_].level3.sales)*e[_].level3.commission/100):2===e[_].type&&(l.commission_btax=e[_].level1.commission,l.commission_btax=l.commission_btax+e[_].level2.commission,l.commission_btax=l.commission_btax+e[_].level3.commission):(0!=e[_].level2.sales||0!=e[_].level2.commission)&&l.sales_btax>=e[_].level2.sales?1===e[_].type?(l.commission_btax=l.commission_btax+(e[_].level2.sales-e[_].level1.sales)*e[_].level1.commission/100,l.commission_btax=l.commission_btax+(l.sales_btax-e[_].level2.sales)*e[_].level2.commission/100):2===e[_].type&&(l.commission_btax=e[_].level1.commission,l.commission_btax=l.commission_btax+e[_].level2.commission):(0!=e[_].level1.sales||0!=e[_].level1.commission)&&l.sales_btax>=e[_].level1.sales&&(1===e[_].type?l.commission_btax=l.commission_btax+(l.sales_btax-e[_].level1.sales)*e[_].level1.commission/100:2===e[_].type&&(l.commission_btax=e[_].level1.commission)):2===e[_].method&&((0!=e[_].level5.sales||0!=e[_].level5.commission)&&l.sales_btax>=e[_].level5.sales?1===e[_].type?l.commission_btax=l.sales_btax*e[_].level5.commission/100:2===e[_].type&&(l.commission_btax=e[_].level5.commission):(0!=e[_].level4.sales||0!=e[_].level4.commission)&&l.sales_btax>=e[_].level4.sales?1===e[_].type?l.commission_btax=l.sales_btax*e[_].level4.commission/100:2===e[_].type&&(l.commission_btax=e[_].level4.commission):(0!=e[_].level3.sales||0!=e[_].level3.commission)&&l.sales_btax>=e[_].level3.sales?1===e[_].type?l.commission_btax=l.sales_btax*e[_].level3.commission/100:2===e[_].type&&(l.commission_btax=e[_].level3.commission):(0!=e[_].level2.sales||0!=e[_].level2.commission)&&l.sales_btax>=e[_].level2.sales?1===e[_].type?l.commission_btax=l.sales_btax*e[_].level2.commission/100:2===e[_].type&&(l.commission_btax=e[_].level2.commission):(0!=e[_].level1.sales||0!=e[_].level1.commission)&&l.sales_btax>=e[_].level1.sales&&(1===e[_].type?l.commission_btax=l.sales_btax*e[_].level1.commission/100:2===e[_].type&&(l.commission_btax=e[_].level1.commission))),1===e[_].method?(0!=e[_].level5.sales||0!=e[_].level5.commission)&&l.sales_atax>=e[_].level5.sales?1===e[_].type?(l.commission_atax=l.commission_atax+(e[_].level2.sales-e[_].level1.sales)*e[_].level1.commission/100,l.commission_atax=l.commission_atax+(e[_].level3.sales-e[_].level2.sales)*e[_].level2.commission/100,l.commission_atax=l.commission_atax+(e[_].level4.sales-e[_].level3.sales)*e[_].level3.commission/100,l.commission_atax=l.commission_atax+(e[_].level5.sales-e[_].level4.sales)*e[_].level4.commission/100,l.commission_atax=l.commission_atax+(l.sales_atax-e[_].level5.sales)*e[_].level5.commission/100):2===e[_].type&&(l.commission_atax=e[_].level1.commission,l.commission_atax=l.commission_atax+e[_].level2.commission,l.commission_atax=l.commission_atax+e[_].level3.commission,l.commission_atax=l.commission_atax+e[_].level4.commission,l.commission_atax=l.commission_atax+e[_].level5.commission):(0!=e[_].level4.sales||0!=e[_].level4.commission)&&l.sales_atax>=e[_].level4.sales?1===e[_].type?(l.commission_atax=l.commission_atax+(e[_].level2.sales-e[_].level1.sales)*e[_].level1.commission/100,l.commission_atax=l.commission_atax+(e[_].level3.sales-e[_].level2.sales)*e[_].level2.commission/100,l.commission_atax=l.commission_atax+(e[_].level4.sales-e[_].level3.sales)*e[_].level3.commission/100,l.commission_atax=l.commission_atax+(l.sales_atax-e[_].level4.sales)*e[_].level4.commission/100):2===e[_].type&&(l.commission_atax=e[_].level1.commission,l.commission_atax=l.commission_atax+e[_].level2.commission,l.commission_atax=l.commission_atax+e[_].level3.commission,l.commission_atax=l.commission_atax+e[_].level4.commission):(0!=e[_].level3.sales||0!=e[_].level3.commission)&&l.sales_atax>=e[_].level3.sales?1===e[_].type?(l.commission_atax=l.commission_atax+(e[_].level2.sales-e[_].level1.sales)*e[_].level1.commission/100,l.commission_atax=l.commission_atax+(e[_].level3.sales-e[_].level2.sales)*e[_].level2.commission/100,l.commission_atax=l.commission_atax+(l.sales_atax-e[_].level3.sales)*e[_].level3.commission/100):2===e[_].type&&(l.commission_atax=e[_].level1.commission,l.commission_atax=l.commission_atax+e[_].level2.commission,l.commission_atax=l.commission_atax+e[_].level3.commission):(0!=e[_].level2.sales||0!=e[_].level2.commission)&&l.sales_atax>=e[_].level2.sales?1===e[_].type?(l.commission_atax=l.commission_atax+(e[_].level2.sales-e[_].level1.sales)*e[_].level1.commission/100,l.commission_atax=l.commission_atax+(l.sales_atax-e[_].level2.sales)*e[_].level2.commission/100):2===e[_].type&&(l.commission_atax=e[_].level1.commission,l.commission_atax=l.commission_atax+e[_].level2.commission):(0!=e[_].level1.sales||0!=e[_].level1.commission)&&l.sales_atax>=e[_].level1.sales&&(1===e[_].type?l.commission_atax=l.commission_atax+(l.sales_atax-e[_].level1.sales)*e[_].level1.commission/100:2===e[_].type&&(l.commission_atax=e[_].level1.commission)):2===e[_].method&&((0!=e[_].level5.sales||0!=e[_].level5.commission)&&l.sales_atax>=e[_].level5.sales?1===e[_].type?l.commission_atax=l.sales_atax*e[_].level5.commission/100:2===e[_].type&&(l.commission_atax=e[_].level5.commission):(0!=e[_].level4.sales||0!=e[_].level4.commission)&&l.sales_atax>=e[_].level4.sales?1===e[_].type?l.commission_atax=l.sales_atax*e[_].level4.commission/100:2===e[_].type&&(l.commission_atax=e[_].level4.commission):(0!=e[_].level3.sales||0!=e[_].level3.commission)&&l.sales_atax>=e[_].level3.sales?1===e[_].type?l.commission_atax=l.sales_atax*e[_].level3.commission/100:2===e[_].type&&(l.commission_atax=e[_].level3.commission):(0!=e[_].level2.sales||0!=e[_].level2.commission)&&l.sales_atax>=e[_].level2.sales?1===e[_].type?l.commission_atax=l.sales_atax*e[_].level2.commission/100:2===e[_].type&&(l.commission_atax=e[_].level2.commission):(0!=e[_].level1.sales||0!=e[_].level1.commission)&&l.sales_atax>=e[_].level1.sales&&(1===e[_].type?l.commission_atax=l.sales_atax*e[_].level1.commission/100:2===e[_].type&&(l.commission_atax=e[_].level1.commission))),c.sales_btax=c.sales_btax+l.sales_btax,c.sales_atax=c.sales_atax+l.sales_atax,c.commission_btax=c.commission_btax+l.commission_btax,c.commission_atax=c.commission_atax+l.commission_atax,l.index=c.size+1,c.docs.push(l),c.size++,c.empty=!1;break}}console.log("getReportCommission_Employees",c),a(c)}))}else a(c)}))},t.prototype.getReportCashBook=function(t,e,n,o){var i=this;t=new Date(t),e=new Date(e);var a=[1,7,10,11,34,2,8,12,33],s=this.vhAuth.getStore();return new Promise((function(r,l){var c,u=0,d=null;if("all"===n)if("all"===o||void 0===o){for(var _=i.getlocalWallets(),p=i.getDefaultBranch()._id,b=null,f=0;f<_.length;f++)if("id_cash"===_[f]._id&&null!=_[f][o]&&null!=_[f][o].cashbook)for(var h=0;h<_[f][p].cashbook.length&&!(new Date(_[f][p].cashbook[h].date).getTime()>t.getTime());h++)d=new Date(_[f][p].cashbook[h].date),b=h;if(d)for(f=0;f<_.length;f++)if("id_cash"===_[f]._id)for(var y=i.getlocalBranchs(),m=0;m<y.length;m++)u+=_[f][y[m]._id].cashbook[b].cashbook_first;else u+=_[f].cashbook[b].cashbook_first}else{for(_=i.getlocalWallets().filter((function(t){return t.id_branch===o||"id_cash"===t._id})),b=null,f=0;f<_.length;f++)if("id_cash"===_[f]._id&&null!=_[f][o]&&null!=_[f][o].cashbook)for(h=0;h<_[f][o].cashbook.length&&!(new Date(_[f][o].cashbook[h].date).getTime()>t.getTime());h++)d=new Date(_[f][o].cashbook[h].date),b=h;if(d)for(f=0;f<_.length;f++)"id_cash"===_[f]._id?u+=_[f][o].cashbook[b].cashbook_first:u+=_[f].cashbook[b].cashbook_first}else if("all"===o||void 0===o)console.log("trường hợp này chưa có hàm, liên hệ anh Huy viết");else{var v=i.getlocalWallet(n);if("id_cash"===v._id){if(null!=v[o]&&null!=v[o].cashbook)for(h=0;h<v[o].cashbook.length&&!(new Date(v[o].cashbook[h].date).getTime()>t.getTime());h++)d=new Date(v[o].cashbook[h].date),u=v[o].cashbook[h].cashbook_first}else if(null!=v.cashbook)for(h=0;h<v.cashbook.length&&!(new Date(v.cashbook[h].date).getTime()>t.getTime());h++)d=new Date(v.cashbook[h].date),u=v.cashbook[h].cashbook_first}d||(d=new Date(s.registrationdate));var g=new Array;if("all"===n)if("all"===o||void 0===o){var x={date:{$gte:d,$lte:e},bill_type:{$in:a},payment_type:{$eq:1}},q={date:{$gte:d,$lte:e},bill_type:{$in:a},payment_type:{$eq:3}};g.push(i.vhmongo_firebase.database().getDocsByFields("bills",x,{},{date:1},0)),g.push(i.vhmongo_firebase.database().getDocsByFields("bills",q,{},{date:1},0))}else{x={date:{$gte:d,$lte:e},id_branch:{$eq:o},bill_type:{$in:a},payment_type:{$eq:1}},q={date:{$gte:d,$lte:e},id_branch:{$eq:o},bill_type:{$in:a},payment_type:{$eq:3}};g.push(i.vhmongo_firebase.database().getDocsByFields("bills",x,{},{date:1},0)),g.push(i.vhmongo_firebase.database().getDocsByFields("bills",q,{},{date:1},0))}else"all"===o||void 0===o||(c={date:{$gte:d,$lte:e},id_wallet:{$eq:n},id_branch:{$eq:o},bill_type:{$in:a}},g.push(i.vhmongo_firebase.database().getDocsByFields("bills",c,{},{date:1},0)));Promise.all(g).then((function(e){var n=e.flat();n=i.vhAlgorithm.sortDatebyASC(n,"date");var o={docs:new Array,empty:!0,size:0,cashbook_first:u,income:0,expenditure:0,cashbook_last:0};if(n.length>0)for(var a=0;a<n.length;a++){var s=Object.assign({},n[a]);if(2!=(null==s?void 0:s.payment_type)){delete s.fee,delete s.discount,delete s.note,delete s.total,delete s.tax;var l=new Date(s.date);1===s.bill_type||7===s.bill_type||10===s.bill_type||11===s.bill_type||34===s.bill_type?l>=t?(o.income=o.income+s.payment,s.index=o.size+1,o.docs.push(s),o.size++,o.empty=!1):o.cashbook_first=o.cashbook_first+s.payment:2!==s.bill_type&&8!==s.bill_type&&12!==s.bill_type&&33!==s.bill_type||(l>=t?(o.expenditure=o.expenditure+s.payment,s.index=o.size+1,o.docs.push(s),o.size++,o.empty=!1):o.cashbook_first=o.cashbook_first-s.payment)}}o.cashbook_last=o.cashbook_first+o.income-o.expenditure,r(o)}))}))},t.prototype.getReportCashBook_old=function(t,e,n,o){var i=this;return t=new Date(t),e=new Date(e),new Promise((function(a,s){var r;r="all"===n?"all"===o||void 0===o?{date:{$lte:e}}:{date:{$lte:e},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$lte:e},id_wallet:{$eq:n}}:{date:{$lte:e},id_wallet:{$eq:n},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("bills",r,{},{date:1},0).then((function(e){var n={docs:new Array,empty:!0,size:0,cashbook_first:0,income:0,expenditure:0,cashbook_last:0};if(e.length>0)for(var o=0;o<e.length;o++){var i=Object.assign({},e[o]);if(2!=(null==i?void 0:i.payment_type)){delete i.fee,delete i.discount,delete i.note,delete i.total,delete i.tax;var s=new Date(i.date);1!==i.bill_type&&7!==i.bill_type&&10!==i.bill_type&&11!==i.bill_type&&34!==i.bill_type||(s>=t?(n.income=n.income+i.payment,i.index=n.size+1,n.docs.push(i),n.size++,n.empty=!1):n.cashbook_first=n.cashbook_first+i.payment),2!==i.bill_type&&8!==i.bill_type&&12!==i.bill_type&&33!==i.bill_type||(s>=t?(n.expenditure=n.expenditure+i.payment,i.index=n.size+1,n.docs.push(i),n.size++,n.empty=!1):n.cashbook_first=n.cashbook_first-i.payment)}}n.cashbook_last=n.cashbook_first+n.income-n.expenditure,a(n)}))}))},t.prototype.syncCashBookEveryDay_Stock1stDayOfMonth=function(){var t=this;return new Promise((function(e,n){var o=t.vhAuth.getStore(),i=[Object.assign({},t.getDefaultBranch())];t.vhmongo_firebase.auth().getServerDate().then((function(n){var a=t.get1stDayOfMonthArray(o.registrationdate,n);if(a.length>0){for(var s=new Array,r=function(n){for(var o=i[n]._id,r=t.getlocalWallets().filter((function(t){return t.id_branch===o||"id_cash"===t._id})),l=new Array,c=function(n){if("id_cash"===r[n]._id)if(null!=r[n][o]&&null!=r[n][o].cashbook){var i=r[n][o].cashbook[r[n][o].cashbook.length-1];if(new Date(i.date).getTime()!=new Date(a[a.length-1]).getTime()){for(var s=r[n][o].cashbook.length;s<a.length;s++)r[n][o].cashbook[s]={},r[n][o].cashbook[s].date=a[s],r[n][o].cashbook[s].cashbook_first=i.cashbook_first;l[n]=new Promise((function(e){for(var a=[],s=[1,7,10,11,34,2,8,12,33];s.length;){var l=s.splice(0,10),c={date:{$gte:new Date(i.date)},id_branch:{$eq:o},id_wallet:{$eq:"id_cash"},bill_type:{$in:l}};a.push(t.vhmongo_firebase.database().getDocsByFields("bills",c,{},{date:1},0))}Promise.all(a).then((function(t){var i=t.flat();if(i.length>0)for(var a=0;a<i.length;a++)if("id_cash"===i[a].id_wallet)for(var s=0;s<r[n][o].cashbook.length;s++)new Date(i[a].date)<new Date(r[n][o].cashbook[s].date)&&(1===i[a].bill_type||7===i[a].bill_type||10===i[a].bill_type||11===i[a].bill_type||34===i[a].bill_type?r[n][o].cashbook[s].cashbook_first=r[n][o].cashbook[s].cashbook_first+i[a].payment:2!==i[a].bill_type&&8!==i[a].bill_type&&12!==i[a].bill_type&&33!==i[a].bill_type||(r[n][o].cashbook[s].cashbook_first=r[n][o].cashbook[s].cashbook_first-i[a].payment));e(r[n])}))}))}else e(null)}else l[n]=new Promise((function(e){for(var i=[],s=[1,7,10,11,34,2,8,12,33];s.length;){var l=s.splice(0,10),c={id_branch:{$eq:o},id_wallet:{$eq:"id_cash"},bill_type:{$in:l}};i.push(t.vhmongo_firebase.database().getDocsByFields("bills",c,{},{date:1},0))}Promise.all(i).then((function(t){var i=t.flat();r[n][o]={},r[n][o].cashbook=new Array;for(var s=0;s<a.length;s++)r[n][o].cashbook[s]={},r[n][o].cashbook[s].date=a[s],r[n][o].cashbook[s].cashbook_first=0;if(i.length>0)for(var l=0;l<i.length;l++)if("id_cash"===i[l].id_wallet)for(s=0;s<r[n][o].cashbook.length;s++)new Date(i[l].date)<new Date(r[n][o].cashbook[s].date)&&(1===i[l].bill_type||7===i[l].bill_type||10===i[l].bill_type||11===i[l].bill_type||34===i[l].bill_type?r[n][o].cashbook[s].cashbook_first=r[n][o].cashbook[s].cashbook_first+i[l].payment:2!==i[l].bill_type&&8!==i[l].bill_type&&12!==i[l].bill_type&&33!==i[l].bill_type||(r[n][o].cashbook[s].cashbook_first=r[n][o].cashbook[s].cashbook_first-i[l].payment));e(r[n])}))}));else if("id_cash"!=r[n]._id)if(null!=r[n].cashbook){var c=r[n].cashbook[r[n].cashbook.length-1];if(new Date(c.date).getTime()!=new Date(a[a.length-1]).getTime()){for(s=r[n].cashbook.length;s<a.length;s++)r[n].cashbook[s]={},r[n].cashbook[s].date=a[s],r[n].cashbook[s].cashbook_first=c.cashbook_first;l[n]=new Promise((function(e){for(var i=[],a=[1,7,10,11,34,2,8,12,33];a.length;){var s=a.splice(0,10),l={date:{$gte:new Date(c.date)},id_branch:{$eq:o},id_wallet:{$eq:r[n]._id},bill_type:{$in:s}};i.push(t.vhmongo_firebase.database().getDocsByFields("bills",l,{},{date:1},0))}Promise.all(i).then((function(t){var o=t.flat();if(o.length>0)for(var i=0;i<o.length;i++)if(o[i].id_wallet===r[n]._id)for(var a=0;a<r[n].cashbook.length;a++)new Date(o[i].date)<new Date(r[n].cashbook[a].date)&&(1===o[i].bill_type||7===o[i].bill_type||10===o[i].bill_type||11===o[i].bill_type||34===o[i].bill_type?r[n].cashbook[a].cashbook_first=r[n].cashbook[a].cashbook_first+o[i].payment:2!==o[i].bill_type&&8!==o[i].bill_type&&12!==o[i].bill_type&&33!==o[i].bill_type||(r[n].cashbook[a].cashbook_first=r[n].cashbook[a].cashbook_first-o[i].payment));e(r[n])}))}))}else e(null)}else l[n]=new Promise((function(e){for(var i=[],s=[1,7,10,11,34,2,8,12,33];s.length;){var l=s.splice(0,10),c={id_branch:{$eq:o},id_wallet:{$eq:r[n]._id},bill_type:{$in:l}};i.push(t.vhmongo_firebase.database().getDocsByFields("bills",c,{},{date:1},0))}Promise.all(i).then((function(t){var o=t.flat();r[n].cashbook=new Array;for(var i=0;i<a.length;i++)r[n].cashbook[i]={},r[n].cashbook[i].date=a[i],r[n].cashbook[i].cashbook_first=0;if(o.length>0)for(var s=0;s<o.length;s++)if(o[s].id_wallet===r[n]._id)for(i=0;i<r[n].cashbook.length;i++)new Date(o[s].date)<new Date(r[n].cashbook[i].date)&&(1===o[s].bill_type||7===o[s].bill_type||10===o[s].bill_type||11===o[s].bill_type||34===o[s].bill_type?r[n].cashbook[i].cashbook_first=r[n].cashbook[i].cashbook_first+o[s].payment:2!==o[s].bill_type&&8!==o[s].bill_type&&12!==o[s].bill_type&&33!==o[s].bill_type||(r[n].cashbook[i].cashbook_first=r[n].cashbook[i].cashbook_first-o[s].payment));e(r[n])}))}))},u=0;u<r.length;u++)c(u);s[n]=new Promise((function(e){Promise.all(l).then((function(n){for(var i=0;i<n.length;i++)if(n[i])if("id_cash"===n[i]._id){var a={};a[o]=n[i][o],t.vhmongo_firebase.database().updateDoc("wallets",n[i]._id,Object.assign({},a))}else t.vhmongo_firebase.database().updateDoc("wallets",n[i]._id,{cashbook:n[i].cashbook});e(n)}))}))},l=0;l<i.length;l++)r(l);Promise.all(s).then((function(t){console.log("syncCashBookEveryDay",t),e(null)}))}else console.log("syncCashBookEveryDay"),e(null)}),(function(t){console.log("syncCashBookEveryDay",t)}))}))},t.prototype.get1stDayOfMonthArray=function(t,e){var n=new Array;for(e=new Date(e),(t=new Date(t)).setDate(1),t.setHours(0),t.setMinutes(0),t.setSeconds(0),t.setMilliseconds(0),t.setMonth(t.getMonth()+1),e.setDate(1),e.setHours(0),e.setMinutes(0),e.setSeconds(0),e.setMilliseconds(0),e.setMonth(e.getMonth()-1);t.getTime()<=e.getTime();)n.push(new Date(t)),t.setMonth(t.getMonth()+1);return n},t.prototype.getValidityDate=function(t){var e=this;return new Promise((function(n,o){t=new Date(t),e.vhmongo_firebase.auth().getServerDate().then((function(o){(o=new Date(o)).setMonth(o.getMonth()-1),o.setDate(1),o.setHours(0),o.setMinutes(0),o.setSeconds(0),t.getTime()>o.getTime()?t.getTime()<new Date(e.vhAuth.getStore().registrationdate).getTime()?n(new Date(e.vhAuth.getStore().registrationdate)):n(null):o.getTime()<new Date(e.vhAuth.getStore().registrationdate).getTime()?n(new Date(e.vhAuth.getStore().registrationdate)):n(o)}))}))},t.prototype.getReportIncomeExpenditureDiary=function(t,e,n,o,i,a){var s=this;return new Promise((function(r,l){var c;"all"===a||void 0===a?("all"===n&&"all"===o&&(c=s.vhmongo_firebase.database().getDocsByFields("bills",{date:{$gte:t,$lte:e},bill_type:{$in:i}},{},{date:1},0)),"all"===n&&"all"!=o&&(c=s.vhmongo_firebase.database().getDocsByFields("bills",{date:{$gte:t,$lte:e},id_employee:{$eq:o},bill_type:{$in:i}},{},{date:1},0)),"all"!=n&&"all"===o&&(c=s.vhmongo_firebase.database().getDocsByFields("bills",{date:{$gte:t,$lte:e},id_wallet:{$eq:n},bill_type:{$in:i}},{},{date:1},0)),"all"!=n&&"all"!=o&&(c=s.vhmongo_firebase.database().getDocsByFields("bills",{date:{$gte:t,$lte:e},id_wallet:{$eq:n},id_employee:{$eq:o},bill_type:{$in:i}},{},{date:1},0))):("all"===n&&"all"===o&&(c=s.vhmongo_firebase.database().getDocsByFields("bills",{date:{$gte:t,$lte:e},bill_type:{$in:i},id_branch:{$eq:a}},{},{date:1},0)),"all"===n&&"all"!=o&&(c=s.vhmongo_firebase.database().getDocsByFields("bills",{date:{$gte:t,$lte:e},id_employee:{$eq:o},bill_type:{$in:i},id_branch:{$eq:a}},{},{date:1},0)),"all"!=n&&"all"===o&&(c=s.vhmongo_firebase.database().getDocsByFields("bills",{date:{$gte:t,$lte:e},id_wallet:{$eq:n},bill_type:{$in:i},id_branch:{$eq:a}},{},{date:1},0)),"all"!=n&&"all"!=o&&(c=s.vhmongo_firebase.database().getDocsByFields("bills",{date:{$gte:t,$lte:e},id_wallet:{$eq:n},id_employee:{$eq:o},bill_type:{$in:i},id_branch:{$eq:a}},{},{date:1},0))),c.then((function(t){var e={docs:new Array,empty:!0,size:0,income:0,expenditure:0};if(t.length>0)for(var n=0;n<t.length;n++){var o=Object.assign({},t[n]);2!=(null==o?void 0:o.payment_type)&&(1!==o.bill_type&&7!==o.bill_type&&10!==o.bill_type&&11!==o.bill_type&&34!==o.bill_type||(e.income=e.income+o.payment,e.docs.push(o),e.size++,e.empty=!1),2!==o.bill_type&&8!==o.bill_type&&12!==o.bill_type&&33!==o.bill_type||(e.expenditure=e.expenditure+o.payment,e.docs.push(o),e.size++,e.empty=!1))}r(e)}))}))},t.prototype.getDebtSuppliers=function(t,e,n,o){var i=this;t=new Date(t),e=new Date(e);var a=this.vhAuth.getStore();return new Promise((function(s,r){var l=new Array;if("all"===n)l=i.vhAlgorithm.sortVietnamesebyASC(i.getlocalSuppliers(),"name");else{var c=i.getlocalSupplier(n);l.push(c)}var u,d=i.getlocalBranchs(),_=i.getDefaultBranch()._id,p=null,b=null;if(null!=l[0][_]&&null!=l[0][_].debt)for(var f=0;f<l[0][_].debt.length&&!(new Date(l[0][_].debt[f].date).getTime()>t.getTime());f++)b=new Date(l[0][_].debt[f].date),p=f;b||(b=new Date(a.registrationdate)),u="all"===n?"all"===o||void 0===o?{date:{$gte:b,$lte:e},bill_type:{$in:[2,10,12]}}:{date:{$gte:b,$lte:e},bill_type:{$in:[2,10,12]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$gte:b,$lte:e},id_supplier:{$eq:n},bill_type:{$in:[2,10,12]}}:{date:{$gte:b,$lte:e},id_supplier:{$eq:n},bill_type:{$in:[2,10,12]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("bills",u,{},{date:1},0).then((function(e){for(var n,i,a={docs:new Array,debt_beginning:0,payment:0,debt:0,rest:0},r=0;r<l.length;r++){var c={_id:l[r]._id,name:l[r].name};a.docs.push(c);for(var u=0,_=0,b=0,f=0,h=0;h<e.length;h++)e[h].id_supplier===l[r]._id&&(new Date(e[h].date).getTime()>=t.getTime()?2===e[h].bill_type?(u+=e[h].total*(1+e[h].tax/100),_+=e[h].payment):12===e[h].bill_type?_+=e[h].payment:10===e[h].bill_type&&(_+=e[h].total*(1+e[h].tax/100),u+=e[h].payment):2===e[h].bill_type?f=f+e[h].total*(1+e[h].tax/100)-e[h].payment:10===e[h].bill_type?f=f+e[h].payment-e[h].total*(1+e[h].tax/100):12===e[h].bill_type&&(f-=e[h].payment));if("all"===o||void 0===o)for(h=0;h<d.length;h++)null!=l[r][d[h]._id]&&null!=l[r][d[h]._id].debt_beginning&&(b+=l[r][d[h]._id].debt_beginning);else null!=l[r][o]&&null!=l[r][o].debt_beginning&&(b=l[r][o].debt_beginning),null!=l[r][o]&&null!=l[r][o].debt&&(p||null!=l[r][o].debt[p]&&(f+=l[r][o].debt[p].debt_first));u=b+f+u,a.docs[a.docs.length-1].index=a.docs.length,a.docs[a.docs.length-1].debt=u,a.docs[a.docs.length-1].payment=_,a.docs[a.docs.length-1].rest=u-_,a.debt_beginning=a.debt_beginning+b,a.debt=a.debt+u,a.payment=a.payment+_,a.rest=a.rest+u-_;var y={docs:new Array,empty:!0,size:0,debt_beginning:b+f,debt:b+f,payment:0,rest:b+f};for(h=0;h<e.length;h++)if(l[r]._id===e[h].id_supplier&&new Date(e[h].date).getTime()>=t.getTime()){var m=Object.assign({},e[h]);null==m||delete m.discount,null==m||delete m.fee,null==m||delete m.id_supplier,null==m||delete m.note,null==m||delete m.payment_type,null==m||delete m.tax,y.docs.push(m),y.docs[y.docs.length-1].debt=0,y.docs[y.docs.length-1].payment=0,2===e[h].bill_type?(y.docs[y.docs.length-1].debt=e[h].total*(1+(null===(n=e[h])||void 0===n?void 0:n.tax)/100),y.docs[y.docs.length-1].payment=e[h].payment,y.docs[y.docs.length-1].rest=y.docs[y.docs.length-1].debt-y.docs[y.docs.length-1].payment):10===e[h].bill_type?(y.docs[y.docs.length-1].payment=e[h].total*(1+(null===(i=e[h])||void 0===i?void 0:i.tax)/100),y.docs[y.docs.length-1].debt=e[h].payment,y.docs[y.docs.length-1].rest=y.docs[y.docs.length-1].debt-y.docs[y.docs.length-1].payment):12===e[h].bill_type&&(y.docs[y.docs.length-1].payment=e[h].payment,y.docs[y.docs.length-1].rest=-e[h].payment),y.debt=y.debt+y.docs[y.docs.length-1].debt,y.payment=y.payment+y.docs[y.docs.length-1].payment,y.rest=y.rest+y.docs[y.docs.length-1].debt-y.docs[y.docs.length-1].payment,y.size++,y.empty=!1,y.docs[y.docs.length-1].index=y.docs.length}a.docs[a.docs.length-1].json=y}console.log("json",a),s(a)}))}))},t.prototype.getDebtCustomers=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=i.vhAuth.getStore(),l=new Array;if("all"===n)l=i.vhAlgorithm.sortVietnamesebyASC(i.getlocalCustomers().filter((function(t){return"id_retail"!=t._id})),"name");else{var c=i.getlocalCustomer(n);l.push(c)}var u,d=i.getlocalBranchs(),_=i.getDefaultBranch()._id,p=null,b=null;if(null!=l[0][_]&&null!=l[0][_].debt)for(var f=0;f<l[0][_].debt.length&&!(new Date(l[0][_].debt[f].date).getTime()>t.getTime());f++)b=new Date(l[0][_].debt[f].date),p=f;b||(b=new Date(r.registrationdate)),u="all"===n?"all"===o||void 0===o?{date:{$gte:b,$lte:e},bill_type:{$in:[1,11]}}:{date:{$gte:b,$lte:e},bill_type:{$in:[1,11]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$gte:b,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1,11]}}:{date:{$gte:b,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1,11]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("bills",u,{},{date:1},0).then((function(e){for(var n,i={docs:new Array,debt_beginning:0,payment:0,debt:0,rest:0},s=0;s<l.length;s++){var r={_id:l[s]._id,name:l[s].name};i.docs.push(r);for(var c=0,u=0,_=0,b=0,f=0;f<e.length;f++)e[f].id_customer===l[s]._id&&(new Date(e[f].date).getTime()>=t.getTime()?1===e[f].bill_type?(c+=e[f].total*(1+e[f].tax/100),u+=e[f].payment):11===e[f].bill_type&&(u+=e[f].payment):1===e[f].bill_type?b=b+e[f].total*(1+e[f].tax/100)-e[f].payment:11===e[f].bill_type&&(b-=e[f].payment));if("all"===o||void 0===o)for(f=0;f<d.length;f++)null!=l[s][d[f]._id]&&null!=l[s][d[f]._id].debt_beginning&&(_+=l[s][d[f]._id].debt_beginning);else null!=l[s][o]&&null!=l[s][o].debt_beginning&&(_=l[s][o].debt_beginning),null!=l[s][o]&&null!=l[s][o].debt&&(p||null!=l[s][o].debt[p]&&(b+=l[s][o].debt[p].debt_first));c=_+b+c,i.docs[i.docs.length-1].index=i.docs.length,i.docs[i.docs.length-1].debt=c,i.docs[i.docs.length-1].payment=u,i.docs[i.docs.length-1].rest=c-u,i.debt_beginning=i.debt_beginning+_,i.debt=i.debt+c,i.payment=i.payment+u,i.rest=i.rest+c-u;var h={docs:new Array,empty:!0,size:0,debt_beginning:_+b,debt:_+b,payment:0,rest:_+b};for(f=0;f<e.length;f++)if(l[s]._id===e[f].id_customer&&new Date(e[f].date).getTime()>=t.getTime()){var y=Object.assign({},e[f]);null==y||delete y.discount,null==y||delete y.fee,null==y||delete y.id_customer,null==y||delete y.note,null==y||delete y.payment_type,null==y||delete y.tax,h.docs.push(y),h.docs[h.docs.length-1].debt=0,h.docs[h.docs.length-1].payment=0,1===e[f].bill_type?(h.docs[h.docs.length-1].debt=e[f].total*(1+(null===(n=e[f])||void 0===n?void 0:n.tax)/100),h.docs[h.docs.length-1].payment=e[f].payment,h.docs[h.docs.length-1].rest=h.docs[h.docs.length-1].debt-h.docs[h.docs.length-1].payment):11===e[f].bill_type&&(h.docs[h.docs.length-1].payment=e[f].payment,h.docs[h.docs.length-1].rest=-e[f].payment),h.debt=h.debt+h.docs[h.docs.length-1].debt,h.payment=h.payment+h.docs[h.docs.length-1].payment,h.rest=h.rest+h.docs[h.docs.length-1].debt-h.docs[h.docs.length-1].payment,h.size++,h.empty=!1,h.docs[h.docs.length-1].index=h.docs.length}i.docs[i.docs.length-1].json=h}console.log("json",i),a(i)}))}))},t.prototype.getReportSales_Categorys_byCategorys=function(t,e,n,o,i){var a=this;return console.log("type",o),o="all"===n?1234:this.getlocalCategory(n).type,console.log("_type",o),new Promise((function(s,r){var l,c,u,d=new Array;1===o?(u=1,c=[1,5]):2===o?(u=2,c=[2,5]):3===o?(u=3,c=[3,5]):4===o?(u=4,c=[4,1,5]):5===o?(u=5,c=[5]):1234===o&&(u=1234,c=[1,2,3,4,5]),"all"===n?(d=a.getlocalCategorys(u),l="all"===i||void 0===i?{date:{$gte:t,$lte:e},ptype:{$in:c},bill_type:{$eq:1}}:{date:{$gte:t,$lte:e},ptype:{$in:c},bill_type:{$eq:1},id_branch:{$eq:i}}):(d.push(a.getlocalCategory(n)),l="all"===i||void 0===i?{date:{$gte:t,$lte:e},ptype:{$in:c},bill_type:{$eq:1}}:{date:{$gte:t,$lte:e},ptype:{$in:c},bill_type:{$eq:1},id_branch:{$eq:i}});var _={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};d.length>0?a.vhmongo_firebase.database().getDocsByFields("vhbill_details",l,{},{date:1},0).then((function(t){if(t.length>0)for(var e=0;e<d.length;e++){for(var n=!1,i=Object.assign({},d[e]),a={id_category:i._id,name:i.name,sales_btax:0,sales_atax:0,quantity:0},r=0;r<t.length;r++)if(1===o||2===o||3===o){if(5===t[r].ptype){if(null!=t[r].combos)for(var l=0;l<t[r].combos.length;l++)d[e]._id===t[r].combos[l].id_category&&(a.quantity=a.quantity+t[r].combos[l].quantity*t[r].quantity,a.sales_btax=a.sales_btax+t[r].combos[l].price*t[r].combos[l].quantity*t[r].quantity,a.sales_atax=a.sales_atax+t[r].combos[l].price*t[r].combos[l].quantity*t[r].quantity*(1+t[r].tax/100))}else if(d[e]._id===t[r].id_category&&(n=!0,a.quantity=a.quantity+t[r].quantity,a.sales_btax=a.sales_btax+t[r].price*t[r].quantity,a.sales_atax=a.sales_atax+t[r].price*t[r].quantity*(1+t[r].tax/100),null!=t[r].toppings))for(l=0;l<t[r].toppings.length;l++)a.quantity=a.quantity+t[r].toppings[l].quantity,a.sales_btax=a.sales_btax+t[r].toppings[l].price*t[r].toppings[l].quantity,a.sales_atax=a.sales_atax+t[r].toppings[l].price*t[r].toppings[l].quantity*(1+t[r].tax/100)}else if(4===o){if(5===t[r].ptype){if(null!=t[r].combos)for(l=0;l<t[r].combos.length;l++)d[e]._id===t[r].combos[l].id_category&&(a.quantity=a.quantity+t[r].combos[l].quantity*t[r].quantity,a.sales_btax=a.sales_btax+t[r].combos[l].price*t[r].combos[l].quantity*t[r].quantity,a.sales_atax=a.sales_atax+t[r].combos[l].price*t[r].combos[l].quantity*t[r].quantity*(1+t[r].tax/100))}else if(4===t[r].ptype)d[e]._id===t[r].id_category&&(n=!0,a.quantity=a.quantity+t[r].quantity,a.sales_btax=a.sales_btax+t[r].price*t[r].quantity,a.sales_atax=a.sales_atax+t[r].price*t[r].quantity*(1+t[r].tax/100));else if(1===t[r].ptype&&null!=t[r].toppings)for(l=0;l<t[r].toppings.length;l++)d[e]._id===t[r].toppings[l].id_category&&(n=!0,a.quantity=a.quantity+t[r].toppings[l].quantity,a.sales_btax=a.sales_btax+t[r].toppings[l].price*t[r].toppings[l].quantity,a.sales_atax=a.sales_atax+t[r].toppings[l].price*t[r].toppings[l].quantity*(1+t[r].tax/100))}else if(5===o){if(5===t[r].ptype&&null!=t[r].combos)for(l=0;l<t[r].combos.length;l++)d[e]._id===t[r].combos[l].id_category&&(a.quantity=a.quantity+t[r].combos[l].quantity*t[r].quantity,a.sales_btax=a.sales_btax+t[r].combos[l].price*t[r].combos[l].quantity*t[r].quantity,a.sales_atax=a.sales_atax+t[r].combos[l].price*t[r].combos[l].quantity*t[r].quantity*(1+t[r].tax/100))}else if(1234===o)if(1===t[r].ptype){if(1===d[e].type&&d[e]._id===t[r].id_category&&(n=!0,a.quantity=a.quantity+t[r].quantity,a.sales_btax=a.sales_btax+t[r].price*t[r].quantity,a.sales_atax=a.sales_atax+t[r].price*t[r].quantity*(1+t[r].tax/100)),4===d[e].type&&null!=t[r].toppings)for(l=0;l<t[r].toppings.length;l++)d[e]._id===t[r].toppings[l].id_category&&(n=!0,a.quantity=a.quantity+t[r].toppings[l].quantity,a.sales_btax=a.sales_btax+t[r].toppings[l].price*t[r].toppings[l].quantity,a.sales_atax=a.sales_atax+t[r].toppings[l].price*t[r].toppings[l].quantity*(1+t[r].tax/100))}else if(2===t[r].ptype)d[e]._id===t[r].id_category&&(n=!0,a.quantity=a.quantity+t[r].quantity,a.sales_btax=a.sales_btax+t[r].price*t[r].quantity,a.sales_atax=a.sales_atax+t[r].price*t[r].quantity*(1+t[r].tax/100));else if(3===t[r].ptype)d[e]._id===t[r].id_category&&(n=!0,a.quantity=a.quantity+t[r].quantity,a.sales_btax=a.sales_btax+t[r].price*t[r].quantity,a.sales_atax=a.sales_atax+t[r].price*t[r].quantity*(1+t[r].tax/100));else if(4===t[r].ptype)d[e]._id===t[r].id_category&&(n=!0,a.quantity=a.quantity+t[r].quantity,a.sales_btax=a.sales_btax+t[r].price*t[r].quantity,a.sales_atax=a.sales_atax+t[r].price*t[r].quantity*(1+t[r].tax/100));else if(5===t[r].ptype)for(l=0;l<t[r].combos.length;l++)d[e]._id===t[r].combos[l].id_category&&(n=!0,a.quantity=a.quantity+t[r].combos[l].quantity*t[r].quantity,a.sales_btax=a.sales_btax+t[r].combos[l].price*t[r].combos[l].quantity*t[r].quantity,a.sales_atax=a.sales_atax+t[r].combos[l].price*t[r].combos[l].quantity*t[r].quantity*(1+t[r].tax/100));n&&(a.sales_atax=Math.round(1e6*a.sales_atax)/1e6,null!=a.subs&&a.subs.forEach((function(t){t.sales_atax=Math.round(1e6*t.sales_atax)/1e6})),null!=a.combos&&a.combos.forEach((function(t){t.sales_atax=Math.round(1e6*t.sales_atax)/1e6})),_.quantity=_.quantity+a.quantity,_.sales_btax=_.sales_btax+a.sales_btax,_.sales_atax=_.sales_atax+a.sales_atax,a.index=_.size+1,_.docs.push(a),_.size++,_.empty=!1)}console.log("getReportSales_Categorys_byCategorys"),s(_)})):s(_)}))},t.prototype.getReportSales_Categorys_byProducts=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l,c=i.getlocalProducts().filter((function(t){if(t.id_category===n)return!0})),u=i.getlocalCategory(n).type;1===u?r=[1,5]:2===u?r=[2,5]:3===u?r=[3,5]:4===u?r=[4,1,5]:5===u&&(r=[5]),l="all"===o||void 0===o?{date:{$gte:t,$lte:e},ptype:{$in:r},bill_type:{$eq:1}}:{date:{$gte:t,$lte:e},ptype:{$in:r},bill_type:{$eq:1},id_branch:{$eq:o}};var d={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};c.length>0?i.vhmongo_firebase.database().getDocsByFields("vhbill_details",l,{},{date:1},0).then((function(t){var e,n;if(t.length>0)for(var o=0;o<c.length;o++){var i=!1,s=Object.assign({},c[o]),r={id_product:s._id,name:s.name,unit:s.unit,barcode:s.barcode,img:s.img,sales_btax:0,sales_atax:0,quantity:0};if(null!=s.subs){r.subs=new Array;for(var l=0;l<s.subs.length;l++){var _={id_subproduct:s.subs[l]._id,name:null===(e=s.subs[l])||void 0===e?void 0:e.name,sales_btax:0,sales_atax:0,quantity:0};r.subs.push(_)}}if(null!=s.combos){r.combos=new Array;for(l=0;l<s.combos.length;l++){var p={id_product:s.combos[l].id_product,name:null===(n=s.combos[l])||void 0===n?void 0:n.name,sales_btax:0,sales_atax:0,quantity:0};null!=s.combos[l].id_subproduct&&(p.id_subproduct=s.combos[l].id_subproduct),r.combos.push(p)}}for(var b=0;b<t.length;b++)if(1===u){if(1===t[b].ptype){if(c[o]._id===t[b].id_product&&(i=!0,r.quantity=r.quantity+t[b].quantity,r.sales_btax=r.sales_btax+t[b].price*t[b].quantity,r.sales_atax=r.sales_atax+t[b].price*t[b].quantity*(1+t[b].tax/100),null!=r.subs))for(l=0;l<r.subs.length;l++)if(c[o].subs[l]._id===t[b].id_subproduct){r.subs[l].quantity=r.subs[l].quantity+t[b].quantity,r.subs[l].sales_btax=r.subs[l].sales_btax+t[b].price*t[b].quantity,r.subs[l].sales_atax=r.subs[l].sales_atax+t[b].price*t[b].quantity*(1+t[b].tax/100);break}}else if(5===t[b].ptype)for(var f=0;f<t[b].combos.length;f++)if(c[o]._id===t[b].combos[f].id_product&&(i=!0,r.quantity=r.quantity+t[b].combos[f].quantity*t[b].quantity,r.sales_btax=r.sales_btax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity,r.sales_atax=r.sales_atax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity*(1+t[b].tax/100),null!=r.subs))for(l=0;l<r.subs.length;l++)if(c[o].subs[l]._id===t[b].combos[f].id_subproduct){r.subs[l].quantity=r.subs[l].quantity+t[b].combos[f].quantity*t[b].quantity,r.subs[l].sales_btax=r.subs[l].sales_btax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity,r.subs[l].sales_atax=r.subs[l].sales_atax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity*(1+t[b].tax/100);break}}else if(2===u){if(2===t[b].ptype)c[o]._id===t[b].id_product&&(i=!0,r.quantity=r.quantity+t[b].quantity,r.sales_btax=r.sales_btax+t[b].price*t[b].quantity,r.sales_atax=r.sales_atax+t[b].price*t[b].quantity*(1+t[b].tax/100));else if(5===t[b].ptype)for(f=0;f<t[b].combos.length;f++)c[o]._id===t[b].combos[f].id_product&&(i=!0,r.quantity=r.quantity+t[b].combos[f].quantity*t[b].quantity,r.sales_btax=r.sales_btax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity,r.sales_atax=r.sales_atax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity*(1+t[b].tax/100))}else if(3===u){if(3===t[b].ptype)c[o]._id===t[b].id_product&&(i=!0,r.quantity=r.quantity+t[b].quantity,r.sales_btax=r.sales_btax+t[b].price*t[b].quantity,r.sales_atax=r.sales_atax+t[b].price*t[b].quantity*(1+t[b].tax/100));else if(5===t[b].ptype)for(f=0;f<t[b].combos.length;f++)c[o]._id===t[b].combos[f].id_product&&(i=!0,r.quantity=r.quantity+t[b].combos[f].quantity*t[b].quantity,r.sales_btax=r.sales_btax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity,r.sales_atax=r.sales_atax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity*(1+t[b].tax/100))}else if(4===u){if(4===t[b].ptype)c[o]._id===t[b].id_product&&(i=!0,r.quantity=r.quantity+t[b].quantity,r.sales_btax=r.sales_btax+t[b].price*t[b].quantity,r.sales_atax=r.sales_atax+t[b].price*t[b].quantity*(1+t[b].tax/100));else if(1===t[b].ptype){if(null!=t[b].toppings)for(f=0;f<t[b].toppings.length;f++)c[o]._id===t[b].toppings[f].id_product&&(i=!0,r.quantity=r.quantity+t[b].toppings[f].quantity,r.sales_btax=r.sales_btax+t[b].toppings[f].price*t[b].toppings[f].quantity,r.sales_atax=r.sales_atax+t[b].toppings[f].price*t[b].toppings[f].quantity*(1+t[b].tax/100))}else if(5===t[b].ptype)for(f=0;f<t[b].combos.length;f++)c[o]._id===t[b].combos[f].id_product&&(i=!0,r.quantity=r.quantity+t[b].combos[f].quantity*t[b].quantity,r.sales_btax=r.sales_btax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity,r.sales_atax=r.sales_atax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity*(1+t[b].tax/100))}else if(5===u&&5===t[b].ptype&&c[o]._id===t[b].id_product&&(i=!0,r.quantity=r.quantity+t[b].quantity,r.sales_btax=r.sales_btax+t[b].price*t[b].quantity,r.sales_atax=r.sales_atax+t[b].price*t[b].quantity*(1+t[b].tax/100),null!=r.combos))for(l=0;l<r.combos.length;l++)c[o].combos[l].id_product===t[b].combos[l].id_product&&(r.combos[l].quantity=r.combos[l].quantity+t[b].combos[l].quantity*t[b].quantity,r.combos[l].sales_btax=r.combos[l].sales_btax+t[b].combos[l].price*t[b].combos[l].quantity*t[b].quantity,r.combos[l].sales_atax=r.combos[l].sales_atax+t[b].combos[l].price*t[b].combos[l].quantity*t[b].quantity*(1+t[b].tax/100));i&&(r.sales_atax=Math.round(1e6*r.sales_atax)/1e6,null!=r.subs&&r.subs.forEach((function(t){t.sales_atax=Math.round(1e6*t.sales_atax)/1e6})),null!=r.combos&&r.combos.forEach((function(t){t.sales_atax=Math.round(1e6*t.sales_atax)/1e6})),d.quantity=d.quantity+r.quantity,d.sales_btax=d.sales_btax+r.sales_btax,d.sales_atax=d.sales_atax+r.sales_atax,r.index=d.size+1,d.docs.push(r),d.size++,d.empty=!1)}console.log("jsons",d),a(d)})):a(d)}))},t.prototype.getReportSales_Categorys_byProduct=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=i.getlocalProduct(n),l=new Array;i.getlocalProductAndCombosAndToppings(n).forEach((function(t){l.push(t._id)}));var c,u=r.type,d={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};c="all"===o||void 0===o?{date:{$gte:t,$lte:e},id_product:{$in:l},bill_type:{$eq:1}}:{date:{$gte:t,$lte:e},id_product:{$in:l},bill_type:{$eq:1},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("vhbill_details",c,{},{date:1},0).then((function(t){var e;if(t.length>0)for(var n=0;n<t.length;n++){var o=new Array;if(o[0]={id_product:r._id,name:r.name,unit:r.unit,barcode:r.barcode,img:r.img,bill_code:t[n].bill_code,bill_type:t[n].bill_type,id_bill:t[n].id_bill,date:t[n].date,tax:t[n].tax,salesman:null===(e=i.vhAuth.getlocalEmployee(t[n].id_employee))||void 0===e?void 0:e.name,customer:i.getlocalCustomer(t[n].id_customer).name},1===u){if(null!=t[n].combos){for(var s=0,l=Object.assign({},o[0]),c=0;c<t[n].combos.length;c++)if(t[n].combos[c].id_product===r._id)if(null!=r.subs)for(var _=0;_<r.subs.length;_++)t[n].combos[c].id_subproduct===r.subs[_]._id&&(0==s?(o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price,o[0].id_subproduct=r.subs[_]._id,o[0].name=o[0].name+"("+r.subs[_].name+")"):(o[s]=Object.assign({},l),o[s].quantity=t[n].combos[c].quantity*t[n].quantity,o[s].price=t[n].combos[c].price,o[s].id_subproduct=r.subs[_]._id,o[s].name=o[s].name+"("+r.subs[_].name+")"),s++);else o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price}else if(o[0].quantity=t[n].quantity,o[0].price=t[n].price,null!=r.subs)for(_=0;_<r.subs.length;_++)if(t[n].id_subproduct===r.subs[_]._id){o[0].id_subproduct=r.subs[_]._id,o[0].name=o[0].name+"("+r.subs[_].name+")";break}}else if(2===u||3===u)if(null!=t[n].combos){for(c=0;c<t[n].combos.length;c++)if(t[n].combos[c].id_product===r._id){o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price;break}}else o[0].quantity=t[n].quantity,o[0].price=t[n].price;else if(4===u)if(null!=t[n].toppings){for(c=0;c<t[n].toppings.length;c++)if(t[n].toppings[c].id_product===r._id){o[0].quantity=t[n].toppings[c].quantity,o[0].price=t[n].toppings[c].price;break}}else o[0].quantity=t[n].quantity,o[0].price=t[n].price;else 5===u&&(o[0].quantity=t[n].quantity,o[0].price=t[n].price);o.forEach((function(t){t.sales_btax=t.price*t.quantity,t.sales_atax=t.price*t.quantity*(1+t.tax/100),t.index=d.size+1,d.docs.push(t),d.size++,d.empty=!1,d.quantity=d.quantity+t.quantity,d.sales_btax=d.sales_btax+t.price*t.quantity,d.sales_atax=d.sales_atax+t.price*t.quantity*(1+Number(t.tax)/100)}))}console.log("json",d),a(d)}))}))},t.prototype.getReportSales_Areas_byAreas=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Array;if("all"===n)r=i.getlocalAreas();else{var l=i.getlocalArea(n);r.push(l)}var c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};if(r.length>0){var u=void 0;u="all"===n?"all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$gte:t,$lte:e},id_area:{$eq:n},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},id_area:{$eq:n},bill_type:{$in:[1]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0).then((function(t){if(t.length>0)for(var e=0;e<r.length;e++){for(var n=!1,o={id_area:r[e]._id,name:r[e].name,sales_btax:0,sales_atax:0,quantity:0},i=0;i<t.length;i++)if(r[e]._id===t[i].id_area)if(5===t[i].ptype){if(null!=t[i].combos)for(var s=0;s<t[i].combos.length;s++)o.quantity=o.quantity+t[i].combos[s].quantity*t[i].quantity,o.sales_btax=o.sales_btax+t[i].combos[s].price*t[i].combos[s].quantity*t[i].quantity,o.sales_atax=o.sales_atax+t[i].combos[s].price*t[i].combos[s].quantity*t[i].quantity*(1+t[i].tax/100)}else if(n=!0,o.quantity=o.quantity+t[i].quantity,o.sales_btax=o.sales_btax+t[i].price*t[i].quantity,o.sales_atax=o.sales_atax+t[i].price*t[i].quantity*(1+t[i].tax/100),null!=t[i].toppings)for(s=0;s<t[i].toppings.length;s++)o.quantity=o.quantity+t[i].toppings[s].quantity,o.sales_btax=o.sales_btax+t[i].toppings[s].price*t[i].toppings[s].quantity,o.sales_atax=o.sales_atax+t[i].toppings[s].price*t[i].toppings[s].quantity*(1+t[i].tax/100);n&&(c.quantity=c.quantity+o.quantity,c.sales_btax=c.sales_btax+o.sales_btax,c.sales_atax=c.sales_atax+o.sales_atax,o.index=c.size+1,c.docs.push(o),c.size++,c.empty=!1)}a(c)}))}else a(c)}))},t.prototype.getReportSales_Areas_byProducts=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l=i.getlocalProducts(1234);r=r="all"===o||void 0===o?{date:{$gte:t,$lte:e},id_area:{$eq:n},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},id_area:{$eq:n},bill_type:{$in:[1]},id_branch:{$eq:o}};var c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};l.length>0?i.vhmongo_firebase.database().getDocsByFields("vhbill_details",r,{},{date:1},0).then((function(t){var e;if(t.length>0)for(var n=0;n<l.length;n++){var o=!1,i=Object.assign({},l[n]),s={id_product:i._id,name:i.name,unit:i.unit,barcode:i.barcode,img:i.img,sales_btax:0,sales_atax:0,quantity:0,subs:new Array};if(null!=i.subs)for(var r=0;r<i.subs.length;r++){var u={id_subproduct:i.subs[r]._id,name:null===(e=i.subs[r])||void 0===e?void 0:e.name,sales_btax:0,sales_atax:0,quantity:0};s.subs.push(u)}for(var d=0;d<t.length;d++)if(1===t[d].ptype){if(1===l[n].type&&l[n]._id===t[d].id_product&&(o=!0,s.quantity=s.quantity+t[d].quantity,s.sales_btax=s.sales_btax+t[d].price*t[d].quantity,s.sales_atax=s.sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100),null!=s.subs))for(r=0;r<s.subs.length;r++)if(l[n].subs[r]._id===t[d].id_subproduct){s.subs[r].quantity=s.subs[r].quantity+t[d].quantity,s.subs[r].sales_btax=s.subs[r].sales_btax+t[d].price*t[d].quantity,s.subs[r].sales_atax=s.subs[r].sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100);break}if(4===l[n].type&&null!=t[d].toppings)for(var _=0;_<t[d].toppings.length;_++)l[n]._id===t[d].toppings[_].id_product&&(o=!0,s.quantity=s.quantity+t[d].toppings[_].quantity,s.sales_btax=s.sales_btax+t[d].toppings[_].price*t[d].toppings[_].quantity,s.sales_atax=s.sales_atax+t[d].toppings[_].price*t[d].toppings[_].quantity*(1+t[d].tax/100))}else if(2===t[d].ptype)l[n]._id===t[d].id_product&&(o=!0,s.quantity=s.quantity+t[d].quantity,s.sales_btax=s.sales_btax+t[d].price*t[d].quantity,s.sales_atax=s.sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100));else if(3===t[d].ptype)l[n]._id===t[d].id_product&&(o=!0,s.quantity=s.quantity+t[d].quantity,s.sales_btax=s.sales_btax+t[d].price*t[d].quantity,s.sales_atax=s.sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100));else if(4===t[d].ptype)l[n]._id===t[d].id_product&&(o=!0,s.quantity=s.quantity+t[d].quantity,s.sales_btax=s.sales_btax+t[d].price*t[d].quantity,s.sales_atax=s.sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100));else if(5===t[d].ptype)for(_=0;_<t[d].combos.length;_++)if(l[n]._id===t[d].combos[_].id_product&&(o=!0,s.quantity=s.quantity+t[d].combos[_].quantity*t[d].quantity,s.sales_btax=s.sales_btax+t[d].combos[_].price*t[d].combos[_].quantity*t[d].quantity,s.sales_atax=s.sales_atax+t[d].combos[_].price*t[d].combos[_].quantity*t[d].quantity*(1+t[d].tax/100),null!=s.subs))for(r=0;r<s.subs.length;r++)if(l[n].subs[r]._id===t[d].combos[_].id_subproduct){s.subs[r].quantity=s.subs[r].quantity+t[d].combos[_].quantity*t[d].quantity,s.subs[r].sales_btax=s.subs[r].sales_btax+t[d].combos[_].price*t[d].combos[_].quantity*t[d].quantity,s.subs[r].sales_atax=s.subs[r].sales_atax+t[d].combos[_].price*t[d].combos[_].quantity*t[d].quantity*(1+t[d].tax/100);break}o&&(s.sales_atax=Math.round(1e6*s.sales_atax)/1e6,null!=s.subs&&s.subs.forEach((function(t){t.sales_atax=Math.round(1e6*t.sales_atax)/1e6})),c.quantity=c.quantity+s.quantity,c.sales_btax=c.sales_btax+s.sales_btax,c.sales_atax=c.sales_atax+s.sales_atax,s.index=c.size+1,c.docs.push(s),c.size++,c.empty=!1)}console.log("getReportSales_Areas_byProducts"),a(c)})):a(c)}))},t.prototype.getReportSales_Areas_byProduct=function(t,e,n,o,i){var a=this;return new Promise((function(s,r){var l=a.getlocalProduct(o),c=new Array;a.getlocalProductAndCombosAndToppings(o).forEach((function(t){c.push(t._id)}));var u,d=l.type,_={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};u="all"===i||void 0===i?{date:{$gte:t,$lte:e},id_area:{$eq:n},id_product:{$in:c},bill_type:{$eq:1}}:{date:{$gte:t,$lte:e},id_area:{$eq:n},id_product:{$in:c},bill_type:{$eq:1},id_branch:{$eq:i}},a.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0).then((function(t){var e;if(t.length>0)for(var n=0;n<t.length;n++){var o=new Array;if(o[0]={id_product:l._id,name:l.name,unit:l.unit,barcode:l.barcode,img:l.img,bill_code:t[n].bill_code,bill_type:t[n].bill_type,id_bill:t[n].id_bill,date:t[n].date,tax:t[n].tax,salesman:null===(e=a.vhAuth.getlocalEmployee(t[n].id_employee))||void 0===e?void 0:e.name,customer:a.getlocalCustomer(t[n].id_customer).name},1===d){if(null!=t[n].combos){for(var i=0,r=Object.assign({},o[0]),c=0;c<t[n].combos.length;c++)if(t[n].combos[c].id_product===l._id)if(null!=l.subs)for(var u=0;u<l.subs.length;u++)t[n].combos[c].id_subproduct===l.subs[u]._id&&(0==i?(o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price,o[0].id_subproduct=l.subs[u]._id,o[0].name=o[0].name+"("+l.subs[u].name+")"):(o[i]=Object.assign({},r),o[i].quantity=t[n].combos[c].quantity*t[n].quantity,o[i].price=t[n].combos[c].price,o[i].id_subproduct=l.subs[u]._id,o[i].name=o[i].name+"("+l.subs[u].name+")"),i++);else o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price}else if(o[0].quantity=t[n].quantity,o[0].price=t[n].price,null!=l.subs)for(u=0;u<l.subs.length;u++)if(t[n].id_subproduct===l.subs[u]._id){o[0].id_subproduct=l.subs[u]._id,o[0].name=o[0].name+"("+l.subs[u].name+")";break}}else if(2===d||3===d)if(null!=t[n].combos){for(c=0;c<t[n].combos.length;c++)if(t[n].combos[c].id_product===l._id){o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price;break}}else o[0].quantity=t[n].quantity,o[0].price=t[n].price;else if(4===d)if(null!=t[n].toppings){for(c=0;c<t[n].toppings.length;c++)if(t[n].toppings[c].id_product===l._id){o[0].quantity=t[n].toppings[c].quantity,o[0].price=t[n].toppings[c].price;break}}else o[0].quantity=t[n].quantity,o[0].price=t[n].price;else 5===d&&(o[0].quantity=t[n].quantity,o[0].price=t[n].price);o.forEach((function(t){t.sales_btax=t.price*t.quantity,t.sales_atax=t.price*t.quantity*(1+t.tax/100),t.index=_.size+1,_.docs.push(t),_.size++,_.empty=!1,_.quantity=_.quantity+t.quantity,_.sales_btax=_.sales_btax+t.price*t.quantity,_.sales_atax=_.sales_atax+t.price*t.quantity*(1+Number(t.tax)/100)}))}console.log("getReportSales_Areas_byProduct"),s(_)}))}))},t.prototype.getReportSales_Products_byProducts=function(t,e,n,o,i){var a=this;return console.log("type",o),new Promise((function(s,r){var l,c,u,d=new Array;if(1===o?(u=1,c=[1,5]):2===o?(u=2,c=[2,5]):3===o?(u=3,c=[3,5]):4===o?(u=4,c=[4,1,5]):5===o?(u=5,c=[5]):1234===o&&(u=1234,c=[1,2,3,4,5]),"all"===n)d=a.getlocalProducts(u),l="all"===i||void 0===i?{date:{$gte:t,$lte:e},ptype:{$in:c},bill_type:{$eq:1}}:{date:{$gte:t,$lte:e},ptype:{$in:c},bill_type:{$eq:1},id_branch:{$eq:i}};else{d.push(a.getlocalProduct(n));var _=new Array;a.getlocalProductAndCombosAndToppings(n).forEach((function(t){_.push(t._id)})),l="all"===i||void 0===i?{date:{$gte:t,$lte:e},id_product:{$in:_},bill_type:{$eq:1}}:{date:{$gte:t,$lte:e},id_product:{$in:_},bill_type:{$eq:1},id_branch:{$eq:i}}}var p={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};d.length>0?a.vhmongo_firebase.database().getDocsByFields("vhbill_details",l,{},{date:1},0).then((function(t){var e,n;if(t.length>0)for(var i=0;i<d.length;i++){var a=!1,r=Object.assign({},d[i]),l={id_product:r._id,name:r.name,unit:r.unit,barcode:r.barcode,img:r.img,sales_btax:0,sales_atax:0,quantity:0};if(null!=r.subs){l.subs=new Array;for(var c=0;c<r.subs.length;c++){var u={id_subproduct:r.subs[c]._id,name:null===(e=r.subs[c])||void 0===e?void 0:e.name,sales_btax:0,sales_atax:0,quantity:0};l.subs.push(u)}}if(null!=r.combos){l.combos=new Array;for(c=0;c<r.combos.length;c++){var _={id_product:r.combos[c].id_product,name:null===(n=r.combos[c])||void 0===n?void 0:n.name,sales_btax:0,sales_atax:0,quantity:0};null!=r.combos[c].id_subproduct&&(_.id_subproduct=r.combos[c].id_subproduct),l.combos.push(_)}}for(var b=0;b<t.length;b++)if(1===o){if(1===t[b].ptype){if(d[i]._id===t[b].id_product&&(a=!0,l.quantity=l.quantity+t[b].quantity,l.sales_btax=l.sales_btax+t[b].price*t[b].quantity,l.sales_atax=l.sales_atax+t[b].price*t[b].quantity*(1+t[b].tax/100),null!=l.subs))for(c=0;c<l.subs.length;c++)if(d[i].subs[c]._id===t[b].id_subproduct){l.subs[c].quantity=l.subs[c].quantity+t[b].quantity,l.subs[c].sales_btax=l.subs[c].sales_btax+t[b].price*t[b].quantity,l.subs[c].sales_atax=l.subs[c].sales_atax+t[b].price*t[b].quantity*(1+t[b].tax/100);break}}else if(5===t[b].ptype)for(var f=0;f<t[b].combos.length;f++)if(d[i]._id===t[b].combos[f].id_product&&(a=!0,l.quantity=l.quantity+t[b].combos[f].quantity*t[b].quantity,l.sales_btax=l.sales_btax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity,l.sales_atax=l.sales_atax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity*(1+t[b].tax/100),null!=l.subs))for(c=0;c<l.subs.length;c++)if(d[i].subs[c]._id===t[b].combos[f].id_subproduct){l.subs[c].quantity=l.subs[c].quantity+t[b].combos[f].quantity*t[b].quantity,l.subs[c].sales_btax=l.subs[c].sales_btax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity,l.subs[c].sales_atax=l.subs[c].sales_atax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity*(1+t[b].tax/100);break}}else if(2===o){if(2===t[b].ptype)d[i]._id===t[b].id_product&&(a=!0,l.quantity=l.quantity+t[b].quantity,l.sales_btax=l.sales_btax+t[b].price*t[b].quantity,l.sales_atax=l.sales_atax+t[b].price*t[b].quantity*(1+t[b].tax/100));else if(5===t[b].ptype)for(f=0;f<t[b].combos.length;f++)d[i]._id===t[b].combos[f].id_product&&(a=!0,l.quantity=l.quantity+t[b].combos[f].quantity*t[b].quantity,l.sales_btax=l.sales_btax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity,l.sales_atax=l.sales_atax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity*(1+t[b].tax/100))}else if(3===o){if(3===t[b].ptype)d[i]._id===t[b].id_product&&(a=!0,l.quantity=l.quantity+t[b].quantity,l.sales_btax=l.sales_btax+t[b].price*t[b].quantity,l.sales_atax=l.sales_atax+t[b].price*t[b].quantity*(1+t[b].tax/100));else if(5===t[b].ptype)for(f=0;f<t[b].combos.length;f++)d[i]._id===t[b].combos[f].id_product&&(a=!0,l.quantity=l.quantity+t[b].combos[f].quantity*t[b].quantity,l.sales_btax=l.sales_btax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity,l.sales_atax=l.sales_atax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity*(1+t[b].tax/100))}else if(4===o){if(4===t[b].ptype)d[i]._id===t[b].id_product&&(a=!0,l.quantity=l.quantity+t[b].quantity,l.sales_btax=l.sales_btax+t[b].price*t[b].quantity,l.sales_atax=l.sales_atax+t[b].price*t[b].quantity*(1+t[b].tax/100));else if(1===t[b].ptype){if(null!=t[b].toppings)for(f=0;f<t[b].toppings.length;f++)d[i]._id===t[b].toppings[f].id_product&&(a=!0,l.quantity=l.quantity+t[b].toppings[f].quantity,l.sales_btax=l.sales_btax+t[b].toppings[f].price*t[b].toppings[f].quantity,l.sales_atax=l.sales_atax+t[b].toppings[f].price*t[b].toppings[f].quantity*(1+t[b].tax/100))}else if(5===t[b].ptype)for(f=0;f<t[b].combos.length;f++)d[i]._id===t[b].combos[f].id_product&&(a=!0,l.quantity=l.quantity+t[b].combos[f].quantity*t[b].quantity,l.sales_btax=l.sales_btax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity,l.sales_atax=l.sales_atax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity*(1+t[b].tax/100))}else if(5===o){if(5===t[b].ptype&&d[i]._id===t[b].id_product&&(a=!0,l.quantity=l.quantity+t[b].quantity,l.sales_btax=l.sales_btax+t[b].price*t[b].quantity,l.sales_atax=l.sales_atax+t[b].price*t[b].quantity*(1+t[b].tax/100),null!=l.combos))for(c=0;c<l.combos.length;c++)d[i].combos[c].id_product===t[b].combos[c].id_product&&(l.combos[c].quantity=l.combos[c].quantity+t[b].combos[c].quantity*t[b].quantity,l.combos[c].sales_btax=l.combos[c].sales_btax+t[b].combos[c].price*t[b].combos[c].quantity*t[b].quantity,l.combos[c].sales_atax=l.combos[c].sales_atax+t[b].combos[c].price*t[b].combos[c].quantity*t[b].quantity*(1+t[b].tax/100))}else if(1234===o)if(1===t[b].ptype){if(1===d[i].type&&d[i]._id===t[b].id_product&&(a=!0,l.quantity=l.quantity+t[b].quantity,l.sales_btax=l.sales_btax+t[b].price*t[b].quantity,l.sales_atax=l.sales_atax+t[b].price*t[b].quantity*(1+t[b].tax/100),null!=l.subs))for(c=0;c<l.subs.length;c++)if(d[i].subs[c]._id===t[b].id_subproduct){l.subs[c].quantity=l.subs[c].quantity+t[b].quantity,l.subs[c].sales_btax=l.subs[c].sales_btax+t[b].price*t[b].quantity,l.subs[c].sales_atax=l.subs[c].sales_atax+t[b].price*t[b].quantity*(1+t[b].tax/100);break}if(4===d[i].type&&null!=t[b].toppings)for(f=0;f<t[b].toppings.length;f++)d[i]._id===t[b].toppings[f].id_product&&(a=!0,l.quantity=l.quantity+t[b].toppings[f].quantity,l.sales_btax=l.sales_btax+t[b].toppings[f].price*t[b].toppings[f].quantity,l.sales_atax=l.sales_atax+t[b].toppings[f].price*t[b].toppings[f].quantity*(1+t[b].tax/100))}else if(2===t[b].ptype)d[i]._id===t[b].id_product&&(a=!0,l.quantity=l.quantity+t[b].quantity,l.sales_btax=l.sales_btax+t[b].price*t[b].quantity,l.sales_atax=l.sales_atax+t[b].price*t[b].quantity*(1+t[b].tax/100));else if(3===t[b].ptype)d[i]._id===t[b].id_product&&(a=!0,l.quantity=l.quantity+t[b].quantity,l.sales_btax=l.sales_btax+t[b].price*t[b].quantity,l.sales_atax=l.sales_atax+t[b].price*t[b].quantity*(1+t[b].tax/100));else if(4===t[b].ptype)d[i]._id===t[b].id_product&&(a=!0,l.quantity=l.quantity+t[b].quantity,l.sales_btax=l.sales_btax+t[b].price*t[b].quantity,l.sales_atax=l.sales_atax+t[b].price*t[b].quantity*(1+t[b].tax/100));else if(5===t[b].ptype)for(f=0;f<t[b].combos.length;f++)if(d[i]._id===t[b].combos[f].id_product&&(a=!0,l.quantity=l.quantity+t[b].combos[f].quantity*t[b].quantity,l.sales_btax=l.sales_btax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity,l.sales_atax=l.sales_atax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity*(1+t[b].tax/100),null!=l.subs))for(c=0;c<l.subs.length;c++)if(d[i].subs[c]._id===t[b].combos[f].id_subproduct){l.subs[c].quantity=l.subs[c].quantity+t[b].combos[f].quantity*t[b].quantity,l.subs[c].sales_btax=l.subs[c].sales_btax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity,l.subs[c].sales_atax=l.subs[c].sales_atax+t[b].combos[f].price*t[b].combos[f].quantity*t[b].quantity*(1+t[b].tax/100);break}a&&(l.sales_atax=Math.round(1e6*l.sales_atax)/1e6,null!=l.subs&&l.subs.forEach((function(t){t.sales_atax=Math.round(1e6*t.sales_atax)/1e6})),null!=l.combos&&l.combos.forEach((function(t){t.sales_atax=Math.round(1e6*t.sales_atax)/1e6})),p.quantity=p.quantity+l.quantity,p.sales_btax=p.sales_btax+l.sales_btax,p.sales_atax=p.sales_atax+l.sales_atax,l.index=p.size+1,p.docs.push(l),p.size++,p.empty=!1)}console.log("jsons",p),s(p)})):s(p)}))},t.prototype.getReportSales_Products_byProduct=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=i.getlocalProduct(n),l=new Array;i.getlocalProductAndCombosAndToppings(n).forEach((function(t){l.push(t._id)}));var c,u=r.type,d={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};c="all"===o||void 0===o?{date:{$gte:t,$lte:e},id_product:{$in:l},bill_type:{$eq:1}}:{date:{$gte:t,$lte:e},id_product:{$in:l},bill_type:{$eq:1},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("vhbill_details",c,{},{date:1},0).then((function(t){var e;if(t.length>0)for(var n=0;n<t.length;n++){var o=new Array;if(o[0]={id_product:r._id,name:r.name,unit:r.unit,barcode:r.barcode,img:r.img,bill_code:t[n].bill_code,bill_type:t[n].bill_type,id_bill:t[n].id_bill,date:t[n].date,tax:t[n].tax,salesman:null===(e=i.vhAuth.getlocalEmployee(t[n].id_employee))||void 0===e?void 0:e.name,customer:i.getlocalCustomer(t[n].id_customer).name},1===u){if(null!=t[n].combos){for(var s=0,l=Object.assign({},o[0]),c=0;c<t[n].combos.length;c++)if(t[n].combos[c].id_product===r._id)if(null!=r.subs)for(var _=0;_<r.subs.length;_++)t[n].combos[c].id_subproduct===r.subs[_]._id&&(0==s?(o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price,o[0].id_subproduct=r.subs[_]._id,o[0].name=o[0].name+"("+r.subs[_].name+")"):(o[s]=Object.assign({},l),o[s].quantity=t[n].combos[c].quantity*t[n].quantity,o[s].price=t[n].combos[c].price,o[s].id_subproduct=r.subs[_]._id,o[s].name=o[s].name+"("+r.subs[_].name+")"),s++);else o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price}else if(o[0].quantity=t[n].quantity,o[0].price=t[n].price,null!=r.subs)for(_=0;_<r.subs.length;_++)if(t[n].id_subproduct===r.subs[_]._id){o[0].id_subproduct=r.subs[_]._id,o[0].name=o[0].name+"("+r.subs[_].name+")";break}}else if(2===u||3===u)if(null!=t[n].combos){for(c=0;c<t[n].combos.length;c++)if(t[n].combos[c].id_product===r._id){o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price;break}}else o[0].quantity=t[n].quantity,o[0].price=t[n].price;else if(4===u)if(null!=t[n].combos){for(c=0;c<t[n].combos.length;c++)if(t[n].combos[c].id_product===r._id){o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price;break}}else if(null!=t[n].toppings){for(c=0;c<t[n].toppings.length;c++)if(t[n].toppings[c].id_product===r._id){o[0].quantity=t[n].toppings[c].quantity,o[0].price=t[n].toppings[c].price;break}}else o[0].quantity=t[n].quantity,o[0].price=t[n].price;else 5===u&&(o[0].quantity=t[n].quantity,o[0].price=t[n].price);o.forEach((function(t){t.sales_btax=t.price*t.quantity,t.sales_atax=t.price*t.quantity*(1+t.tax/100),t.index=d.size+1,d.docs.push(t),d.size++,d.empty=!1,d.quantity=d.quantity+t.quantity,d.sales_btax=d.sales_btax+t.price*t.quantity,d.sales_atax=d.sales_atax+t.price*t.quantity*(1+Number(t.tax)/100)}))}console.log("json",d),a(d)}))}))},t.prototype.getReportSales_Customers_byCustomers=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Array;if("all"===n)r=i.getlocalCustomers();else{var l=i.getlocalCustomer(n);r.push(l)}var c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};if(r.length>0){var u=void 0;u="all"===n?"all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$gte:t,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0).then((function(t){if(t.length>0)for(var e=0;e<r.length;e++){for(var n=!1,o={id_customer:r[e]._id,name:r[e].name,sales_btax:0,sales_atax:0,quantity:0},i=0;i<t.length;i++)if(r[e]._id===t[i].id_customer)if(5===t[i].ptype){if(null!=t[i].combos)for(var s=0;s<t[i].combos.length;s++)o.quantity=o.quantity+t[i].combos[s].quantity*t[i].quantity,o.sales_btax=o.sales_btax+t[i].combos[s].price*t[i].combos[s].quantity*t[i].quantity,o.sales_atax=o.sales_atax+t[i].combos[s].price*t[i].combos[s].quantity*t[i].quantity*(1+t[i].tax/100)}else if(n=!0,o.quantity=o.quantity+t[i].quantity,o.sales_btax=o.sales_btax+t[i].price*t[i].quantity,o.sales_atax=o.sales_atax+t[i].price*t[i].quantity*(1+t[i].tax/100),null!=t[i].toppings)for(s=0;s<t[i].toppings.length;s++)o.quantity=o.quantity+t[i].toppings[s].quantity,o.sales_btax=o.sales_btax+t[i].toppings[s].price*t[i].toppings[s].quantity,o.sales_atax=o.sales_atax+t[i].toppings[s].price*t[i].toppings[s].quantity*(1+t[i].tax/100);n&&(c.quantity=c.quantity+o.quantity,c.sales_btax=c.sales_btax+o.sales_btax,c.sales_atax=c.sales_atax+o.sales_atax,o.index=c.size+1,c.docs.push(o),c.size++,c.empty=!1)}a(c)}))}else a(c)}))},t.prototype.getReportSales_Customers_byProducts=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l=i.getlocalProducts(1234);r=r="all"===o||void 0===o?{date:{$gte:t,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1]},id_branch:{$eq:o}};var c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};l.length>0?i.vhmongo_firebase.database().getDocsByFields("vhbill_details",r,{},{date:1},0).then((function(t){var e;if(t.length>0)for(var n=0;n<l.length;n++){var o=!1,i=Object.assign({},l[n]),s={id_product:i._id,name:i.name,unit:i.unit,barcode:i.barcode,img:i.img,sales_btax:0,sales_atax:0,quantity:0};if(null!=i.subs){s.subs=new Array;for(var r=0;r<i.subs.length;r++){var u={id_subproduct:i.subs[r]._id,name:null===(e=i.subs[r])||void 0===e?void 0:e.name,sales_btax:0,sales_atax:0,quantity:0};s.subs.push(u)}}for(var d=0;d<t.length;d++)if(1===t[d].ptype){if(1===l[n].type&&l[n]._id===t[d].id_product&&(o=!0,s.quantity=s.quantity+t[d].quantity,s.sales_btax=s.sales_btax+t[d].price*t[d].quantity,s.sales_atax=s.sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100),null!=s.subs))for(r=0;r<s.subs.length;r++)if(l[n].subs[r]._id===t[d].id_subproduct){s.subs[r].quantity=s.subs[r].quantity+t[d].quantity,s.subs[r].sales_btax=s.subs[r].sales_btax+t[d].price*t[d].quantity,s.subs[r].sales_atax=s.subs[r].sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100);break}if(4===l[n].type&&null!=t[d].toppings)for(var _=0;_<t[d].toppings.length;_++)l[n]._id===t[d].toppings[_].id_product&&(o=!0,s.quantity=s.quantity+t[d].toppings[_].quantity,s.sales_btax=s.sales_btax+t[d].toppings[_].price*t[d].toppings[_].quantity,s.sales_atax=s.sales_atax+t[d].toppings[_].price*t[d].toppings[_].quantity*(1+t[d].tax/100))}else if(2===t[d].ptype)l[n]._id===t[d].id_product&&(o=!0,s.quantity=s.quantity+t[d].quantity,s.sales_btax=s.sales_btax+t[d].price*t[d].quantity,s.sales_atax=s.sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100));else if(3===t[d].ptype)l[n]._id===t[d].id_product&&(o=!0,s.quantity=s.quantity+t[d].quantity,s.sales_btax=s.sales_btax+t[d].price*t[d].quantity,s.sales_atax=s.sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100));else if(4===t[d].ptype)l[n]._id===t[d].id_product&&(o=!0,s.quantity=s.quantity+t[d].quantity,s.sales_btax=s.sales_btax+t[d].price*t[d].quantity,s.sales_atax=s.sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100));else if(5===t[d].ptype)for(_=0;_<t[d].combos.length;_++)if(l[n]._id===t[d].combos[_].id_product&&(o=!0,s.quantity=s.quantity+t[d].combos[_].quantity*t[d].quantity,s.sales_btax=s.sales_btax+t[d].combos[_].price*t[d].combos[_].quantity*t[d].quantity,s.sales_atax=s.sales_atax+t[d].combos[_].price*t[d].combos[_].quantity*t[d].quantity*(1+t[d].tax/100),null!=s.subs))for(r=0;r<s.subs.length;r++)if(l[n].subs[r]._id===t[d].combos[_].id_subproduct){s.subs[r].quantity=s.subs[r].quantity+t[d].combos[_].quantity*t[d].quantity,s.subs[r].sales_btax=s.subs[r].sales_btax+t[d].combos[_].price*t[d].combos[_].quantity*t[d].quantity,s.subs[r].sales_atax=s.subs[r].sales_atax+t[d].combos[_].price*t[d].combos[_].quantity*t[d].quantity*(1+t[d].tax/100);break}o&&(s.sales_atax=Math.round(1e6*s.sales_atax)/1e6,null!=s.subs&&s.subs.forEach((function(t){t.sales_atax=Math.round(1e6*t.sales_atax)/1e6})),c.quantity=c.quantity+s.quantity,c.sales_btax=c.sales_btax+s.sales_btax,c.sales_atax=c.sales_atax+s.sales_atax,s.index=c.size+1,c.docs.push(s),c.size++,c.empty=!1)}console.log("getReportSales_Customers_byProducts"),a(c)})):a(c)}))},t.prototype.getReportSales_Customers_byProduct=function(t,e,n,o,i){var a=this;return new Promise((function(s,r){var l=a.getlocalProduct(o),c=new Array;a.getlocalProductAndCombosAndToppings(o).forEach((function(t){c.push(t._id)}));var u,d=l.type,_={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};u="all"===i||void 0===i?{date:{$gte:t,$lte:e},id_customer:{$eq:n},id_product:{$in:c},bill_type:{$eq:1}}:{date:{$gte:t,$lte:e},id_customer:{$eq:n},id_product:{$in:c},bill_type:{$eq:1},id_branch:{$eq:i}},a.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0).then((function(t){var e;if(t.length>0)for(var n=0;n<t.length;n++){var o=new Array;if(o[0]={id_product:l._id,name:l.name,unit:l.unit,barcode:l.barcode,img:l.img,bill_code:t[n].bill_code,bill_type:t[n].bill_type,id_bill:t[n].id_bill,date:t[n].date,tax:t[n].tax,salesman:null===(e=a.vhAuth.getlocalEmployee(t[n].id_employee))||void 0===e?void 0:e.name,customer:a.getlocalCustomer(t[n].id_customer).name},1===d){if(null!=t[n].combos){for(var i=0,r=Object.assign({},o[0]),c=0;c<t[n].combos.length;c++)if(t[n].combos[c].id_product===l._id)if(null!=l.subs)for(var u=0;u<l.subs.length;u++)t[n].combos[c].id_subproduct===l.subs[u]._id&&(0==i?(o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price,o[0].id_subproduct=l.subs[u]._id,o[0].name=o[0].name+"("+l.subs[u].name+")"):(o[i]=Object.assign({},r),o[i].quantity=t[n].combos[c].quantity*t[n].quantity,o[i].price=t[n].combos[c].price,o[i].id_subproduct=l.subs[u]._id,o[i].name=o[i].name+"("+l.subs[u].name+")"),i++);else o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price}else if(o[0].quantity=t[n].quantity,o[0].price=t[n].price,null!=l.subs)for(u=0;u<l.subs.length;u++)if(t[n].id_subproduct===l.subs[u]._id){o[0].id_subproduct=l.subs[u]._id,o[0].name=o[0].name+"("+l.subs[u].name+")";break}}else if(2===d||3===d)if(null!=t[n].combos){for(c=0;c<t[n].combos.length;c++)if(t[n].combos[c].id_product===l._id){o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price;break}}else o[0].quantity=t[n].quantity,o[0].price=t[n].price;else if(4===d)if(null!=t[n].toppings){for(c=0;c<t[n].toppings.length;c++)if(t[n].toppings[c].id_product===l._id){o[0].quantity=t[n].toppings[c].quantity,o[0].price=t[n].toppings[c].price;break}}else o[0].quantity=t[n].quantity,o[0].price=t[n].price;else 5===d&&(o[0].quantity=t[n].quantity,o[0].price=t[n].price);o.forEach((function(t){t.sales_btax=t.price*t.quantity,t.sales_atax=t.price*t.quantity*(1+t.tax/100),t.index=_.size+1,_.docs.push(t),_.size++,_.empty=!1,_.quantity=_.quantity+t.quantity,_.sales_btax=_.sales_btax+t.price*t.quantity,_.sales_atax=_.sales_atax+t.price*t.quantity*(1+Number(t.tax)/100)}))}console.log("getReportSales_Customers_byProduct"),s(_)}))}))},t.prototype.getReportSales_Employees_byEmployees=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Array;if("all"===n)r=i.vhAuth.getlocalEmployees();else{var l=i.vhAuth.getlocalEmployee(n);r.push(l)}var c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};if(r.length>0){var u=void 0;u="all"===n?"all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$gte:t,$lte:e},id_employee:{$eq:n},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},id_employee:{$eq:n},bill_type:{$in:[1]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0).then((function(t){if(t.length>0)for(var e=0;e<r.length;e++){for(var n=!1,o={id_employee:r[e]._id,name:r[e].name,sales_btax:0,sales_atax:0,quantity:0},i=0;i<t.length;i++)if(r[e]._id===t[i].id_employee)if(5===t[i].ptype){if(null!=t[i].combos)for(var s=0;s<t[i].combos.length;s++)o.quantity=o.quantity+t[i].combos[s].quantity*t[i].quantity,o.sales_btax=o.sales_btax+t[i].combos[s].price*t[i].combos[s].quantity*t[i].quantity,o.sales_atax=o.sales_atax+t[i].combos[s].price*t[i].combos[s].quantity*t[i].quantity*(1+t[i].tax/100)}else if(n=!0,o.quantity=o.quantity+t[i].quantity,o.sales_btax=o.sales_btax+t[i].price*t[i].quantity,o.sales_atax=o.sales_atax+t[i].price*t[i].quantity*(1+t[i].tax/100),null!=t[i].toppings)for(s=0;s<t[i].toppings.length;s++)o.quantity=o.quantity+t[i].toppings[s].quantity,o.sales_btax=o.sales_btax+t[i].toppings[s].price*t[i].toppings[s].quantity,o.sales_atax=o.sales_atax+t[i].toppings[s].price*t[i].toppings[s].quantity*(1+t[i].tax/100);n&&(c.quantity=c.quantity+o.quantity,c.sales_btax=c.sales_btax+o.sales_btax,c.sales_atax=c.sales_atax+o.sales_atax,o.index=c.size+1,c.docs.push(o),c.size++,c.empty=!1)}console.log("getReportSales_Employees_byEmployees"),a(c)}))}else a(c)}))},t.prototype.getReportSales_Employees_byProducts=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l=i.getlocalProducts(1234);r=r="all"===o||void 0===o?{date:{$gte:t,$lte:e},id_employee:{$eq:n},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},id_employee:{$eq:n},bill_type:{$in:[1]},id_branch:{$eq:o}};var c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};l.length>0?i.vhmongo_firebase.database().getDocsByFields("vhbill_details",r,{},{date:1},0).then((function(t){var e;if(t.length>0)for(var n=0;n<l.length;n++){var o=!1,i=Object.assign({},l[n]),s={id_product:i._id,name:i.name,unit:i.unit,barcode:i.barcode,img:i.img,sales_btax:0,sales_atax:0,quantity:0};if(null!=i.subs){s.subs=new Array;for(var r=0;r<i.subs.length;r++){var u={id_subproduct:i.subs[r]._id,name:null===(e=i.subs[r])||void 0===e?void 0:e.name,sales_btax:0,sales_atax:0,quantity:0};s.subs.push(u)}}for(var d=0;d<t.length;d++)if(1===t[d].ptype){if(1===l[n].type&&l[n]._id===t[d].id_product&&(o=!0,s.quantity=s.quantity+t[d].quantity,s.sales_btax=s.sales_btax+t[d].price*t[d].quantity,s.sales_atax=s.sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100),null!=s.subs))for(r=0;r<s.subs.length;r++)if(l[n].subs[r]._id===t[d].id_subproduct){s.subs[r].quantity=s.subs[r].quantity+t[d].quantity,s.subs[r].sales_btax=s.subs[r].sales_btax+t[d].price*t[d].quantity,s.subs[r].sales_atax=s.subs[r].sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100);break}if(4===l[n].type&&null!=t[d].toppings)for(var _=0;_<t[d].toppings.length;_++)l[n]._id===t[d].toppings[_].id_product&&(o=!0,s.quantity=s.quantity+t[d].toppings[_].quantity,s.sales_btax=s.sales_btax+t[d].toppings[_].price*t[d].toppings[_].quantity,s.sales_atax=s.sales_atax+t[d].toppings[_].price*t[d].toppings[_].quantity*(1+t[d].tax/100))}else if(2===t[d].ptype)l[n]._id===t[d].id_product&&(o=!0,s.quantity=s.quantity+t[d].quantity,s.sales_btax=s.sales_btax+t[d].price*t[d].quantity,s.sales_atax=s.sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100));else if(3===t[d].ptype)l[n]._id===t[d].id_product&&(o=!0,s.quantity=s.quantity+t[d].quantity,s.sales_btax=s.sales_btax+t[d].price*t[d].quantity,s.sales_atax=s.sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100));else if(4===t[d].ptype)l[n]._id===t[d].id_product&&(o=!0,s.quantity=s.quantity+t[d].quantity,s.sales_btax=s.sales_btax+t[d].price*t[d].quantity,s.sales_atax=s.sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100));else if(5===t[d].ptype)for(_=0;_<t[d].combos.length;_++)if(l[n]._id===t[d].combos[_].id_product&&(o=!0,s.quantity=s.quantity+t[d].combos[_].quantity*t[d].quantity,s.sales_btax=s.sales_btax+t[d].combos[_].price*t[d].combos[_].quantity*t[d].quantity,s.sales_atax=s.sales_atax+t[d].combos[_].price*t[d].combos[_].quantity*t[d].quantity*(1+t[d].tax/100),null!=s.subs))for(r=0;r<s.subs.length;r++)if(l[n].subs[r]._id===t[d].combos[_].id_subproduct){s.subs[r].quantity=s.subs[r].quantity+t[d].combos[_].quantity*t[d].quantity,s.subs[r].sales_btax=s.subs[r].sales_btax+t[d].combos[_].price*t[d].combos[_].quantity*t[d].quantity,s.subs[r].sales_atax=s.subs[r].sales_atax+t[d].combos[_].price*t[d].combos[_].quantity*t[d].quantity*(1+t[d].tax/100);break}o&&(s.sales_atax=Math.round(1e6*s.sales_atax)/1e6,null!=s.subs&&s.subs.forEach((function(t){t.sales_atax=Math.round(1e6*t.sales_atax)/1e6})),c.quantity=c.quantity+s.quantity,c.sales_btax=c.sales_btax+s.sales_btax,c.sales_atax=c.sales_atax+s.sales_atax,s.index=c.size+1,c.docs.push(s),c.size++,c.empty=!1)}console.log("getReportSales_Employees_byProduct"),a(c)})):a(c)}))},t.prototype.getReportSales_Employees_byProduct=function(t,e,n,o,i){var a=this;return new Promise((function(s,r){var l=a.getlocalProduct(o),c=new Array;a.getlocalProductAndCombosAndToppings(o).forEach((function(t){c.push(t._id)}));var u,d=l.type,_={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};u="all"===i||void 0===i?{date:{$gte:t,$lte:e},id_employee:{$eq:n},id_product:{$in:c},bill_type:{$eq:1}}:{date:{$gte:t,$lte:e},id_employee:{$eq:n},id_product:{$in:c},bill_type:{$eq:1},id_branch:{$eq:i}},a.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0).then((function(t){var e;if(t.length>0)for(var n=0;n<t.length;n++){var o=new Array;if(o[0]={id_product:l._id,name:l.name,unit:l.unit,barcode:l.barcode,img:l.img,bill_code:t[n].bill_code,bill_type:t[n].bill_type,id_bill:t[n].id_bill,date:t[n].date,tax:t[n].tax,salesman:null===(e=a.vhAuth.getlocalEmployee(t[n].id_employee))||void 0===e?void 0:e.name,customer:a.getlocalCustomer(t[n].id_customer).name},1===d){if(null!=t[n].combos){for(var i=0,r=Object.assign({},o[0]),c=0;c<t[n].combos.length;c++)if(t[n].combos[c].id_product===l._id)if(null!=l.subs)for(var u=0;u<l.subs.length;u++)t[n].combos[c].id_subproduct===l.subs[u]._id&&(0==i?(o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price,o[0].id_subproduct=l.subs[u]._id,o[0].name=o[0].name+"("+l.subs[u].name+")"):(o[i]=Object.assign({},r),o[i].quantity=t[n].combos[c].quantity*t[n].quantity,o[i].price=t[n].combos[c].price,o[i].id_subproduct=l.subs[u]._id,o[i].name=o[i].name+"("+l.subs[u].name+")"),i++);else o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price}else if(o[0].quantity=t[n].quantity,o[0].price=t[n].price,null!=l.subs)for(u=0;u<l.subs.length;u++)if(t[n].id_subproduct===l.subs[u]._id){o[0].id_subproduct=l.subs[u]._id,o[0].name=o[0].name+"("+l.subs[u].name+")";break}}else if(2===d||3===d)if(null!=t[n].combos){for(c=0;c<t[n].combos.length;c++)if(t[n].combos[c].id_product===l._id){o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price;break}}else o[0].quantity=t[n].quantity,o[0].price=t[n].price;else if(4===d)if(null!=t[n].toppings){for(c=0;c<t[n].toppings.length;c++)if(t[n].toppings[c].id_product===l._id){o[0].quantity=t[n].toppings[c].quantity,o[0].price=t[n].toppings[c].price;break}}else o[0].quantity=t[n].quantity,o[0].price=t[n].price;else 5===d&&(o[0].quantity=t[n].quantity,o[0].price=t[n].price);o.forEach((function(t){t.sales_btax=t.price*t.quantity,t.sales_atax=t.price*t.quantity*(1+t.tax/100),t.index=_.size+1,_.docs.push(t),_.size++,_.empty=!1,_.quantity=_.quantity+t.quantity,_.sales_btax=_.sales_btax+t.price*t.quantity,_.sales_atax=_.sales_atax+t.price*t.quantity*(1+Number(t.tax)/100)}))}console.log("getReportSales_Employees_byProduct"),s(_)}))}))},t.prototype.getReportSales_Tables_byTables=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Array;if("all"===n)r=i.getlocalTables();else{var l=i.getlocalTable(n);r.push(l)}var c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};if(r.length>0){var u=void 0;u="all"===n?"all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$gte:t,$lte:e},id_table:{$eq:n},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},id_table:{$eq:n},bill_type:{$in:[1]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0).then((function(t){if(t.length>0)for(var e=0;e<r.length;e++)if("go_home"!=r[e]._id){for(var n=!1,o={id_table:r[e]._id,name:r[e].name,sales_btax:0,sales_atax:0,quantity:0},i=0;i<t.length;i++)if(r[e]._id===t[i].id_table)if(5===t[i].ptype){if(null!=t[i].combos)for(var s=0;s<t[i].combos.length;s++)o.quantity=o.quantity+t[i].combos[s].quantity*t[i].quantity,o.sales_btax=o.sales_btax+t[i].combos[s].price*t[i].combos[s].quantity*t[i].quantity,o.sales_atax=o.sales_atax+t[i].combos[s].price*t[i].combos[s].quantity*t[i].quantity*(1+t[i].tax/100)}else if(n=!0,o.quantity=o.quantity+t[i].quantity,o.sales_btax=o.sales_btax+t[i].price*t[i].quantity,o.sales_atax=o.sales_atax+t[i].price*t[i].quantity*(1+t[i].tax/100),null!=t[i].toppings)for(s=0;s<t[i].toppings.length;s++)o.quantity=o.quantity+t[i].toppings[s].quantity,o.sales_btax=o.sales_btax+t[i].toppings[s].price*t[i].toppings[s].quantity,o.sales_atax=o.sales_atax+t[i].toppings[s].price*t[i].toppings[s].quantity*(1+t[i].tax/100);n&&(c.quantity=c.quantity+o.quantity,c.sales_btax=c.sales_btax+o.sales_btax,c.sales_atax=c.sales_atax+o.sales_atax,o.index=c.size+1,c.docs.push(o),c.size++,c.empty=!1)}console.log("getReportSales_Tables_byTables"),a(c)}))}else a(c)}))},t.prototype.getReportSales_Tables_byProducts=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l=i.getlocalProducts(1234);r=r="all"===o||void 0===o?{date:{$gte:t,$lte:e},id_table:{$eq:n},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},id_table:{$eq:n},bill_type:{$in:[1]},id_branch:{$eq:o}};var c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};l.length>0?i.vhmongo_firebase.database().getDocsByFields("vhbill_details",r,{},{date:1},0).then((function(t){var e;if(t.length>0)for(var n=0;n<l.length;n++){var o=!1,i=Object.assign({},l[n]),s={id_product:i._id,name:i.name,unit:i.unit,barcode:i.barcode,img:i.img,sales_btax:0,sales_atax:0,quantity:0};if(null!=i.subs){s.subs=new Array;for(var r=0;r<i.subs.length;r++){var u={id_subproduct:i.subs[r]._id,name:null===(e=i.subs[r])||void 0===e?void 0:e.name,sales_btax:0,sales_atax:0,quantity:0};s.subs.push(u)}}for(var d=0;d<t.length;d++)if(1===t[d].ptype){if(1===l[n].type&&l[n]._id===t[d].id_product&&(o=!0,s.quantity=s.quantity+t[d].quantity,s.sales_btax=s.sales_btax+t[d].price*t[d].quantity,s.sales_atax=s.sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100),null!=s.subs))for(r=0;r<s.subs.length;r++)if(l[n].subs[r]._id===t[d].id_subproduct){s.subs[r].quantity=s.subs[r].quantity+t[d].quantity,s.subs[r].sales_btax=s.subs[r].sales_btax+t[d].price*t[d].quantity,s.subs[r].sales_atax=s.subs[r].sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100);break}if(4===l[n].type&&null!=t[d].toppings)for(var _=0;_<t[d].toppings.length;_++)l[n]._id===t[d].toppings[_].id_product&&(o=!0,s.quantity=s.quantity+t[d].toppings[_].quantity,s.sales_btax=s.sales_btax+t[d].toppings[_].price*t[d].toppings[_].quantity,s.sales_atax=s.sales_atax+t[d].toppings[_].price*t[d].toppings[_].quantity*(1+t[d].tax/100))}else if(2===t[d].ptype)l[n]._id===t[d].id_product&&(o=!0,s.quantity=s.quantity+t[d].quantity,s.sales_btax=s.sales_btax+t[d].price*t[d].quantity,s.sales_atax=s.sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100));else if(3===t[d].ptype)l[n]._id===t[d].id_product&&(o=!0,s.quantity=s.quantity+t[d].quantity,s.sales_btax=s.sales_btax+t[d].price*t[d].quantity,s.sales_atax=s.sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100));else if(4===t[d].ptype)l[n]._id===t[d].id_product&&(o=!0,s.quantity=s.quantity+t[d].quantity,s.sales_btax=s.sales_btax+t[d].price*t[d].quantity,s.sales_atax=s.sales_atax+t[d].price*t[d].quantity*(1+t[d].tax/100));else if(5===t[d].ptype)for(_=0;_<t[d].combos.length;_++)if(l[n]._id===t[d].combos[_].id_product&&(o=!0,s.quantity=s.quantity+t[d].combos[_].quantity*t[d].quantity,s.sales_btax=s.sales_btax+t[d].combos[_].price*t[d].combos[_].quantity*t[d].quantity,s.sales_atax=s.sales_atax+t[d].combos[_].price*t[d].combos[_].quantity*t[d].quantity*(1+t[d].tax/100),null!=s.subs))for(r=0;r<s.subs.length;r++)if(l[n].subs[r]._id===t[d].combos[_].id_subproduct){s.subs[r].quantity=s.subs[r].quantity+t[d].combos[_].quantity*t[d].quantity,s.subs[r].sales_btax=s.subs[r].sales_btax+t[d].combos[_].price*t[d].combos[_].quantity*t[d].quantity,s.subs[r].sales_atax=s.subs[r].sales_atax+t[d].combos[_].price*t[d].combos[_].quantity*t[d].quantity*(1+t[d].tax/100);break}o&&(s.sales_atax=Math.round(1e6*s.sales_atax)/1e6,null!=s.subs&&s.subs.forEach((function(t){t.sales_atax=Math.round(1e6*t.sales_atax)/1e6})),c.quantity=c.quantity+s.quantity,c.sales_btax=c.sales_btax+s.sales_btax,c.sales_atax=c.sales_atax+s.sales_atax,s.index=c.size+1,c.docs.push(s),c.size++,c.empty=!1)}console.log("getReportSales_Tables_byProducts"),a(c)})):a(c)}))},t.prototype.getReportSales_Tables_byProduct=function(t,e,n,o,i){var a=this;return new Promise((function(s,r){var l=a.getlocalProduct(o),c=new Array;a.getlocalProductAndCombosAndToppings(o).forEach((function(t){c.push(t._id)}));var u,d=l.type,_={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};u="all"===i||void 0===i?{date:{$gte:t,$lte:e},id_table:{$eq:n},id_product:{$in:c},bill_type:{$eq:1}}:{date:{$gte:t,$lte:e},id_table:{$eq:n},id_product:{$in:c},bill_type:{$eq:1},id_branch:{$eq:i}},a.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0).then((function(t){var e;if(t.length>0)for(var n=0;n<t.length;n++){var o=new Array;if(o[0]={id_product:l._id,name:l.name,unit:l.unit,barcode:l.barcode,img:l.img,bill_code:t[n].bill_code,bill_type:t[n].bill_type,id_bill:t[n].id_bill,date:t[n].date,tax:t[n].tax,salesman:null===(e=a.vhAuth.getlocalEmployee(t[n].id_employee))||void 0===e?void 0:e.name,customer:a.getlocalCustomer(t[n].id_customer).name},1===d){if(null!=t[n].combos){for(var i=0,r=Object.assign({},o[0]),c=0;c<t[n].combos.length;c++)if(t[n].combos[c].id_product===l._id)if(null!=l.subs)for(var u=0;u<l.subs.length;u++)t[n].combos[c].id_subproduct===l.subs[u]._id&&(0==i?(o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price,o[0].id_subproduct=l.subs[u]._id,o[0].name=o[0].name+"("+l.subs[u].name+")"):(o[i]=Object.assign({},r),o[i].quantity=t[n].combos[c].quantity*t[n].quantity,o[i].price=t[n].combos[c].price,o[i].id_subproduct=l.subs[u]._id,o[i].name=o[i].name+"("+l.subs[u].name+")"),i++);else o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price}else if(o[0].quantity=t[n].quantity,o[0].price=t[n].price,null!=l.subs)for(u=0;u<l.subs.length;u++)if(t[n].id_subproduct===l.subs[u]._id){o[0].id_subproduct=l.subs[u]._id,o[0].name=o[0].name+"("+l.subs[u].name+")";break}}else if(2===d||3===d)if(null!=t[n].combos){for(c=0;c<t[n].combos.length;c++)if(t[n].combos[c].id_product===l._id){o[0].quantity=t[n].combos[c].quantity*t[n].quantity,o[0].price=t[n].combos[c].price;break}}else o[0].quantity=t[n].quantity,o[0].price=t[n].price;else if(4===d)if(null!=t[n].toppings){for(c=0;c<t[n].toppings.length;c++)if(t[n].toppings[c].id_product===l._id){o[0].quantity=t[n].toppings[c].quantity,o[0].price=t[n].toppings[c].price;break}}else o[0].quantity=t[n].quantity,o[0].price=t[n].price;else 5===d&&(o[0].quantity=t[n].quantity,o[0].price=t[n].price);o.forEach((function(t){t.sales_btax=t.price*t.quantity,t.sales_atax=t.price*t.quantity*(1+t.tax/100),t.index=_.size+1,_.docs.push(t),_.size++,_.empty=!1,_.quantity=_.quantity+t.quantity,_.sales_btax=_.sales_btax+t.price*t.quantity,_.sales_atax=_.sales_atax+t.price*t.quantity*(1+Number(t.tax)/100)}))}console.log("getReportSales_Tables_byProduct"),s(_)}))}))},t.prototype.getReportInputOutputReturns_byTime_byIDMaterial_byBillTypeArray=function(t,e,n,o,i){var a=this;return new Promise((function(s,r){var l=new Array;if("all"===n)l=a.vhAlgorithm.sortVietnamesebyASC(a.getlocalProducts(3),"name");else{var c=a.getlocalProduct(n);l.push(c)}var u={docs:new Array,empty:!0,size:0,quantity:0,pay_btax:0,pay_atax:0};if(l.length>0){var d=void 0;d="all"===n?"all"===i||void 0===i?{date:{$gte:t,$lte:e},ptype:{$eq:3},bill_type:{$in:o}}:{date:{$gte:t,$lte:e},ptype:{$eq:3},bill_type:{$in:o},id_branch:{$eq:i}}:"all"===i||void 0===i?{date:{$gte:t,$lte:e},id_product:{$eq:n},bill_type:{$in:o}}:{date:{$gte:t,$lte:e},id_product:{$eq:n},bill_type:{$in:o},id_branch:{$eq:i}},a.vhmongo_firebase.database().getDocsByFields("vhbill_details",d,{},{date:1},0).then((function(t){for(var e=0;e<l.length;e++){for(var n=!1,o={_id:l[e]._id,name:l[e].name,type:l[e].type,unit:l[e].unit,quantity:0,pay_btax:0,pay_atax:0},i=0;i<t.length;i++)t[i].id_product===l[e]._id&&(n=!0,3===t[i].bill_type||16===t[i].bill_type||(o.pay_btax=o.pay_btax+t[i].price*t[i].quantity,o.pay_atax=o.pay_atax+t[i].price*t[i].quantity*(1+t[i].tax/100)),o.quantity=o.quantity+t[i].quantity);n&&(u.pay_btax=u.pay_btax+o.price*o.quantity,u.pay_atax=u.pay_atax+o.price*o.quantity*(1+o.tax/100),u.quantity=u.quantity+o.quantity,u.docs.push(o),u.size++,u.empty=!1)}console.log("json",u),s(u)}))}else console.log("server -> products khong ton tai trong CSDL: "),s(u)}))},t.prototype.getReportInputOutputReturns_Detail_byTime_byIDMaterial_byBillTypeArray=function(t,e,n,o,i){var a=this;return new Promise((function(s,r){var l,c=a.getlocalProduct(n),u={docs:new Array,empty:!0,size:0,quantity:0,pay_btax:0,pay_atax:0};l="all"===i||void 0===i?{date:{$gte:t,$lte:e},id_product:{$eq:n},bill_type:{$in:o}}:{date:{$gte:t,$lte:e},id_product:{$eq:n},bill_type:{$in:o},id_branch:{$eq:i}},a.vhmongo_firebase.database().getDocsByFields("vhbill_details",l,{},{date:1},0).then((function(t){for(var e,n,o,i,a,r,l,d,_,p,b,f,h,y,m,v,g,x,q,w=0;w<t.length;w++){var P={id_bill:null===(e=t[w])||void 0===e?void 0:e.id_bill,bill_code:null===(n=t[w])||void 0===n?void 0:n.bill_code,bill_type:null===(o=t[w])||void 0===o?void 0:o.bill_type,date:null===(i=t[w])||void 0===i?void 0:i.date,price_btax:null===(a=t[w])||void 0===a?void 0:a.price,price_atax:(null===(r=t[w])||void 0===r?void 0:r.price)*(1+t[w].tax/100),pay_btax:(null===(l=t[w])||void 0===l?void 0:l.price)*(null===(d=t[w])||void 0===d?void 0:d.quantity),pay_atax:(null===(_=t[w])||void 0===_?void 0:_.price)*(null===(p=t[w])||void 0===p?void 0:p.quantity)*(1+t[w].tax/100),quantity:null===(b=t[w])||void 0===b?void 0:b.quantity,name:c.name,unit:c.unit};(null===(f=t[w])||void 0===f?void 0:f.id_cashier)&&(P.id_cashier=null===(h=t[w])||void 0===h?void 0:h.id_cashier),(null===(y=t[w])||void 0===y?void 0:y.id_employee)&&(P.id_employee=null===(m=t[w])||void 0===m?void 0:m.id_employee),(null===(v=t[w])||void 0===v?void 0:v.id_customer)&&(P.id_customer=null===(g=t[w])||void 0===g?void 0:g.id_customer),(null===(x=t[w])||void 0===x?void 0:x.id_supplier)&&(P.id_supplier=null===(q=t[w])||void 0===q?void 0:q.id_supplier),u.quantity=u.quantity+t[w].quantity,u.pay_btax=u.pay_btax+t[w].price*t[w].quantity,u.pay_atax=u.pay_atax+t[w].price*t[w].quantity*(1+t[w].tax/100),u.docs.push(P),u.size++,u.empty=!1}s(u)}))}))},t.prototype.getReportInputOutputInventory_byTime_byIDMaterial=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r={docs:new Array,empty:!0,size:0,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0,stock_first:0,stock_last:0,cost_stock_first_btax:0,cost_stock_first_atax:0,cost_stock_last_btax:0,cost_stock_last_atax:0},l=i.vhAuth.getStore(),c=new Array;if("all"===n)c=i.vhAlgorithm.sortVietnamesebyASC(i.getlocalProducts(3),"name");else{var u=i.getlocalProduct(n);c.push(u)}var d=null,_=null;if("all"===n)if("all"===o||void 0===o)console.log("trường hợp này chưa có hàm, liên hệ anh Huy viết");else{if(null!=c[0][o]&&null!=c[0][o].inventory)for(var p=0;p<c[0][o].inventory.length&&!(new Date(c[0][o].inventory[p].date).getTime()>t.getTime());p++)_=new Date(c[0][o].inventory[p].date),d=p;if(_){for(var b=!1,f=0;f<c.length;f++)null!=c[f][o]&&null!=c[f][o].inventory||(b=!0);if(b)return console.log("Vui lòng đồng bộ kho để lấy về dữ liệu mới nhất"),a(r)}}else if("all"===o||void 0===o)console.log("trường hợp này chưa có hàm, liên hệ anh Huy viết");else if(null!=c[0][o]&&null!=c[0][o].inventory)for(p=0;p<c[0][o].inventory.length&&!(new Date(c[0][o].inventory[p].date).getTime()>t.getTime());p++)_=new Date(c[0][o].inventory[p].date),d=p;if(_||(_=new Date(l.registrationdate)),c.length>0){var h,y=new Array;"all"===n?(h="all"===o||void 0===o?{date:{$gte:_,$lte:e},ptype:{$eq:3},bill_type:{$in:[1,3,10,30,2,9,16,31]}}:{date:{$gte:_,$lte:e},ptype:{$eq:3},bill_type:{$in:[1,3,10,30,2,9,16,31]},id_branch:{$eq:o}},y[0]=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",h,{},{date:1},0)):(h="all"===o||void 0===o?{date:{$gte:_,$lte:e},id_product:{$eq:c[0]._id},bill_type:{$in:[1,3,10,30,2,9,16,31]}}:{date:{$gte:_,$lte:e},id_product:{$eq:c[0]._id},bill_type:{$in:[1,3,10,30,2,9,16,31]},id_branch:{$eq:o}},y[0]=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",h,{},{date:1},0)),Promise.all(y).then((function(e){for(var n=e.flat(),i=0;i<c.length;i++){for(var s={stock_first:0,cost_stock_first_btax:0,cost_stock_first_atax:0,unit_cost_stock_first_btax:0,unit_cost_stock_first_atax:0,inquantity_tofirst:0,outquantity_tofirst:0,pay_tofirst_btax:0,pay_tofirst_atax:0,profit_first_btax:0,profit_first_atax:0,sales_tofirst_btax:0,sales_tofirst_atax:0},l={_id:c[i]._id,name:c[i].name,type:c[i].type,unit:c[i].unit,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0,stock_first:0,stock_last:0,cost_stock_first_btax:0,cost_stock_first_atax:0,cost_stock_last_btax:0,cost_stock_last_atax:0},u=0,_=0,p=0,b=0,f=0,h=0,y=0,m=0;m<n.length;m++)if(3===n[m].ptype&&n[m].id_product===c[i]._id){var v=new Date(n[m].date);1===n[m].bill_type||3===n[m].bill_type||10===n[m].bill_type||30===n[m].bill_type?v>=new Date(t)?(l.revenue_btax=l.revenue_btax+n[m].price*n[m].quantity,l.revenue_atax=l.revenue_atax+n[m].price*n[m].quantity*(1+n[m].tax/100),l.outquantity=l.outquantity+n[m].quantity,r.revenue_btax=r.revenue_btax+n[m].price*n[m].quantity,r.revenue_atax=r.revenue_atax+n[m].price*n[m].quantity*(1+n[m].tax/100),r.outquantity=r.outquantity+n[m].quantity):u+=n[m].quantity:2===n[m].bill_type||16===n[m].bill_type||31===n[m].bill_type?(v>=new Date(t)?(l.cost_btax=l.cost_btax+n[m].price*n[m].quantity,l.cost_atax=l.cost_atax+n[m].price*n[m].quantity*(1+n[m].tax/100),l.inquantity=l.inquantity+n[m].quantity,r.cost_btax=r.cost_btax+n[m].price*n[m].quantity,r.cost_atax=r.cost_atax+n[m].price*n[m].quantity*(1+n[m].tax/100),r.inquantity=r.inquantity+n[m].quantity):(_+=n[m].quantity,p+=n[m].price*n[m].quantity,b+=n[m].price*n[m].quantity*(1+n[m].tax/100)),f+=n[m].quantity,h+=n[m].price*n[m].quantity,y+=n[m].price*n[m].quantity*(1+n[m].tax/100)):9===n[m].bill_type&&(s.stock_first=s.stock_first+n[m].quantity,s.cost_stock_first_btax=s.cost_stock_first_btax+n[m].price*n[m].quantity,s.cost_stock_first_atax=s.cost_stock_first_btax+n[m].price*n[m].quantity*(1+n[m].tax/100))}null!=d&&(s=Object.assign({},c[i][o].inventory[d])),l.stock_first=s.stock_first+_-u,l.stock_last=l.stock_first+l.inquantity-l.outquantity,s.stock_first+_!=0&&(l.cost_stock_first_btax=(s.cost_stock_first_btax+p)/(s.stock_first+_)*l.stock_first,l.cost_stock_first_atax=(s.cost_stock_first_atax+b)/(s.stock_first+_)*l.stock_first),s.stock_first+f!=0&&(l.cost_stock_last_btax=(s.cost_stock_first_btax+h)/(s.stock_first+f)*l.stock_last,l.cost_stock_last_atax=(s.cost_stock_first_atax+y)/(s.stock_first+f)*l.stock_last),r.stock_first=r.stock_first+l.stock_first,r.stock_last=r.stock_last+l.stock_last,r.cost_stock_first_btax=r.cost_stock_first_btax+l.cost_stock_first_btax,r.cost_stock_first_atax=r.cost_stock_first_atax+l.cost_stock_first_atax,r.cost_stock_last_btax=r.cost_stock_last_btax+l.cost_stock_last_btax,r.cost_stock_last_atax=r.cost_stock_last_atax+l.cost_stock_last_atax,l.revenue_atax=Math.round(1e6*l.revenue_atax)/1e6,l.cost_atax=Math.round(1e6*l.cost_atax)/1e6,l.cost_stock_first_atax=Math.round(1e6*l.cost_stock_first_atax)/1e6,l.cost_stock_last_atax=Math.round(1e6*l.cost_stock_last_atax)/1e6,l.index=r.size+1,r.docs.push(l),r.size++,r.empty=!1}a(r),console.log("getReportInputOutputInventory_byTime_byIDMaterial",r)}))}else console.log("server -> products khong ton tai trong CSDL: "),a(r)}))},t.prototype.getReportInputOutputInventory_byTime_byIDMaterial1=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Array;if("all"===n)r=i.vhAlgorithm.sortVietnamesebyASC(i.getlocalProducts(3),"name");else{var l=i.getlocalProduct(n);r.push(l)}var c={docs:new Array,empty:!0,size:0,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0,stock_first:0,stock_last:0,cost_stock_first_btax:0,cost_stock_first_atax:0,cost_stock_last_btax:0,cost_stock_last_atax:0};if(r.length>0){var u=void 0;u="all"===n?"all"===o||void 0===o?{date:{$lte:e},ptype:{$eq:3},bill_type:{$in:[1,3,10,30,2,9,16,31]}}:{date:{$lte:e},ptype:{$eq:3},bill_type:{$in:[1,3,10,30,2,9,16,31]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$lte:e},ptype:{$eq:3},id_product:{$eq:n},bill_type:{$in:[1,3,10,30,2,9,16,31]}}:{date:{$lte:e},ptype:{$eq:3},id_product:{$eq:n},bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0).then((function(e){for(var n=0;n<r.length;n++){for(var o={_id:r[n]._id,name:r[n].name,type:r[n].type,unit:r[n].unit,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0,stock_first:0,stock_last:0,cost_stock_first_btax:0,cost_stock_first_atax:0,cost_stock_last_btax:0,cost_stock_last_atax:0},i=0,s=0,l=0,u=0,d=0,_=0,p=0,b=0;b<e.length;b++)if(e[b].id_product===r[n]._id){var f=new Date(e[b].date);1===e[b].bill_type||3===e[b].bill_type||10===e[b].bill_type||30===e[b].bill_type?f>=new Date(t)?(o.revenue_btax=o.revenue_btax+e[b].price*e[b].quantity,o.revenue_atax=o.revenue_atax+e[b].price*e[b].quantity*(1+e[b].tax/100),o.outquantity=o.outquantity+e[b].quantity,c.revenue_btax=c.revenue_btax+e[b].price*e[b].quantity,c.revenue_atax=c.revenue_atax+e[b].price*e[b].quantity*(1+e[b].tax/100),c.outquantity=c.outquantity+e[b].quantity):i+=e[b].quantity:3===e[b].bill_type?f>=new Date(t)?(o.outquantity=o.outquantity+e[b].quantity,c.outquantity=c.outquantity+e[b].quantity):i+=e[b].quantity:2===e[b].bill_type||9===e[b].bill_type||31===e[b].bill_type?(f>=new Date(t)?(o.cost_btax=o.cost_btax+e[b].price*e[b].quantity,o.cost_atax=o.cost_atax+e[b].price*e[b].quantity*(1+e[b].tax/100),o.inquantity=o.inquantity+e[b].quantity,c.cost_btax=c.cost_btax+e[b].price*e[b].quantity,c.cost_atax=c.cost_atax+e[b].price*e[b].quantity*(1+e[b].tax/100),c.inquantity=c.inquantity+e[b].quantity):(s+=e[b].quantity,l+=e[b].price*e[b].quantity,u+=e[b].price*e[b].quantity*(1+e[b].tax/100)),d+=e[b].quantity,_+=e[b].price*e[b].quantity,p+=e[b].price*e[b].quantity*(1+e[b].tax/100)):16===e[b].bill_type&&(f>=new Date(t)?(o.inquantity=o.inquantity+e[b].quantity,c.inquantity=c.inquantity+e[b].quantity):s+=e[b].quantity,d+=e[b].quantity)}o.stock_first=s-i,o.stock_last=o.stock_first+o.inquantity-o.outquantity,0!=s&&(o.cost_stock_first_btax=l/s*o.stock_first),0!=s&&(o.cost_stock_first_atax=u/s*o.stock_first),0!=d&&(o.cost_stock_last_btax=_/d*o.stock_last),0!=d&&(o.cost_stock_last_atax=p/d*o.stock_last),c.stock_first=c.stock_first+o.stock_first,c.stock_last=c.stock_last+o.stock_last,c.cost_stock_first_btax=c.cost_stock_first_btax+o.cost_stock_first_btax,c.cost_stock_first_atax=c.cost_stock_first_atax+o.cost_stock_first_atax,c.cost_stock_last_btax=c.cost_stock_last_btax+o.cost_stock_last_btax,c.cost_stock_last_atax=c.cost_stock_last_atax+o.cost_stock_last_atax,0==o.stock_first&&0==o.inquantity&&0==o.outquantity||(o.index=c.size+1,c.docs.push(o),c.size++,c.empty=!1)}a(c)}))}else console.log("server -> products khong ton tai trong CSDL: "),a(c)}))},t.prototype.syncInventoryEveryDay_Stock1stDayOfMonth=function(){var t=this;return new Promise((function(e,n){var o=t.vhAuth.getStore(),i=100,a=[Object.assign({},t.getDefaultBranch())];t.vhmongo_firebase.auth().getServerDate().then((function(n){var s=t.get1stDayOfMonthArray(o.registrationdate,n);if(s.length>0){for(var r=new Array,l=function(e){r[e]=new Promise((function(n){for(var o=a[e]._id,r=t.getlocalProducts(3),l=new Array,c=0;c<r.length;c++)l.push(c);var u=!0,d=l.splice(0,10),_=setInterval((function(){if(u){u=!1;for(var a=new Array,c=function(e){a[a.length]=new Promise((function(n){if(null!=r[e][o]&&null!=r[e][o].inventory){var a=r[e][o].inventory[r[e][o].inventory.length-1],l=r[e][o].inventory.length;if(new Date(a.date).getTime()<new Date(s[s.length-1]).getTime()){for(var c=l;c<s.length;c++)r[e][o].inventory[c]={},r[e][o].inventory[c].date=s[c],r[e][o].inventory[c].inquantity_tofirst=a.inquantity_tofirst,r[e][o].inventory[c].pay_tofirst_btax=a.pay_tofirst_btax,r[e][o].inventory[c].pay_tofirst_atax=a.pay_tofirst_atax,r[e][o].inventory[c].outquantity_tofirst=a.outquantity_tofirst,r[e][o].inventory[c].sales_tofirst_btax=a.sales_tofirst_btax,r[e][o].inventory[c].sales_tofirst_atax=a.sales_tofirst_atax,r[e][o].inventory[c].stock_first=0,r[e][o].inventory[c].unit_cost_stock_first_btax=0,r[e][o].inventory[c].unit_cost_stock_first_atax=0,r[e][o].inventory[c].cost_stock_first_btax=0,r[e][o].inventory[c].cost_stock_first_atax=0,r[e][o].inventory[c].profit_first_btax=0,r[e][o].inventory[c].profit_first_atax=0;var u={date:{$gte:new Date(a.date),$lte:new Date(s[s.length-1])},bill_type:{$in:[1,3,10,30,2,9,16,31]},id_branch:{$eq:o},id_product:{$eq:r[e]._id}};t.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0).then((function(a){if(a.length>0)for(var c=0;c<a.length;c++)if(3===a[c].ptype&&a[c].id_product===r[e]._id)for(var u=l;u<s.length;u++)new Date(a[c].date).getTime()<new Date(r[e][o].inventory[u].date).getTime()&&(1===a[c].bill_type||3===a[c].bill_type||10===a[c].bill_type||30===a[c].bill_type?(r[e][o].inventory[u].outquantity_tofirst=r[e][o].inventory[u].outquantity_tofirst+a[c].quantity,r[e][o].inventory[u].sales_tofirst_btax=r[e][o].inventory[u].sales_tofirst_btax+a[c].price*a[c].quantity,r[e][o].inventory[u].sales_tofirst_atax=r[e][o].inventory[u].sales_tofirst_atax+a[c].price*a[c].quantity*(1+a[c].tax/100)):2!==a[c].bill_type&&9!==a[c].bill_type&&16!==a[c].bill_type&&31!==a[c].bill_type||(r[e][o].inventory[u].inquantity_tofirst=r[e][o].inventory[u].inquantity_tofirst+a[c].quantity,r[e][o].inventory[u].pay_tofirst_btax=r[e][o].inventory[u].pay_tofirst_btax+a[c].price*a[c].quantity,r[e][o].inventory[u].pay_tofirst_atax=r[e][o].inventory[u].pay_tofirst_atax+a[c].price*a[c].quantity*(1+a[c].tax/100)));for(u=l;u<s.length;u++){var d=r[e][o].inventory[u].inquantity_tofirst-r[e][o].inventory[u-1].inquantity_tofirst,_=r[e][o].inventory[u].pay_tofirst_btax-r[e][o].inventory[u-1].pay_tofirst_btax,p=r[e][o].inventory[u].pay_tofirst_atax-r[e][o].inventory[u-1].pay_tofirst_atax;r[e][o].inventory[u].stock_first=r[e][o].inventory[u].inquantity_tofirst-r[e][o].inventory[u].outquantity_tofirst,r[e][o].inventory[u-1].stock_first+d!=0&&(r[e][o].inventory[u].unit_cost_stock_first_btax=(r[e][o].inventory[u-1].cost_stock_first_btax+_)/(r[e][o].inventory[u-1].stock_first+d),r[e][o].inventory[u].unit_cost_stock_first_atax=(r[e][o].inventory[u-1].cost_stock_first_atax+p)/(r[e][o].inventory[u-1].stock_first+d),r[e][o].inventory[u].cost_stock_first_btax=r[e][o].inventory[u].unit_cost_stock_first_btax*r[e][o].inventory[u].stock_first,r[e][o].inventory[u].cost_stock_first_atax=r[e][o].inventory[u].unit_cost_stock_first_atax*r[e][o].inventory[u].stock_first);var b=r[e][o].inventory[u].outquantity_tofirst-r[e][o].inventory[u-1].outquantity_tofirst,f=r[e][o].inventory[u].unit_cost_stock_first_btax*b,h=r[e][o].inventory[u].unit_cost_stock_first_atax*b,y=r[e][o].inventory[u].sales_tofirst_btax-r[e][o].inventory[u-1].sales_tofirst_btax,m=r[e][o].inventory[u].sales_tofirst_atax-r[e][o].inventory[u-1].sales_tofirst_atax;r[e][o].inventory[u].profit_first_btax=y-f,r[e][o].inventory[u].profit_first_atax=m-h}i--;var v=t.getlocalProduct(r[e]._id),g={};null!=v[o]?(g[o]=v[o],g[o].inventory=r[e][o].inventory):g[o]=r[e][o],t.vhmongo_firebase.database().updateDoc("products",r[e]._id,Object.assign({},g)).then((function(){console.log(e,r[e]),n(!0)}))}))}else n(null)}else{u={bill_type:{$in:[1,3,10,30,2,9,16,31]},id_branch:{$eq:o},id_product:{$eq:r[e]._id}};t.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0).then((function(a){r[e][o]={},r[e][o].inventory=new Array;for(var l=0;l<s.length;l++)r[e][o].inventory[l]={},r[e][o].inventory[l].date=s[l],r[e][o].inventory[l].inquantity_tofirst=0,r[e][o].inventory[l].pay_tofirst_btax=0,r[e][o].inventory[l].pay_tofirst_atax=0,r[e][o].inventory[l].outquantity_tofirst=0,r[e][o].inventory[l].sales_tofirst_btax=0,r[e][o].inventory[l].sales_tofirst_atax=0,r[e][o].inventory[l].stock_first=0,r[e][o].inventory[l].unit_cost_stock_first_btax=0,r[e][o].inventory[l].unit_cost_stock_first_atax=0,r[e][o].inventory[l].cost_stock_first_btax=0,r[e][o].inventory[l].cost_stock_first_atax=0,r[e][o].inventory[l].profit_first_btax=0,r[e][o].inventory[l].profit_first_atax=0;if(a.length>0){for(var c=0;c<a.length;c++)if(3===a[c].ptype&&a[c].id_product===r[e]._id)for(l=0;l<r[e][o].inventory.length;l++)new Date(a[c].date).getTime()<new Date(r[e][o].inventory[l].date).getTime()&&(1===a[c].bill_type||3===a[c].bill_type||10===a[c].bill_type||30===a[c].bill_type?(r[e][o].inventory[l].outquantity_tofirst=r[e][o].inventory[l].outquantity_tofirst+a[c].quantity,r[e][o].inventory[l].sales_tofirst_btax=r[e][o].inventory[l].sales_tofirst_btax+a[c].price*a[c].quantity,r[e][o].inventory[l].sales_tofirst_atax=r[e][o].inventory[l].sales_tofirst_atax+a[c].price*a[c].quantity*(1+a[c].tax/100)):2!==a[c].bill_type&&9!==a[c].bill_type&&16!==a[c].bill_type&&31!==a[c].bill_type||(r[e][o].inventory[l].inquantity_tofirst=r[e][o].inventory[l].inquantity_tofirst+a[c].quantity,r[e][o].inventory[l].pay_tofirst_btax=r[e][o].inventory[l].pay_tofirst_btax+a[c].price*a[c].quantity,r[e][o].inventory[l].pay_tofirst_atax=r[e][o].inventory[l].pay_tofirst_atax+a[c].price*a[c].quantity*(1+a[c].tax/100)));for(l=0;l<r[e][o].inventory.length;l++)if(0===l){var u=r[e][o].inventory[0].inquantity_tofirst,d=r[e][o].inventory[0].pay_tofirst_btax,_=r[e][o].inventory[0].pay_tofirst_atax;r[e][o].inventory[0].stock_first=r[e][o].inventory[0].inquantity_tofirst-r[e][o].inventory[0].outquantity_tofirst,0!=u&&(r[e][o].inventory[0].unit_cost_stock_first_btax=d/u,r[e][o].inventory[0].unit_cost_stock_first_atax=_/u,r[e][o].inventory[0].cost_stock_first_btax=r[e][o].inventory[0].unit_cost_stock_first_btax*r[e][o].inventory[0].stock_first,r[e][o].inventory[0].cost_stock_first_atax=r[e][o].inventory[0].unit_cost_stock_first_atax*r[e][o].inventory[0].stock_first);var p=r[e][o].inventory[0].outquantity_tofirst,b=r[e][o].inventory[0].unit_cost_stock_first_btax*p,f=r[e][o].inventory[0].unit_cost_stock_first_atax*p,h=r[e][o].inventory[0].sales_tofirst_btax,y=r[e][o].inventory[0].sales_tofirst_atax;r[e][o].inventory[0].profit_first_btax=h-b,r[e][o].inventory[0].profit_first_atax=y-f}else{u=r[e][o].inventory[l].inquantity_tofirst-r[e][o].inventory[l-1].inquantity_tofirst,d=r[e][o].inventory[l].pay_tofirst_btax-r[e][o].inventory[l-1].pay_tofirst_btax,_=r[e][o].inventory[l].pay_tofirst_atax-r[e][o].inventory[l-1].pay_tofirst_atax;r[e][o].inventory[l].stock_first=r[e][o].inventory[l].inquantity_tofirst-r[e][o].inventory[l].outquantity_tofirst,r[e][o].inventory[l-1].stock_first+u!=0&&(r[e][o].inventory[l].unit_cost_stock_first_btax=(r[e][o].inventory[l-1].cost_stock_first_btax+d)/(r[e][o].inventory[l-1].stock_first+u),r[e][o].inventory[l].unit_cost_stock_first_atax=(r[e][o].inventory[l-1].cost_stock_first_atax+_)/(r[e][o].inventory[l-1].stock_first+u),r[e][o].inventory[l].cost_stock_first_btax=r[e][o].inventory[l].unit_cost_stock_first_btax*r[e][o].inventory[l].stock_first,r[e][o].inventory[l].cost_stock_first_atax=r[e][o].inventory[l].unit_cost_stock_first_atax*r[e][o].inventory[l].stock_first);p=r[e][o].inventory[l].outquantity_tofirst-r[e][o].inventory[l-1].outquantity_tofirst,b=r[e][o].inventory[l].unit_cost_stock_first_btax*p,f=r[e][o].inventory[l].unit_cost_stock_first_atax*p,h=r[e][o].inventory[l].sales_tofirst_btax-r[e][o].inventory[l-1].sales_tofirst_btax,y=r[e][o].inventory[l].sales_tofirst_atax-r[e][o].inventory[l-1].sales_tofirst_atax;r[e][o].inventory[l].profit_first_btax=h-b,r[e][o].inventory[l].profit_first_atax=y-f}}i--;var m=t.getlocalProduct(r[e]._id),v={};null!=m[o]?(v[o]=m[o],v[o].inventory=r[e][o].inventory):v[o]=r[e][o],t.vhmongo_firebase.database().updateDoc("products",r[e]._id,Object.assign({},v)).then((function(){console.log(e,r[e]),n(!0)}))}))}}))},p=d[0];p<=d[d.length-1];p++)c(p);Promise.all(a).then((function(){i<=0&&(n(e),clearInterval(_)),l.length>0?(u=!0,d=l.splice(0,10)):(n(e),clearInterval(_))}))}}),10)}))},c=0;c<a.length;c++)l(c);Promise.all(r).then((function(t){console.log("syncInventoryEveryDay_Stock1stDayOfMonth",t),e(null)}))}else console.log("syncInventoryEveryDay_Stock1stDayOfMonth"),e(null)}))}))},t.prototype.getReportInputOutputInventory_byEndTime_byIDMaterial=function(t,e,n){var o=this;return new Promise((function(i,a){var s=new Array;if("all"===e)s=o.vhAlgorithm.sortVietnamesebyASC(o.getlocalProducts(3),"name");else{var r=o.getlocalProduct(n);s.push(r)}var l={docs:new Array,empty:!0,size:0,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0,stock_last:0,cost_stock_last_btax:0,cost_stock_last_atax:0};if(s.length>0){var c=void 0;c="all"===e?"all"===n||void 0===n?{date:{$lte:t},ptype:{$eq:3},bill_type:{$in:[1,3,10,30,2,9,16,31]}}:{date:{$lte:t},ptype:{$eq:3},bill_type:{$in:[1,3,10,30,2,9,16,31]},id_branch:{$eq:n}}:"all"===n||void 0===n?{date:{$lte:t},ptype:{$eq:3},id_product:{$eq:e},bill_type:{$in:[1,3,10,30,2,9,16,31]}}:{date:{$lte:t},ptype:{$eq:3},id_product:{$eq:e},bill_type:{$in:[1,3,10,30,2,9,16,31]},id_branch:{$eq:n}},o.vhmongo_firebase.database().getDocsByFields("vhbill_details",c,{},{date:1},0).then((function(t){for(var e=0;e<s.length;e++){for(var n={_id:s[e]._id,name:s[e].name,type:s[e].type,unit:s[e].unit,img:s[e].img,allow_sell:s[e].allow_sell,barcode:s[e].barcode,price:s[e].price,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0,stock_last:0,cost_stock_last_btax:0,cost_stock_last_atax:0},o=0;o<t.length;o++)if(t[o].id_product===s[e]._id){new Date(t[o].date);1===t[o].bill_type||10===t[o].bill_type||30===t[o].bill_type?(n.revenue_btax=n.revenue_btax+t[o].price*t[o].quantity,n.revenue_atax=n.revenue_atax+t[o].price*t[o].quantity*(1+t[o].tax/100),n.outquantity=n.outquantity+t[o].quantity,l.revenue_btax=l.revenue_btax+t[o].price*t[o].quantity,l.revenue_atax=l.revenue_atax+t[o].price*t[o].quantity*(1+t[o].tax/100),l.outquantity=l.outquantity+t[o].quantity):2===t[o].bill_type||9===t[o].bill_type||31===t[o].bill_type?(n.cost_btax=n.cost_btax+t[o].price*t[o].quantity,n.cost_atax=n.cost_atax+t[o].price*t[o].quantity*(1+t[o].tax/100),n.inquantity=n.inquantity+t[o].quantity,l.cost_btax=l.cost_btax+t[o].price*t[o].quantity,l.cost_atax=l.cost_atax+t[o].price*t[o].quantity*(1+t[o].tax/100),l.inquantity=l.inquantity+t[o].quantity):3===t[o].bill_type?(n.outquantity=n.outquantity+t[o].quantity,l.outquantity=l.outquantity+t[o].quantity):16===t[o].bill_type&&(n.inquantity=n.inquantity+t[o].quantity,l.inquantity=l.inquantity+t[o].quantity)}n.stock_last=n.inquantity-n.outquantity,0!=n.inquantity&&(n.cost_stock_last_btax=n.cost_btax/n.inquantity*n.stock_last),0!=n.inquantity&&(n.cost_stock_last_atax=n.cost_atax/n.inquantity*n.stock_last),n.cost_stock_last_btax=Math.round(1e6*n.cost_stock_last_btax)/1e6,n.cost_stock_last_atax=Math.round(1e6*n.cost_stock_last_atax)/1e6,n.cost_atax=Math.round(1e6*n.cost_atax)/1e6,l.stock_last=l.stock_last+n.stock_last,l.cost_stock_last_btax=l.cost_stock_last_btax+n.cost_stock_last_btax,l.cost_stock_last_atax=l.cost_stock_last_atax+n.cost_stock_last_atax,0==n.inquantity&&0==n.outquantity||(l.cost_atax=Math.round(1e6*l.cost_atax)/1e6,n.index=l.size+1,l.docs.push(n),l.size++,l.empty=!1)}i(l)}))}else console.log("server -> products khong ton tai trong CSDL: "),i(l)}))},t.prototype.getReportInputOutputInventory_Detail_byEndTime_byIDMaterial=function(t,e,n){var o=this;return new Promise((function(i,a){var s,r=o.getlocalProduct(e),l={docs:new Array,empty:!0,size:0,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0};s="all"===n||void 0===n?{date:{$lte:t},id_product:{$eq:e},bill_type:{$in:[1,3,10,30,2,9,16,31]}}:{date:{$lte:t},id_product:{$eq:e},bill_type:{$in:[1,3,10,30,2,9,16,31]},id_branch:{$eq:n}},o.vhmongo_firebase.database().getDocsByFields("vhbill_details",s,{},{date:1},0).then((function(t){for(var e,n,o,a,s,c,u,d,_,p,b,f,h,y,m,v,g,x,q,w,P=0;P<t.length;P++){var D={id_bill:null===(e=t[P])||void 0===e?void 0:e.id_bill,bill_code:null===(n=t[P])||void 0===n?void 0:n.bill_code,bill_type:null===(o=t[P])||void 0===o?void 0:o.bill_type,date:null===(a=t[P])||void 0===a?void 0:a.date,tax:null===(s=t[P])||void 0===s?void 0:s.tax,price_btax:null===(c=t[P])||void 0===c?void 0:c.price,price_atax:(null===(u=t[P])||void 0===u?void 0:u.price)*(1+t[P].tax/100),payment_btax:(null===(d=t[P])||void 0===d?void 0:d.price)*(null===(_=t[P])||void 0===_?void 0:_.quantity),payment_atax:(null===(p=t[P])||void 0===p?void 0:p.price)*(null===(b=t[P])||void 0===b?void 0:b.quantity)*(1+t[P].tax/100),quantity:null===(f=t[P])||void 0===f?void 0:f.quantity,name:r.name,unit:r.unit};(null===(h=t[P])||void 0===h?void 0:h.id_cashier)&&(D.id_cashier=null===(y=t[P])||void 0===y?void 0:y.id_cashier),(null===(m=t[P])||void 0===m?void 0:m.id_employee)&&(D.id_employee=null===(v=t[P])||void 0===v?void 0:v.id_employee),(null===(g=t[P])||void 0===g?void 0:g.id_customer)&&(D.id_customer=null===(x=t[P])||void 0===x?void 0:x.id_customer),(null===(q=t[P])||void 0===q?void 0:q.id_supplier)&&(D.id_supplier=null===(w=t[P])||void 0===w?void 0:w.id_supplier),1===t[P].bill_type||10===t[P].bill_type||30===t[P].bill_type?(D.type="output",l.revenue_btax=l.revenue_btax+t[P].price*t[P].quantity,l.revenue_atax=l.revenue_atax+t[P].price*t[P].quantity*(1+t[P].tax/100),l.outquantity=l.outquantity+t[P].quantity):2===t[P].bill_type||31===t[P].bill_type?(D.type="input",l.cost_btax=l.cost_btax+t[P].price*t[P].quantity,l.cost_atax=l.cost_atax+t[P].price*t[P].quantity*(1+t[P].tax/100),l.inquantity=l.inquantity+t[P].quantity):9===t[P].bill_type?(D.type="beginning",l.cost_btax=l.cost_btax+t[P].price*t[P].quantity,l.cost_atax=l.cost_atax+t[P].price*t[P].quantity*(1+t[P].tax/100),l.inquantity=l.inquantity+t[P].quantity):3===t[P].bill_type?(D.type="output",l.outquantity=l.outquantity+t[P].quantity):16===t[P].bill_type&&(D.type="input",l.inquantity=l.inquantity+t[P].quantity),l.docs.push(D),l.size++,l.empty=!1}i(l)}))}))},t.prototype.getReportInputOutputInventory_Detail_byTime_byIDMaterial=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l=i.getlocalProduct(n),c={docs:new Array,empty:!0,size:0,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0};r="all"===o||void 0===o?{date:{$gte:t,$lte:e},id_product:{$eq:n},bill_type:{$in:[1,3,10,30,2,9,16,31]}}:{date:{$gte:t,$lte:e},id_product:{$eq:n},bill_type:{$in:[1,3,10,30,2,9,16,31]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("vhbill_details",r,{},{date:1},0).then((function(t){for(var e,n,o,i,s,r,u,d,_,p,b,f,h,y,m,v,g,x,q,w=0;w<t.length;w++){var P={id_bill:null===(e=t[w])||void 0===e?void 0:e.id_bill,bill_code:null===(n=t[w])||void 0===n?void 0:n.bill_code,bill_type:null===(o=t[w])||void 0===o?void 0:o.bill_type,date:null===(i=t[w])||void 0===i?void 0:i.date,price_btax:null===(s=t[w])||void 0===s?void 0:s.price,price_atax:(null===(r=t[w])||void 0===r?void 0:r.price)*(1+t[w].tax/100),payment_btax:(null===(u=t[w])||void 0===u?void 0:u.price)*(null===(d=t[w])||void 0===d?void 0:d.quantity),payment_atax:(null===(_=t[w])||void 0===_?void 0:_.price)*(null===(p=t[w])||void 0===p?void 0:p.quantity)*(1+t[w].tax/100),quantity:null===(b=t[w])||void 0===b?void 0:b.quantity,name:l.name,unit:l.unit};(null===(f=t[w])||void 0===f?void 0:f.id_cashier)&&(P.id_cashier=null===(h=t[w])||void 0===h?void 0:h.id_cashier),(null===(y=t[w])||void 0===y?void 0:y.id_employee)&&(P.id_employee=null===(m=t[w])||void 0===m?void 0:m.id_employee),(null===(v=t[w])||void 0===v?void 0:v.id_customer)&&(P.id_customer=null===(g=t[w])||void 0===g?void 0:g.id_customer),(null===(x=t[w])||void 0===x?void 0:x.id_supplier)&&(P.id_supplier=null===(q=t[w])||void 0===q?void 0:q.id_supplier),1===t[w].bill_type||10===t[w].bill_type||30===t[w].bill_type?(P.type="output",c.revenue_btax=c.revenue_btax+t[w].price*t[w].quantity,c.revenue_atax=c.revenue_atax+t[w].price*t[w].quantity*(1+t[w].tax/100),c.outquantity=c.outquantity+t[w].quantity):2===t[w].bill_type||31===t[w].bill_type?(P.type="input",c.cost_btax=c.cost_btax+t[w].price*t[w].quantity,c.cost_atax=c.cost_atax+t[w].price*t[w].quantity*(1+t[w].tax/100),c.inquantity=c.inquantity+t[w].quantity):9===t[w].bill_type?(P.type="beginning",c.cost_btax=c.cost_btax+t[w].price*t[w].quantity,c.cost_atax=c.cost_atax+t[w].price*t[w].quantity*(1+t[w].tax/100),c.inquantity=c.inquantity+t[w].quantity):3===t[w].bill_type?(P.type="output",c.outquantity=c.outquantity+t[w].quantity):16===t[w].bill_type&&(P.type="input",c.inquantity=c.inquantity+t[w].quantity),c.docs.push(P),c.size++,c.empty=!1}a(c)}))}))},t.prototype.getReportInputOutput_byTime_byIDMaterial=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Array;if("all"===n)r=i.vhAlgorithm.sortVietnamesebyASC(i.getlocalProducts(3),"name");else{var l=i.getlocalProduct(n);r.push(l)}var c={docs:new Array,empty:!0,size:0,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0};if(r.length>0){var u=void 0;u="all"===n?"all"===o||void 0===o?{date:{$gte:t,$lte:e},ptype:{$eq:3},bill_type:{$in:[1,3,10,30,2,16,31]}}:{date:{$gte:t,$lte:e},ptype:{$eq:3},bill_type:{$in:[1,3,10,30,2,16,31]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$gte:t,$lte:e},ptype:{$eq:3},id_product:{$eq:n},bill_type:{$in:[1,3,10,30,2,16,31]}}:{date:{$gte:t,$lte:e},ptype:{$eq:3},id_product:{$eq:n},bill_type:{$in:[1,3,10,30,2,16,31]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0).then((function(t){for(var e=0;e<r.length;e++){for(var n={_id:r[e]._id,name:r[e].name,type:r[e].type,unit:r[e].unit,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0},o=0;o<t.length;o++)t[o].id_product===r[e]._id&&(1===t[o].bill_type||10===t[o].bill_type||30===t[o].bill_type?(n.revenue_btax=n.revenue_btax+t[o].price*t[o].quantity,n.revenue_atax=n.revenue_atax+t[o].price*t[o].quantity*(1+t[o].tax/100),n.outquantity=n.outquantity+t[o].quantity,c.revenue_btax=c.revenue_btax+t[o].price*t[o].quantity,c.revenue_atax=c.revenue_atax+t[o].price*t[o].quantity*(1+t[o].tax/100),c.outquantity=c.outquantity+t[o].quantity):2===t[o].bill_type||31===t[o].bill_type?(n.cost_btax=n.cost_btax+t[o].price*t[o].quantity,n.cost_atax=n.cost_atax+t[o].price*t[o].quantity*(1+t[o].tax/100),n.inquantity=n.inquantity+t[o].quantity,c.cost_btax=c.cost_btax+t[o].price*t[o].quantity,c.cost_atax=c.cost_atax+t[o].price*t[o].quantity*(1+t[o].tax/100),c.inquantity=c.inquantity+t[o].quantity):3===t[o].bill_type?(n.outquantity=n.outquantity+t[o].quantity,c.outquantity=c.outquantity+t[o].quantity):16===t[o].bill_type&&(n.inquantity=n.inquantity+t[o].quantity,c.inquantity=c.inquantity+t[o].quantity));0==n.inquantity&&0==n.outquantity||(n.index=c.size+1,c.docs.push(n),c.size++,c.empty=!1)}a(c)}))}else console.log("server -> products khong ton tai trong CSDL: "),a(c)}))},t.prototype.getReportInputOutput_Detail_byTime_byIDMaterial=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l=i.getlocalProduct(n),c={docs:new Array,empty:!0,size:0,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0};r="all"===o||void 0===o?{date:{$gte:t,$lte:e},id_product:{$eq:n},bill_type:{$in:[1,3,10,30,2,16,31]}}:{date:{$gte:t,$lte:e},id_product:{$eq:n},bill_type:{$in:[1,3,10,30,2,16,31]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("vhbill_details",r,{},{date:1},0).then((function(t){for(var e,n,o,i,s,r,u,d,_,p,b,f,h,y,m,v,g,x,q,w=0;w<t.length;w++){var P={id_bill:null===(e=t[w])||void 0===e?void 0:e.id_bill,bill_code:null===(n=t[w])||void 0===n?void 0:n.bill_code,bill_type:null===(o=t[w])||void 0===o?void 0:o.bill_type,date:null===(i=t[w])||void 0===i?void 0:i.date,price_btax:null===(s=t[w])||void 0===s?void 0:s.price,price_atax:(null===(r=t[w])||void 0===r?void 0:r.price)*(1+t[w].tax/100),payment_btax:(null===(u=t[w])||void 0===u?void 0:u.price)*(null===(d=t[w])||void 0===d?void 0:d.quantity),payment_atax:(null===(_=t[w])||void 0===_?void 0:_.price)*(null===(p=t[w])||void 0===p?void 0:p.quantity)*(1+t[w].tax/100),quantity:null===(b=t[w])||void 0===b?void 0:b.quantity,name:l.name,unit:l.unit};(null===(f=t[w])||void 0===f?void 0:f.id_cashier)&&(P.id_cashier=null===(h=t[w])||void 0===h?void 0:h.id_cashier),(null===(y=t[w])||void 0===y?void 0:y.id_employee)&&(P.id_employee=null===(m=t[w])||void 0===m?void 0:m.id_employee),(null===(v=t[w])||void 0===v?void 0:v.id_customer)&&(P.id_customer=null===(g=t[w])||void 0===g?void 0:g.id_customer),(null===(x=t[w])||void 0===x?void 0:x.id_supplier)&&(P.id_supplier=null===(q=t[w])||void 0===q?void 0:q.id_supplier),1===t[w].bill_type||10===t[w].bill_type||30===t[w].bill_type?(P.type="output",c.revenue_btax=c.revenue_btax+t[w].price*t[w].quantity,c.revenue_atax=c.revenue_atax+t[w].price*t[w].quantity*(1+t[w].tax/100),c.outquantity=c.outquantity+t[w].quantity):2===t[w].bill_type||31===t[w].bill_type?(P.type="input",c.cost_btax=c.cost_btax+t[w].price*t[w].quantity,c.cost_atax=c.cost_atax+t[w].price*t[w].quantity*(1+t[w].tax/100),c.inquantity=c.inquantity+t[w].quantity):3===t[w].bill_type?(P.type="output",c.outquantity=c.outquantity+t[w].quantity):16===t[w].bill_type&&(P.type="input",c.inquantity=c.inquantity+t[w].quantity),c.docs.push(P),c.size++,c.empty=!1}a(c)}))}))},t.prototype.getReportRevenue_byHoursOut_hourArray=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l={docs:new Array,empty:!0,size:0,revenue:0};r="all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1,7,10,11]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1,7,10,11]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("bills",r,{},{date:1},0).then((function(t){if(t.length>0){for(var e=new Array,o=0;o<n.length;o++)e[o]={},e[o].revenue=0;for(var i=0;i<t.length;i++){var s=Object.assign({},t[i]);if(s.date){var r=new Date(s.date).getHours();for(o=0;o<n.length;o++)n[o]===r&&(e[o].revenue=e[o].revenue+Number(s.payment),l.revenue=l.revenue+Number(s.payment))}}l.docs=e,l.size=n.length,l.empty=!1}a(l)}))}))},t.prototype.getReportRevenue_byDaysOut_dayArray=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l={docs:new Array,empty:!0,size:0,revenue:0};r="all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1,7,10,11]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1,7,10,11]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("bills",r,{},{date:1},0).then((function(t){if(t.length>0){for(var e=new Array,o=0;o<n.length;o++)e[o]={},e[o].revenue=0;for(var i=0;i<t.length;i++){var s=t[i];if(s.date){var r=new Date(s.date).getDate();for(o=0;o<n.length;o++)n[o]===r&&(e[o].revenue=e[o].revenue+Number(s.payment),l.revenue=l.revenue+Number(s.payment))}}l.docs=e,l.size=n.length,l.empty=!1}a(l)}))}))},t.prototype.getReportRevenue_byMonthsOut_monthArray=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l={docs:new Array,empty:!0,size:0,revenue:0};r="all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1,7,10,11]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1,7,10,11]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("bills",r,{},{date:1},0).then((function(t){if(t.length>0){for(var e=new Array,o=0;o<n.length;o++)e[o]={},e[o].revenue=0;for(var i=0;i<t.length;i++){var s=t[i];if(s.date){var r=new Date(s.date).getMonth();for(o=0;o<n.length;o++)n[o]===r&&(e[o].revenue=e[o].revenue+Number(s.payment),l.revenue=l.revenue+Number(s.payment))}}l.docs=e,l.size=n.length,l.empty=!1}a(l)}))}))},t.prototype.getReportRevenue_byIDbranch=function(t,e,n){var o=this;return new Promise((function(i,a){var s,r={docs:new Array,empty:!0,size:0,revenue:0},l=new Array;if("all"===n||void 0===n)l=o.vhAlgorithm.sortVietnamesebyASC(o.getlocalBranchs(),"name"),s={date:{$gte:t,$lte:e},bill_type:{$in:[1,7,10,11]}};else{var c=o.getlocalBranch(n);l.push(c),s={date:{$gte:t,$lte:e},bill_type:{$in:[1,7,10,11]},id_branch:{$eq:n}}}o.vhmongo_firebase.database().getDocsByFields("bills",s,{},{date:1},0).then((function(t){if(t.length>0){for(var e=new Array,n=0;n<l.length;n++)e[n]={},e[n].id_branch=l[n]._id,e[n].name=l[n].name,e[n].revenue=0;for(var o=0;o<t.length;o++)for(n=0;n<l.length;n++)l[n]._id===t[o].id_branch&&(e[n].revenue=e[n].revenue+Number(t[o].payment),r.revenue=r.revenue+Number(t[o].payment));r.docs=e,r.size=l.length,r.empty=!1}i(r)}))}))},t.prototype.getReportSales_byHoursOut_hourArray=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0};r="all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("vhbill_details",r,{},{date:1},0).then((function(t){if(t.length>0){for(var e=new Array,o=0;o<n.length;o++)e[o]={},e[o].sales_btax=0,e[o].sales_atax=0;for(var i=0;i<t.length;i++){var s=Object.assign({},t[i]);if(s.date){var r=new Date(s.date).getHours();for(o=0;o<n.length;o++)n[o]===r&&(e[o].sales_btax=e[o].sales_btax+Number(s.price)*s.quantity,e[o].sales_atax=e[o].sales_atax+Number(s.price)*s.quantity*(1+s.tax/100),l.sales_btax=l.sales_btax+Number(s.price)*s.quantity,l.sales_atax=l.sales_atax+Number(s.price)*s.quantity*(1+s.tax/100))}}l.docs=e,l.size=n.length,l.empty=!1}a(l)}))}))},t.prototype.getReportSales_byDaysOut_dayArray=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0};r="all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("vhbill_details",r,{},{date:1},0).then((function(t){if(t.length>0){for(var e=new Array,o=0;o<n.length;o++)e[o]={},e[o].sales_btax=0,e[o].sales_atax=0;for(var i=0;i<t.length;i++){var s=Object.assign({},t[i]);if(s.date){var r=new Date(s.date).getDate();for(o=0;o<n.length;o++)n[o]===r&&(e[o].sales_btax=e[o].sales_btax+Number(s.price)*s.quantity,e[o].sales_atax=e[o].sales_atax+Number(s.price)*s.quantity*(1+s.tax/100),l.sales_btax=l.sales_btax+Number(s.price)*s.quantity,l.sales_atax=l.sales_atax+Number(s.price)*s.quantity*(1+s.tax/100))}}l.docs=e,l.size=n.length,l.empty=!1}a(l)}))}))},t.prototype.getReportSales_byMonthsOut_monthArray=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0};r="all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("vhbill_details",r,{},{date:1},0).then((function(t){if(t.length>0){for(var e=new Array,o=0;o<n.length;o++)e[o]={},e[o].sales_btax=0,e[o].sales_atax=0;for(var i=0;i<t.length;i++){var s=t[i];if(s.date){var r=new Date(s.date).getMonth();for(o=0;o<n.length;o++)n[o]===r&&(e[o].sales_btax=e[o].sales_btax+Number(s.price)*s.quantity,e[o].sales_atax=e[o].sales_atax+Number(s.price)*s.quantity*(1+s.tax/100),l.sales_btax=l.sales_btax+Number(s.price)*s.quantity,l.sales_atax=l.sales_atax+Number(s.price)*s.quantity*(1+s.tax/100))}}l.docs=e,l.size=n.length,l.empty=!1}a(l)}))}))},t.prototype.getReportSales_byIDbranch=function(t,e,n){var o=this;return new Promise((function(i,a){var s,r={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0},l=new Array;if("all"===n||void 0===n)l=o.vhAlgorithm.sortVietnamesebyASC(o.getlocalBranchs(),"name"),s={date:{$gte:t,$lte:e},bill_type:{$eq:1}};else{var c=o.getlocalBranch(n);l.push(c),s={date:{$gte:t,$lte:e},bill_type:{$eq:1},id_branch:{$eq:n}}}o.vhmongo_firebase.database().getDocsByFields("vhbill_details",s,{},{date:1},0).then((function(t){if(t.length>0){for(var e=new Array,n=0;n<l.length;n++)e[n]={},e[n].id_branch=l[n]._id,e[n].name=l[n].name,e[n].sales_btax=0,e[n].sales_atax=0;for(var o=0;o<t.length;o++){var a=t[o];for(n=0;n<l.length;n++)l[n]._id===a.id_branch&&(3===a.bill_type?(e[n].sales_btax=e[n].sales_btax-Number(a.price)*a.quantity,e[n].sales_atax=e[n].sales_atax-Number(a.price)*a.quantity*(1+a.tax/100),r.sales_btax=r.sales_btax-Number(a.price)*a.quantity,r.sales_atax=r.sales_atax-Number(a.price)*a.quantity*(1+a.tax/100)):(e[n].sales_btax=e[n].sales_btax+Number(a.price)*a.quantity,e[n].sales_atax=e[n].sales_atax+Number(a.price)*a.quantity*(1+a.tax/100),r.sales_btax=r.sales_btax+Number(a.price)*a.quantity,r.sales_atax=r.sales_atax+Number(a.price)*a.quantity*(1+a.tax/100)))}r.docs=e,r.size=l.length,r.empty=!1}i(r)}))}))},t.prototype.getReportSales_Products_byTime_DESC=function(t,e){var n=this;return new Promise((function(o,i){var a,s=n.getlocalProducts();a={date:{$gte:t,$lte:e},bill_type:{$in:[1]}};var r={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};s.length>0?n.vhmongo_firebase.database().getDocsByFields("vhbill_details",a,{},{date:1},0).then((function(t){var e;if(t.length>0)for(var i=0;i<s.length;i++){var a=!1,l=Object.assign({},s[i]),c={id_product:l._id,name:l.name,unit:l.unit,barcode:l.barcode,img:l.img,sales_btax:0,sales_atax:0,quantity:0,subs:new Array};if(null!=l.subs)for(var u=0;u<l.subs.length;u++){var d={id_subproduct:l.subs[u]._id,name:null===(e=l.subs[u])||void 0===e?void 0:e.name,sales_btax:0,sales_atax:0,quantity:0};c.subs.push(d)}for(var _=0;_<t.length;_++)if(s[i]._id===t[_].id_product){a=!0,c.quantity=c.quantity+t[_].quantity,c.sales_btax=c.sales_btax+t[_].price*t[_].quantity,c.sales_atax=c.sales_atax+t[_].price*t[_].quantity*(1+t[_].tax/100);for(u=0;u<c.subs.length;u++)if(c.subs[u].id_subproduct===t[_].id_subproduct){c.subs[u].quantity=c.subs[u].quantity+t[_].quantity,c.subs[u].sales_btax=c.subs[u].sales_btax+t[_].price*t[_].quantity,c.subs[u].sales_atax=c.subs[u].sales_atax+t[_].price*t[_].quantity*(1+t[_].tax/100);break}}a&&(r.quantity=r.quantity+c.quantity,r.sales_btax=r.sales_btax+c.sales_btax,r.sales_atax=r.sales_atax+c.sales_atax,c.index=r.size+1,r.docs.push(c),r.size++,r.empty=!1)}r.docs=n.vhAlgorithm.sortNumberbyDESC(r.docs,"sales_atax"),o(r)})):o(r)}))},t.prototype.getReportSales_Categorys_byTime_DESC=function(t,e){var n=this;return new Promise((function(o,i){var a=new Array;a=n.getlocalCategorys();var s={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};if(a.length>0){var r={date:{$gte:t,$lte:e},bill_type:{$in:[1]}};n.vhmongo_firebase.database().getDocsByFields("vhbill_details",r,{},{date:1},0).then((function(t){if(t.length>0){for(var e=0;e<t.length;e++){var i=n.getlocalProduct(t[e].id_product);t[e].id_category=i.id_category}for(e=0;e<a.length;e++){for(var r={id_category:a[e]._id,name:a[e].name,sales_btax:0,sales_atax:0,quantity:0},l=0;l<t.length;l++)a[e]._id===t[l].id_category&&(r.quantity=r.quantity+t[l].quantity,r.sales_btax=r.sales_btax+t[l].price*t[l].quantity,r.sales_atax=r.sales_atax+t[l].price*t[l].quantity*(1+t[l].tax/100));0!=r.quantity&&(s.quantity=s.quantity+r.quantity,s.sales_btax=s.sales_btax+r.sales_btax,s.sales_atax=s.sales_atax+r.sales_atax,r.index=s.size+1,s.docs.push(r),s.size++,s.empty=!1)}}s.docs=n.vhAlgorithm.sortNumberbyDESC(s.docs,"sales_atax"),o(s)}))}else o(s)}))},t.prototype.getReportMaterials_byOutOfStock=function(t){var e=this;return new Promise((function(n,o){var i=e.getlocalProducts(3),a=e.getlocalBranchs(),s=new Array;if("all"===t||void 0===t){for(var r=0;r<i.length;r++){i[r].quantity=0,i[r].branchs=new Array;for(var l=0;l<a.length;l++)if(void 0===i[r].quantity_branch[a[l]._id]&&(i[r].quantity_branch[a[l]._id]=0),i[r].quantity_branch[a[l]._id]<=0){i[r].quantity=i[r].quantity+i[r].quantity_branch[a[l]._id];var c={id_branch:a[l]._id,name:a[l].name,quantity:i[r].quantity_branch[a[l]._id]};i[r].branchs.push(c)}delete i[r].quantity_branch}s=i.filter((function(t){return t.branchs.length>0}))}else{for(r=0;r<i.length;r++){i[r].quantity=0,i[r].branchs=new Array,void 0===i[r].quantity_branch[t]&&(i[r].quantity_branch[t]=0),i[r].quantity=i[r].quantity_branch[t];c={id_branch:t,name:e.getlocalBranch(t).name,quantity:i[r].quantity_branch[t]};i[r].branchs.push(c),delete i[r].quantity_branch}s=i.filter((function(t){if(t.quantity<=0)return!0}))}n(s)}))},t.prototype.getReportMaterials_byLowInStock=function(t){var e=this;return new Promise((function(n,o){var i=e.getlocalProducts(3),a=e.getlocalBranchs(),s=new Array;if("all"===t||void 0===t){for(var r=0;r<i.length;r++){i[r].quantity=0,i[r].branchs=new Array;for(var l=0;l<a.length;l++)if(void 0===i[r].quantity_branch[a[l]._id]&&(i[r].quantity_branch[a[l]._id]=0),i[r].quantity_branch[a[l]._id]<=i[r].warning_number){i[r].quantity=i[r].quantity+i[r].quantity_branch[a[l]._id];var c={id_branch:a[l]._id,name:a[l].name,quantity:i[r].quantity_branch[a[l]._id]};i[r].branchs.push(c)}delete i[r].quantity_branch}s=i.filter((function(t){return t.branchs.length>0}))}else{for(r=0;r<i.length;r++){i[r].quantity=0,i[r].branchs=new Array,void 0===i[r].quantity_branch[t]&&(i[r].quantity_branch[t]=0),i[r].quantity=i[r].quantity_branch[t];c={id_branch:t,name:e.getlocalBranch(t).name,quantity:i[r].quantity_branch[t]};i[r].branchs.push(c),delete i[r].quantity_branch}s=i.filter((function(t){if(t.quantity<=t.warning_number)return!0}))}n(s)}))},t.prototype.makeCorrectQuantityMaterials=function(){var t=this;return new Promise((function(e,n){var o=t.getlocalProducts(3),i=t.getlocalBranchs();t.vhmongo_firebase.database().getDocsByFields("vhbill_details",{ptype:{$eq:3},bill_type:{$in:[1,3,10,30,2,9,16,31]}},{},{date:1},0).then((function(n){if(o.length>0&&n.length>0){for(var a=new Array,s=0;s<o.length;s++){for(var r=0,l={},c=0;c<i.length;c++)l[i[c]._id]=0;for(var u=0;u<n.length;u++){var d=n[u];o[s]._id===d.id_product&&(1===d.bill_type||3===d.bill_type||10===d.bill_type||30===n[u].bill_type?(r-=d.quantity,null!=l[d.id_branch]?l[d.id_branch]=l[d.id_branch]-d.quantity:l[d.id_branch]=-d.quantity):2!==d.bill_type&&9!==d.bill_type&&16!==d.bill_type&&31!==n[u].bill_type||(r+=d.quantity,null!=l[d.id_branch]?l[d.id_branch]=l[d.id_branch]+d.quantity:l[d.id_branch]=d.quantity))}var _=!1;for(var p in o[s].quantity!=r&&(_=!0),o[s].quantity_branch)for(var b in l)p===b&&o[s].quantity_branch[p]===l[b]&&(_=!0);_&&a.push(t.updateProduct(o[s]._id,{quantity:r,quantity_branch:l}))}Promise.all(a).then((function(){e(null)}))}else e(null)}))}))},t.prototype.getReportInventoryTime_byTimes=function(t){var e=this;return new Promise((function(n,o){var i=e.getlocalInventorytime(t),a=e.getlocalProducts(3),s={docs:new Array,empty:!0,size:0};if(a.length>0){s={docs:new Array,empty:!0,size:0,total_stock:0,total_realstock:0,total_inventorynotes:new Array};var r=new Array,l=new Array,c=new Array,u=new Array,d={date:{$lte:i.date},ptype:{$eq:3},bill_type:{$in:[1,3,10,2,9,16]}};u[0]=e.vhmongo_firebase.database().getDocsByFields("vhbill_details",d,{},{date:1},0).then((function(t){r=E(t)}));var _={id_inventorytime:{$eq:t},bill_type:{$in:[13]}};u[1]=e.vhmongo_firebase.database().getDocsByFields("vhbill_details",_,{},{date:1},0).then((function(t){l=E(t)}));var p={id_inventorytime:{$eq:t},bill_type:{$in:[13]}};u[2]=e.vhmongo_firebase.database().getDocsByFields("bills",p,{},{date:1},0).then((function(t){c=E(t)})),Promise.all(u).then((function(){for(var t=0,e=0,o=new Array,i=0;i<c.length;i++){var u={bill_code:c[i].bill_code,quantity:0};o.push(u)}for(var d=function(n){if(3===a[n].type){for(var i=0,u=0;u<r.length;u++)a[n]._id===r[u].id_product&&(1===r[u].bill_type||3===r[u].bill_type||10===r[u].bill_type?i-=r[u].quantity:2!==r[u].bill_type&&9!==r[u].bill_type&&16!==r[u].bill_type||(i+=r[u].quantity));var d=new Array,_=0;for(u=0;u<c.length;u++){var p={bill_code:c[u].bill_code,quantity:0};d.push(p)}for(u=0;u<l.length;u++)for(var b=0;b<d.length;b++)a[n]._id===l[u].id_product&&d[b].bill_code===l[u].bill_code&&(d[b].quantity=l[u].quantity,_+=l[u].quantity,o[b].quantity=o[b].quantity+l[u].quantity);t+=i,e+=_;var f={_id:a[n]._id,data:function(){var t=a[n];return delete a[n]._id,t},stock:i,realstock:_,inventorynotes:d};s.docs.push(f),s.empty=!1,s.size++}},_=0;_<a.length;_++)d(_);s.total_stock=t,s.total_realstock=e,s.total_inventorynotes=E(o),n(s)}))}}))},t}();W.decorators=[{type:e.Injectable}],W.ctorParameters=function(){return[{type:o.Vhmongo_firebase},{type:V},{type:F},{type:L}]};var Q=function(){function t(t){this.vhmongo_firebase=t}return t.prototype.startLocalStorage=function(){return new Promise((function(t){t(null)}))},t.prototype.callbackMessagesFromChatStores=function(){return c.Observable.create((function(t){t.next()}))},t.prototype.removeAllCallback=function(){},t.prototype.connect=function(){},t.prototype.callbackChatStoreList=function(){var t=this;return c.Observable.create((function(e){t.callbackChatStore((function(){t.getchatStoreList().then((function(t){e.next(t)}))}))}))},t.prototype.callbackChatStore=function(t){t()},t.prototype.getchatStoreList=function(){return new Promise((function(t,e){t({})}))},t.prototype.selectChatStore=function(t){return new Promise((function(t,e){t(!0)}))},t.prototype.unselectChatStore=function(t){return new Promise((function(t,e){t(!0)}))},t.prototype.finishChatStore=function(t){return new Promise((function(t,e){t(!0)}))},t.prototype.connectChatStore=function(t){},t.prototype.sendMessageToChatStore=function(t,e){},t.prototype.sendImageToChatStore=function(t,e){},t}();Q.decorators=[{type:e.Injectable}],Q.ctorParameters=function(){return[{type:o.Vhmongo_firebase}]};var J=function(){function t(t,e,n,o){var i=this;this.vhmongo_firebase=t,this.vhQuery=e,this.vhAuth=n,this.vhAlgorithm=o,this.utoken=null,this.cameras=new Array,this.cloudcams=new Array,this.rooms=new Array,this.mainboards=new Array,this.functions=new Array,this.components=new Array,this.icons=new Array,this.appsettingstations=new Array,this.scripts=new Array,this.script_details=new Array,this.logs=new Array,this.hwinfo={},this.subjectcameras=new c.Subject,this.subjectappsettingstations=new c.Subject,this.subjectrooms=new c.Subject,this.subjectmainboards=new c.Subject,this.subjectfunctions=new c.Subject,this.subjecticons=new c.Subject,this.subjectcomponents=new c.Subject,r.Device.getId().then((function(t){var e=i.vhAuth.localStorageGET("hwinfo");null!=e&&null!=e?i.hwinfo=e:(i.hwinfo=Object.assign({},t),i.vhAuth.localStorageSET("hwinfo",i.hwinfo))}))}return t.prototype.syncCollections=function(){var t=this;return new Promise((function(e,n){t.initSyncCollections(),t.callbackCollectionInsert().subscribe(),t.callbackCollectionUpdate().subscribe(),t.callbackCollectionDelete().subscribe(),t.getEUtokenfromDatabase(),setTimeout((function(){e(!0)}),5e3)}))},t.prototype.initSyncCollections=function(){var t=new Array;return t[0]="rooms",t[1]="mainboards",t[2]="components",t[3]="icons",t[4]="functions",t[5]="vhemployees",t[6]="appsettingstations",this.vhmongo_firebase.socketMongoDB().initSyncCollections(t)},t.prototype.closeSyncCollections=function(){this.vhmongo_firebase.socketMongoDB().closeSyncCollections()},t.prototype.callbackCollectionInsert=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackCollectionInsert().subscribe((function(n){if("vhemployees"===n.colname?n.colname="employees":"appsettingstations"===n.colname&&(n.colname="appsettingstations"),"cameras"===n.colname)t.getlocalCamera(n._id)||((o=Object.assign({},n.data))._id=n._id,t.cameras.push(o),t.publishObservableEventCameras(),e.next(n.colname));else if("rooms"===n.colname){if(!t.getlocalRoom(n._id))(o=Object.assign({},n.data))._id=n._id,t.rooms.push(o),t.publishObservableEventRooms(),e.next(n.colname)}else if("mainboards"===n.colname){if(!t.getlocalMainboard(n._id))(o=Object.assign({},n.data))._id=n._id,t.mainboards.push(o),t.publishObservableEventMainboards(),e.next(n.colname)}else if("components"===n.colname){if(!t.getlocalComponent(n._id))(o=Object.assign({},n.data))._id=n._id,t.components.push(o),t.publishObservableEventComponents(),e.next(n.colname)}else if("icons"===n.colname){if(!t.getlocalIcon(n._id))(o=Object.assign({},n.data))._id=n._id,t.icons.push(o),t.publishObservableEventIcons(),e.next(n.colname)}else if("functions"===n.colname){if(!t.getlocalFunction(n._id))(o=Object.assign({},n.data))._id=n._id,t.functions.push(o),t.publishObservableEventFunctions(),e.next(n.colname)}else if("employees"===n.colname){(o=Object.assign({},n.data))._id=n._id,t.vhAuth.insertlocalEmployeeFromSyncCollection(o),t.vhAuth.publishObservableEventEmployees(),e.next(n.colname)}else if("appsettingstations"===n.colname){var o;if(!t.getLocalAppSettingStation(n._id))if(n.data.uuid===t.hwinfo.uuid)(o=Object.assign({},n.data))._id=n._id,delete o.uuid,t.appsettingstations.push(o),t.publishObservableEventAppSettingNameStations(),e.next(n.colname)}console.log("inserted",n.colname)}))}))},t.prototype.callbackCollectionUpdate=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackCollectionUpdate().subscribe((function(n){if("vhemployees"===n.colname?n.colname="employees":"appsettingstations"===n.colname&&(n.colname="appsettingstations"),"cameras"===n.colname){for(var o=0;o<t.cameras.length;o++)if(t.cameras[o]._id===n._id){t.cameras[o]=Object.assign(Object.assign({},t.cameras[o]),n.data),t.publishObservableEventCameras(),e.next(n.colname);break}}else if("rooms"===n.colname){for(o=0;o<t.rooms.length;o++)if(t.rooms[o]._id===n._id){t.rooms[o]=Object.assign(Object.assign({},t.rooms[o]),n.data),t.publishObservableEventRooms(),e.next(n.colname);break}}else if("mainboards"===n.colname){for(o=0;o<t.mainboards.length;o++)if(t.mainboards[o]._id===n._id){t.mainboards[o]=Object.assign(Object.assign({},t.mainboards[o]),n.data),t.publishObservableEventMainboards(),e.next(n.colname);break}}else if("components"===n.colname){for(o=0;o<t.components.length;o++)if(t.rooms[o]._id===n._id){t.rooms[o]=Object.assign(Object.assign({},t.components[o]),n.data),t.publishObservableEventComponents(),e.next(n.colname);break}}else if("icons"===n.colname){for(o=0;o<t.icons.length;o++)if(t.icons[o]._id===n._id){t.icons[o]=Object.assign(Object.assign({},t.icons[o]),n.data),t.publishObservableEventIcons(),e.next(n.colname);break}}else if("functions"===n.colname){for(o=0;o<t.icons.functions;o++)if(t.functions[o]._id===n._id){t.functions[o]=Object.assign(Object.assign({},t.functions[o]),n.data),t.publishObservableEventFunctions(),e.next(n.colname);break}}else if("employees"===n.colname)t.vhAuth.updateLocalEmployeeFromSyncCollection(n._id,n.data),t.vhAuth.publishObservableEventEmployees(),e.next(n.colname);else if("appsettingstations"===n.colname)for(o=0;o<t.appsettingstations.length;o++)if(t.appsettingstations[o]._id===n._id){t.appsettingstations[o]=Object.assign(Object.assign({},t.appsettingstations[o]),n.data),t.publishObservableEventAppSettingNameStations(),e.next(n.colname);break}console.log("updated",n.colname)}))}))},t.prototype.callbackCollectionDelete=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackCollectionDelete().subscribe((function(n){if("vhemployees"===n.colname?n.colname="employees":"appsettingstations"===n.colname&&(n.colname="appsettingstations"),"cameras"===n.colname){for(var o=0;o<t.cameras.length;o++)if(t.cameras[o]._id===n._id){t.cameras.splice(o,1),t.publishObservableEventCameras(),e.next(n.colname);break}}else if("rooms"===n.colname){for(o=0;o<t.rooms.length;o++)if(t.rooms[o]._id===n._id){t.rooms.splice(o,1),t.publishObservableEventRooms(),e.next(n.colname);break}}else if("mainboards"===n.colname){for(o=0;o<t.mainboards.length;o++)if(t.mainboards[o]._id===n._id){t.mainboards.splice(o,1),t.publishObservableEventMainboards(),e.next(n.colname);break}}else if("components"===n.colname){for(o=0;o<t.components.length;o++)if(t.components[o]._id===n._id){t.components.splice(o,1),t.publishObservableEventComponents(),e.next(n.colname);break}}else if("icons"===n.colname){for(o=0;o<t.icons.length;o++)if(t.icons[o]._id===n._id){t.icons.splice(o,1),t.publishObservableEventIcons(),e.next(n.colname);break}}else if("functions"===n.colname){for(o=0;o<t.functions.length;o++)if(t.functions[o]._id===n._id){t.functions.splice(o,1),t.publishObservableEventFunctions(),e.next(n.colname);break}}else if("employees"===n.colname)t.vhAuth.deleteLocalEmployeeFromSyncCollection(n._id),t.vhAuth.publishObservableEventEmployees(),e.next(n.colname);else if("appsettingstations"===n.colname)for(o=0;o<t.appsettingstations.length;o++)if(t.appsettingstations[o]._id===n._id){t.appsettingstations.splice(o,1),t.publishObservableEventAppSettingNameStations(),e.next(n.colname);break}console.log("deleted",n.colname)}))}))},t.prototype.startLocalStorage=function(){var t=this;return new Promise((function(e){var n=new Array;n[0]=t.vhAuth.refreshLocalMyPermission(),n[1]=t.refreshLocalCloudCams(),n[2]=t.getEUtokenfromDatabase(),t.vhQuery.asyncPromiseAll(n).then((function(){e(null)}))}))},t.prototype.getCloudCamServer=function(){return this.vhmongo_firebase.f3rdclouds().getCloudCamServer()},t.prototype.createPaymentVnpay=function(t,e,n,o,i,a){var s={projectName:this.vhmongo_firebase.auth().getProjectName(),sid:this.vhmongo_firebase.auth().getDatabase(),data:n};this.vhmongo_firebase.f3rdclouds().createPaymentVnpay(t,e,"billpayment","thanh toan","vn",s,o,i,a).then((function(t){window.location=t.data}),(function(t){console.log("error",t)}))},t.prototype.getDiscountFromCode=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.f3rdclouds().getDiscountFromCode(t).then((function(t){t.size>0?n(t.docs[0].data().discount):n(0)}),(function(t){console.error(t),o(t)}))}))},t.prototype.getPriceList_Records=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.clouds().getPriceList_Records().then((function(n){var o=new Array;n.size>0&&n.forEach((function(t){o.push(t.data()),o[o.length-1]._id=t.id})),o=t.vhAlgorithm.sortNumberbyASC(o,"month"),e(o)}),(function(t){console.error(t),n(t)}))}))},t.prototype.getPriceList_Detectors=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.clouds().getPriceList_Detectors().then((function(n){var o=new Array;n.size>0&&n.forEach((function(t){o.push(t.data()),o[o.length-1]._id=t.id})),o=t.vhAlgorithm.sortNumberbyASC(o,"month"),e(o)}),(function(t){console.error(t),n(t)}))}))},t.prototype.getPriceList_rLPRs=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.clouds().getPriceList_rLPRs().then((function(n){var o=new Array;n.size>0&&n.forEach((function(t){o.push(t.data()),o[o.length-1]._id=t.id})),o=t.vhAlgorithm.sortNumberbyASC(o,"month"),e(o)}),(function(t){console.error(t),n(t)}))}))},t.prototype.getPriceList_cLPRs=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.clouds().getPriceList_cLPRs().then((function(n){var o=new Array;n.size>0&&n.forEach((function(t){o.push(t.data()),o[o.length-1]._id=t.id})),o=t.vhAlgorithm.sortNumberbyASC(o,"month"),e(o)}),(function(t){console.error(t),n(t)}))}))},t.prototype.publishObservableEventCameras=function(){this.subjectcameras.next(this.cameras)},t.prototype.observableLocalCameras=function(){return this.subjectcameras},t.prototype.getObservableLocalCameras=function(){var t=this;return new c.Observable((function(e){t.observableLocalCameras().subscribe((function(t){e.next(t)})),t.publishObservableEventCameras()}))},t.prototype.getlocalCamera=function(t){for(var e=0;e<this.cameras.length;e++)if(this.cameras[e]._id===t)return this.cameras[e];return null},t.prototype.getlocalCameras=function(){return this.cameras},t.prototype.refreshLocalCameras=function(){var t=this;return new Promise((function(e){t.getCameras().then((function(){e(null)}))}))},t.prototype.createLicenseCam=function(){return new Promise((function(t,e){}))},t.prototype.addCamera=function(t){return new Promise((function(t,e){}))},t.prototype.updateCamera=function(t,e){var n=this;return new Promise((function(e,o){n.vhmongo_firebase.database().getDoc("cameras",t).then((function(t){}),(function(t){o(t)}))}))},t.prototype.deleteCamera=function(t){return new Promise((function(t,e){}))},t.prototype.getCamera=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("cameras",t).then((function(t){n(t)}))}))},t.prototype.getCameras=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("cameras").then((function(n){t.cameras=new Array,t.cameras=n,e(n)}),(function(t){n(t)}))}))},t.prototype.getFee_detailsByFields=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.database().getDocsByFields_onRootCollectionsFirebase("fee_details",t,{},n,o).then((function(t){e(t)}),(function(t){a(t)}))}))},t.prototype.getFeesByFields=function(t,e,n,o){var i=this;return new Promise((function(e,a){t.database={database:{$eq:i.vhmongo_firebase.auth().getDatabase()}},i.vhmongo_firebase.database().getDocsByFields_onRootCollectionsFirebase("fees",t,{},n,o).then((function(t){e(t)}),(function(t){a(t)}))}))},t.prototype.getFee=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc_onRootCollectionsFirebase("fees",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getFee_Details=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields_onRootCollectionsFirebase("fee_details",{id_fee:{$eq:t}},{},{},0).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.importUtoken=function(t){this.vhmongo_firebase.f3rdclouds().importUtoken(t)},t.prototype.getLocalEUtoken=function(){return this.vhmongo_firebase.f3rdclouds().getLocalEUtoken()},t.prototype.getEUtokenfromDatabase=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.f3rdclouds().getEUtokenfromDatabase().then((function(){e(null)}))}))},t.prototype.checkExpiredUtoken=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.f3rdclouds().checkExpiredUtoken().then((function(t){0===t.vcode?e(!0):(console.log(t.message),e(!1))}))}))},t.prototype.getlocalCloudCam=function(t){for(var e=0;e<this.cloudcams.length;e++)if(this.cloudcams[e].licensecam===t)return this.cloudcams[e];return null},t.prototype.getlocalCloudCams=function(){return this.cloudcams},t.prototype.refreshLocalCloudCams=function(){var t=this;return new Promise((function(e){t.getCloudCamsByEndUser().then((function(){e(null)}))}))},t.prototype.changeCloudCamEnableCLPRbyEndUser=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().changeCloudCamEnableCLPRbyEndUser(t,e).then((function(t){0===t.vcode?o(!0):(console.log(t.message),o(!1))}))}))},t.prototype.changeCloudCamEnableRLPRbyEndUser=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().changeCloudCamEnableRLPRbyEndUser(t,e).then((function(t){0===t.vcode?o(!0):(console.log(t.message),o(!1))}))}))},t.prototype.changeCloudCamEnableDetectorByEndUser=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().changeCloudCamEnableDetectorByEndUser(t,e).then((function(t){0===t.vcode?o(!0):(console.log(t.message),o(!1))}))}))},t.prototype.changeCloudCamEnableRecordByEndUser=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().changeCloudCamEnableRecordByEndUser(t,e).then((function(t){0===t.vcode?o(!0):(console.log(t.message),o(!1))}))}))},t.prototype.changeCloudCamEnableActiveByEndUser=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().changeCloudCamEnableActiveByEndUser(t,e).then((function(t){0===t.vcode?o(!0):(console.log(t.message),o(!1))}))}))},t.prototype.changeCloudCamURLbyEndUser=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().changeCloudCamURLbyEndUser(t,e).then((function(t){0===t.vcode?o(!0):(console.log(t.message),o(!1))}))}))},t.prototype.addCloudCamByEndUser=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().addCloudCamByEndUser(t,e).then((function(t){0===t.vcode?o(t.data):(console.log(t.message),o(null))}))}))},t.prototype.addCloudCamBoxByEndUser=function(t,e,n){var o=this;return new Promise((function(i){o.vhmongo_firebase.f3rdclouds().addCloudCamBoxByEndUser(t,e,n).then((function(t){0===t.vcode?i(t.data):(console.log(t.message),i(null))}))}))},t.prototype.updateCloudCamDataByEndUser=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().updateCloudCamDataByEndUser(t,e).then((function(t){0===t.vcode?o(!0):(console.log(t.message),o(!1))}))}))},t.prototype.deleteCloudCamByEndUser=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.f3rdclouds().deleteCloudCamByEndUser(t).then((function(t){0===t.vcode?n(!0):(console.log(t.message),n(!1))}))}))},t.prototype.getCloudCamByEndUser=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.f3rdclouds().getCloudCamByEndUser(t).then((function(t){0===t.vcode?n(t.data):(console.log(t.message),n(null))}))}))},t.prototype.getCloudCamsByEndUser=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.f3rdclouds().getCloudCamsByEndUser().then((function(n){0===n.vcode?t.cloudcams=n.data:(console.log(n.message),t.cloudcams=new Array),e(t.cloudcams)}),(function(t){n(t)}))}))},t.prototype.getPlaybackListCamByEndUser=function(t,e,n,o){var i=this;return new Promise((function(a,s){i.vhmongo_firebase.f3rdclouds().getPlaybackListCambyEndUser(t,e,n,o).then((function(t){0===t.vcode?a(t.data):(console.log(t),a([]))}),(function(t){s(t)}))}))},t.prototype.publishObservableEventRooms=function(){this.subjectrooms.next(this.rooms)},t.prototype.observableLocalRooms=function(){return this.subjectrooms},t.prototype.getObservableLocalRooms=function(){var t=this;return new c.Observable((function(e){t.observableLocalRooms().subscribe((function(t){e.next(t)})),t.publishObservableEventRooms()}))},t.prototype.getlocalRoom=function(t){for(var e=0;e<this.rooms.length;e++)if(this.rooms[e]._id===t)return this.rooms[e];return null},t.prototype.getlocalRooms=function(){return this.rooms},t.prototype.refreshLocalRooms=function(){var t=this;return new Promise((function(e){t.getRooms().then((function(){e(null)}))}))},t.prototype.addRoom=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("rooms",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateRoom=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("rooms",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteRoom=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("rooms",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getRoom=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("rooms",t).then((function(t){n(t)}))}))},t.prototype.getRooms=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("rooms").then((function(n){t.rooms=new Array,t.rooms=n,e(n)}),(function(t){n(t)}))}))},t.prototype.getlocalLog=function(t){for(var e=0;e<this.logs.length;e++)if(this.logs[e]._id===t)return this.logs[e];return null},t.prototype.getlocalLogs=function(){return this.logs},t.prototype.refreshLocalLogs=function(){var t=this;return new Promise((function(e){t.getLogs().then((function(){e(null)}))}))},t.prototype.addLog=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("logs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateLog=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("logs",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteLog=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("logs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getLog=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("logs",t).then((function(t){n(t)}))}))},t.prototype.getLogs=function(){var t=this;return new Promise((function(e,n){t.logs=new Array,t.vhmongo_firebase.database().getDocs("logs").then((function(n){t.logs=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventMainboards=function(){this.subjectmainboards.next(this.mainboards)},t.prototype.observableLocalMainboards=function(){return this.subjectmainboards},t.prototype.getObservableLocalMainboards=function(){var t=this;return new c.Observable((function(e){t.observableLocalMainboards().subscribe((function(t){e.next(t)})),t.publishObservableEventMainboards()}))},t.prototype.getlocalMainboard=function(t){for(var e=0;e<this.mainboards.length;e++)if(this.mainboards[e]._id===t)return this.mainboards[e];return null},t.prototype.getlocalMainboards=function(){return this.mainboards},t.prototype.refreshLocalMainboards=function(){var t=this;return new Promise((function(e){t.getMainboards().then((function(){e(null)}))}))},t.prototype.addMainboard=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("mainboards",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateMainboard=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("mainboards",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteMainboard=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("mainboards",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getMainboard=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("mainboards",t).then((function(t){n(t)}))}))},t.prototype.getMainboards=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("mainboards").then((function(n){t.mainboards=new Array,t.mainboards=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventFunctions=function(){this.subjectfunctions.next(this.functions)},t.prototype.observableLocalFunctions=function(){return this.subjectfunctions},t.prototype.getObservableLocalFunctions=function(){var t=this;return new c.Observable((function(e){t.observableLocalFunctions().subscribe((function(t){e.next(t)})),t.publishObservableEventFunctions()}))},t.prototype.getlocalFunction=function(t){for(var e=0;e<this.functions.length;e++)if(this.functions[e]._id===t)return this.functions[e];return null},t.prototype.getlocalFunctions=function(){return this.functions},t.prototype.refreshLocalFunctions=function(){var t=this;return new Promise((function(e){t.getFunctions().then((function(){e(null)}))}))},t.prototype.addFunction=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("functions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateFunction=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("functions",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteFunction=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("functions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getFunction=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("functions",t).then((function(t){n(t)}))}))},t.prototype.getFunctions=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("functions").then((function(n){t.functions=new Array,t.functions=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventComponents=function(){this.subjectcomponents.next(this.components)},t.prototype.observableLocalComponents=function(){return this.subjectcomponents},t.prototype.getObservableLocalComponents=function(){var t=this;return new c.Observable((function(e){t.observableLocalComponents().subscribe((function(t){e.next(t)})),t.publishObservableEventComponents()}))},t.prototype.getlocalComponent=function(t){for(var e=0;e<this.components.length;e++)if(this.components[e]._id===t)return this.components[e];return null},t.prototype.getlocalComponents=function(){return this.components},t.prototype.refreshLocalComponents=function(){var t=this;return new Promise((function(e){t.getComponents().then((function(){e(null)}))}))},t.prototype.addComponent=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("components",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateComponent=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("components",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteComponent=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("components",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getComponent=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("components",t).then((function(t){n(t)}))}))},t.prototype.getComponents=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("components").then((function(n){t.components=new Array,t.components=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventIcons=function(){this.subjecticons.next(this.icons)},t.prototype.observableLocalIcons=function(){return this.subjecticons},t.prototype.getObservableLocalIcons=function(){var t=this;return new c.Observable((function(e){t.observableLocalIcons().subscribe((function(t){e.next(t)})),t.publishObservableEventIcons()}))},t.prototype.getlocalIcon=function(t){for(var e=0;e<this.icons.length;e++)if(this.icons[e]._id===t)return this.icons[e];return null},t.prototype.getlocalIcons=function(){return this.icons},t.prototype.refreshLocalIcons=function(){var t=this;return new Promise((function(e){t.getIcons().then((function(){e(null)}))}))},t.prototype.addIcon=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("icons",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateIcon=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("icons",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteIcon=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("icons",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getIcon=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("icons",t).then((function(t){n(t)}))}))},t.prototype.getIcons=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("icons").then((function(n){t.icons=new Array,t.icons=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventAppSettingNameStations=function(){this.subjectappsettingstations.next()},t.prototype.observableLocalAppSettingNameStations=function(){return this.subjectappsettingstations},t.prototype.getObservableLocalAppSettingNameStations=function(){var t=this;return new c.Observable((function(e){t.observableLocalAppSettingNameStations().subscribe((function(){for(var n=new Array,o=0;o<t.appsettingstations.length;o++)n.push(t.appsettingstations[o].appsetting_name);e.next(n)})),t.publishObservableEventAppSettingNameStations()}))},t.prototype.getLocalAppSettingNameStations=function(){for(var t=new Array,e=0;e<this.appsettingstations.length;e++)t.push(this.appsettingstations[e].appsetting_name);return t},t.prototype.getLocalAppSettingNameStation=function(t){for(var e={},n=0;n<this.appsettingstations.length;n++)if(this.appsettingstations[n].appsetting_name===t){delete(e=Object.assign({},this.appsettingstations[n]))._id,delete e.appsetting_name;break}return e},t.prototype.getLocalAppSettingStation=function(t){for(var e=0;e<this.appsettingstations.length;e++)if(this.appsettingstations[e]._id===t)return this.appsettingstations[e];return null},t.prototype.refreshLocalAppSettingNameStations=function(){return new Promise((function(t,e){t(null)}))},t.prototype.getAppSettingStations=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocsByFields("appsettingstations",{uuid:{$eq:t.hwinfo.uuid}},{},{},0).then((function(n){n.length>0&&(t.appsettingstations=n),e(null)}),(function(t){n(t)}))}))},t.prototype.updateAppSettingNameStation=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().getDocsByFields("appsettingstations",{appsetting_name:{$eq:t},uuid:{$eq:n.hwinfo.uuid}},{},{},0).then((function(a){if(a.length>0)n.vhmongo_firebase.database().updateDoc("appsettingstations",a[0]._id,e).then((function(t){o(t)}),(function(t){i(t)}));else{var s=Object.assign({},e);s.appsetting_name=t,s.uuid=n.hwinfo.uuid,n.vhmongo_firebase.database().addDoc("appsettingstations",s).then((function(){o(!0)}),(function(t){i(t)}))}}))}))},t.prototype.deleteAppSettingNameStation=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("appsettingstations",{appsetting_name:{$eq:t},uuid:{$eq:e.hwinfo.uuid}},{},{},0).then((function(t){t.length>0?e.vhmongo_firebase.database().deleteDoc("appsettingstations",t[0]._id).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}))}))},t.prototype.getlocalScript=function(t){for(var e=0;e<this.scripts.length;e++)if(this.scripts[e]._id===t)return this.scripts[e];return null},t.prototype.getlocalScripts=function(){return this.scripts},t.prototype.refreshLocalScripts=function(){var t=this;return new Promise((function(e){t.getScripts().then((function(){e(null)}))}))},t.prototype.addScript=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("scripts",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateScript=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("scripts",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteScript=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("scripts",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getScript=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("scripts",t).then((function(t){n(t)}))}))},t.prototype.getScripts=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("scripts").then((function(n){t.scripts=new Array,t.scripts=n,e(n)}),(function(t){n(t)}))}))},t.prototype.getlocalScript_detail=function(t){for(var e=0;e<this.script_details.length;e++)if(this.script_details[e]._id===t)return this.script_details[e];return null},t.prototype.getlocalScript_details=function(){return this.script_details},t.prototype.refreshLocalScript_details=function(){var t=this;return new Promise((function(e){t.getScript_details().then((function(){e(null)}))}))},t.prototype.addScript_detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("script_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateScript_detail=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("script_details",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteScript_detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("script_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getScript_detail=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("script_details",t).then((function(t){n(t)}))}))},t.prototype.getScript_details=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("script_details").then((function(n){t.script_details=new Array,t.script_details=n,e(n)}),(function(t){n(t)}))}))},t}();J.decorators=[{type:e.Injectable}],J.ctorParameters=function(){return[{type:o.Vhmongo_firebase},{type:V},{type:F},{type:L}]};var H=function(){function t(t,e,n,o){var i=this;this.vhmongo_firebase=t,this.vhQuery=e,this.vhAuth=n,this.vhAlgorithm=o,this.designs=new Array,this.cameras=new Array,this.cloudcams=new Array,this.rooms=new Array,this.mainboards=new Array,this.functions=new Array,this.components=new Array,this.icons=new Array,this.appsettingstations=new Array,this.scripts=new Array,this.script_details=new Array,this.logs=new Array,this.hwinfo={},this.subjectcameras=new c.Subject,this.subjectappsettingstations=new c.Subject,this.subjectrooms=new c.Subject,this.subjectmainboards=new c.Subject,this.subjectfunctions=new c.Subject,this.subjecticons=new c.Subject,this.subjectcomponents=new c.Subject,r.Device.getId().then((function(t){var e=i.vhAuth.localStorageGET("hwinfo");null!=e&&null!=e?i.hwinfo=e:(i.hwinfo=Object.assign({},t),i.vhAuth.localStorageSET("hwinfo",i.hwinfo))}))}return t.prototype.syncCollections=function(){var t=this;return new Promise((function(e,n){t.initSyncCollections(),t.callbackCollectionInsert().subscribe(),t.callbackCollectionUpdate().subscribe(),t.callbackCollectionDelete().subscribe(),t.getUtokenByUser(),setTimeout((function(){e(!0)}),3e3)}))},t.prototype.initSyncCollections=function(){var t=new Array;return t[0]="rooms",t[1]="mainboards",t[2]="components",t[3]="icons",t[4]="functions",t[5]="vhemployees",t[6]="appsettingstations",this.vhmongo_firebase.socketMongoDB().initSyncCollections(t)},t.prototype.closeSyncCollections=function(){this.vhmongo_firebase.socketMongoDB().closeSyncCollections()},t.prototype.callbackCollectionInsert=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackCollectionInsert().subscribe((function(n){if("vhemployees"===n.colname?n.colname="employees":"appsettingstations"===n.colname&&(n.colname="appsettingstations"),"cameras"===n.colname)t.getlocalCamera(n._id)||((o=Object.assign({},n.data))._id=n._id,t.cameras.push(o),t.publishObservableEventCameras(),e.next(n.colname));else if("rooms"===n.colname){if(!t.getlocalRoom(n._id))(o=Object.assign({},n.data))._id=n._id,t.rooms.push(o),t.publishObservableEventRooms(),e.next(n.colname)}else if("mainboards"===n.colname){if(!t.getlocalMainboard(n._id))(o=Object.assign({},n.data))._id=n._id,t.mainboards.push(o),t.publishObservableEventMainboards(),e.next(n.colname)}else if("components"===n.colname){if(!t.getlocalComponent(n._id))(o=Object.assign({},n.data))._id=n._id,t.components.push(o),t.publishObservableEventComponents(),e.next(n.colname)}else if("icons"===n.colname){if(!t.getlocalIcon(n._id))(o=Object.assign({},n.data))._id=n._id,t.icons.push(o),t.publishObservableEventIcons(),e.next(n.colname)}else if("functions"===n.colname){if(!t.getlocalFunction(n._id))(o=Object.assign({},n.data))._id=n._id,t.functions.push(o),t.publishObservableEventFunctions(),e.next(n.colname)}else if("employees"===n.colname){(o=Object.assign({},n.data))._id=n._id,t.vhAuth.insertlocalEmployeeFromSyncCollection(o),t.vhAuth.publishObservableEventEmployees(),e.next(n.colname)}else if("appsettingstations"===n.colname){var o;if(!t.getLocalAppSettingStation(n._id))if(n.data.uuid===t.hwinfo.uuid)(o=Object.assign({},n.data))._id=n._id,delete o.uuid,t.appsettingstations.push(o),t.publishObservableEventAppSettingNameStations(),e.next(n.colname)}console.log("inserted",n.colname)}))}))},t.prototype.callbackCollectionUpdate=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackCollectionUpdate().subscribe((function(n){if("vhemployees"===n.colname?n.colname="employees":"appsettingstations"===n.colname&&(n.colname="appsettingstations"),"cameras"===n.colname){for(var o=0;o<t.cameras.length;o++)if(t.cameras[o]._id===n._id){t.cameras[o]=Object.assign(Object.assign({},t.cameras[o]),n.data),t.publishObservableEventCameras(),e.next(n.colname);break}}else if("rooms"===n.colname){for(o=0;o<t.rooms.length;o++)if(t.rooms[o]._id===n._id){t.rooms[o]=Object.assign(Object.assign({},t.rooms[o]),n.data),t.publishObservableEventRooms(),e.next(n.colname);break}}else if("mainboards"===n.colname){for(o=0;o<t.mainboards.length;o++)if(t.mainboards[o]._id===n._id){t.mainboards[o]=Object.assign(Object.assign({},t.mainboards[o]),n.data),t.publishObservableEventMainboards(),e.next(n.colname);break}}else if("components"===n.colname){for(o=0;o<t.components.length;o++)if(t.rooms[o]._id===n._id){t.rooms[o]=Object.assign(Object.assign({},t.components[o]),n.data),t.publishObservableEventComponents(),e.next(n.colname);break}}else if("icons"===n.colname){for(o=0;o<t.icons.length;o++)if(t.icons[o]._id===n._id){t.icons[o]=Object.assign(Object.assign({},t.icons[o]),n.data),t.publishObservableEventIcons(),e.next(n.colname);break}}else if("functions"===n.colname){for(o=0;o<t.icons.functions;o++)if(t.functions[o]._id===n._id){t.functions[o]=Object.assign(Object.assign({},t.functions[o]),n.data),t.publishObservableEventFunctions(),e.next(n.colname);break}}else if("employees"===n.colname)t.vhAuth.updateLocalEmployeeFromSyncCollection(n._id,n.data),t.vhAuth.publishObservableEventEmployees(),e.next(n.colname);else if("appsettingstations"===n.colname)for(o=0;o<t.appsettingstations.length;o++)if(t.appsettingstations[o]._id===n._id){t.appsettingstations[o]=Object.assign(Object.assign({},t.appsettingstations[o]),n.data),t.publishObservableEventAppSettingNameStations(),e.next(n.colname);break}console.log("updated",n.colname)}))}))},t.prototype.callbackCollectionDelete=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackCollectionDelete().subscribe((function(n){if("vhemployees"===n.colname?n.colname="employees":"appsettingstations"===n.colname&&(n.colname="appsettingstations"),"cameras"===n.colname){for(var o=0;o<t.cameras.length;o++)if(t.cameras[o]._id===n._id){t.cameras.splice(o,1),t.publishObservableEventCameras(),e.next(n.colname);break}}else if("rooms"===n.colname){for(o=0;o<t.rooms.length;o++)if(t.rooms[o]._id===n._id){t.rooms.splice(o,1),t.publishObservableEventRooms(),e.next(n.colname);break}}else if("mainboards"===n.colname){for(o=0;o<t.mainboards.length;o++)if(t.mainboards[o]._id===n._id){t.mainboards.splice(o,1),t.publishObservableEventMainboards(),e.next(n.colname);break}}else if("components"===n.colname){for(o=0;o<t.components.length;o++)if(t.components[o]._id===n._id){t.components.splice(o,1),t.publishObservableEventComponents(),e.next(n.colname);break}}else if("icons"===n.colname){for(o=0;o<t.icons.length;o++)if(t.icons[o]._id===n._id){t.icons.splice(o,1),t.publishObservableEventIcons(),e.next(n.colname);break}}else if("functions"===n.colname){for(o=0;o<t.functions.length;o++)if(t.functions[o]._id===n._id){t.functions.splice(o,1),t.publishObservableEventFunctions(),e.next(n.colname);break}}else if("employees"===n.colname)t.vhAuth.deleteLocalEmployeeFromSyncCollection(n._id),t.vhAuth.publishObservableEventEmployees(),e.next(n.colname);else if("appsettingstations"===n.colname)for(o=0;o<t.appsettingstations.length;o++)if(t.appsettingstations[o]._id===n._id){t.appsettingstations.splice(o,1),t.publishObservableEventAppSettingNameStations(),e.next(n.colname);break}console.log("deleted",n.colname)}))}))},t.prototype.startLocalStorage=function(){var t=this;return new Promise((function(e){var n=new Array;n[0]=t.vhAuth.refreshLocalMyPermission(),n[1]=t.refreshLocalCloudCams(),t.vhQuery.asyncPromiseAll(n).then((function(){e(null)}))}))},t.prototype.createPaymentVnpay=function(t,e,n,o,i,a){var s={projectName:this.vhmongo_firebase.auth().getProjectName(),sid:this.vhmongo_firebase.auth().getDatabase(),data:n};this.vhmongo_firebase.clouds().createPaymentVnpay(t,e,"billpayment","thanh toan","vn",s,o,i,a).then((function(t){window.location=t.data}),(function(t){console.log("error",t)}))},t.prototype.getDiscountFromCode=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.clouds().getDiscountFromCode(t).then((function(t){t.size>0?n(t.docs[0].data().discount):n(0)}),(function(t){console.error(t),o(t)}))}))},t.prototype.getPriceList_Records=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.clouds().getPriceList_Records().then((function(n){var o=new Array;n.size>0&&n.forEach((function(t){o.push(t.data()),o[o.length-1]._id=t.id})),o=t.vhAlgorithm.sortNumberbyASC(o,"month"),e(o)}),(function(t){console.error(t),n(t)}))}))},t.prototype.getPriceList_Detectors=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.clouds().getPriceList_Detectors().then((function(n){var o=new Array;n.size>0&&n.forEach((function(t){o.push(t.data()),o[o.length-1]._id=t.id})),o=t.vhAlgorithm.sortNumberbyASC(o,"month"),e(o)}),(function(t){console.error(t),n(t)}))}))},t.prototype.getPriceList_rLPRs=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.clouds().getPriceList_rLPRs().then((function(n){var o=new Array;n.size>0&&n.forEach((function(t){o.push(t.data()),o[o.length-1]._id=t.id})),o=t.vhAlgorithm.sortNumberbyASC(o,"month"),e(o)}),(function(t){console.error(t),n(t)}))}))},t.prototype.getPriceList_cLPRs=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.clouds().getPriceList_cLPRs().then((function(n){var o=new Array;n.size>0&&n.forEach((function(t){o.push(t.data()),o[o.length-1]._id=t.id})),o=t.vhAlgorithm.sortNumberbyASC(o,"month"),e(o)}),(function(t){console.error(t),n(t)}))}))},t.prototype.publishObservableEventCameras=function(){this.subjectcameras.next(this.cameras)},t.prototype.observableLocalCameras=function(){return this.subjectcameras},t.prototype.getObservableLocalCameras=function(){var t=this;return new c.Observable((function(e){t.observableLocalCameras().subscribe((function(t){e.next(t)})),t.publishObservableEventCameras()}))},t.prototype.getlocalCamera=function(t){for(var e=0;e<this.cameras.length;e++)if(this.cameras[e]._id===t)return this.cameras[e];return null},t.prototype.getlocalCameras=function(){return this.cameras},t.prototype.refreshLocalCameras=function(){var t=this;return new Promise((function(e){t.getCameras().then((function(){e(null)}))}))},t.prototype.createLicenseCam=function(){return new Promise((function(t,e){}))},t.prototype.addCamera=function(t){return new Promise((function(t,e){}))},t.prototype.updateCamera=function(t,e){return new Promise((function(t,e){}))},t.prototype.deleteCamera=function(t){return new Promise((function(t,e){}))},t.prototype.getCamera=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("cameras",t).then((function(t){n(t)}))}))},t.prototype.getCameras=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("cameras").then((function(n){t.cameras=new Array,t.cameras=n,e(n)}),(function(t){n(t)}))}))},t.prototype.getlocalCloudCam=function(t){for(var e=0;e<this.cloudcams.length;e++)if(this.cloudcams[e].licensecam===t)return this.cloudcams[e];return null},t.prototype.getlocalCloudCams=function(){return this.cloudcams},t.prototype.refreshLocalCloudCams=function(){var t=this;return new Promise((function(e){t.getCloudCamsbyUser().then((function(){e(null)}))}))},t.prototype.changeCloudCamEnableCLPRbyUser=function(t,e,n){var o=this;return new Promise((function(i){o.vhmongo_firebase.clouds().changeCloudCamEnableCLPRbyUser(t,e,n).then((function(t){0===t.vcode?i(!0):(console.log(t.message),i(!1))}))}))},t.prototype.changeCloudCamEnableRLPRbyUser=function(t,e,n){var o=this;return new Promise((function(i){o.vhmongo_firebase.clouds().changeCloudCamEnableRLPRbyUser(t,e,n).then((function(t){0===t.vcode?i(!0):(console.log(t.message),i(!1))}))}))},t.prototype.changeCloudCamEnableDetectorByUser=function(t,e,n){var o=this;return new Promise((function(i){o.vhmongo_firebase.clouds().changeCloudCamEnableDetectorByUser(t,e,n).then((function(t){0===t.vcode?i(!0):(console.log(t.message),i(!1))}))}))},t.prototype.changeCloudCamEnableRecordByUser=function(t,e,n){var o=this;return new Promise((function(i){o.vhmongo_firebase.clouds().changeCloudCamEnableRecordByUser(t,e,n).then((function(t){0===t.vcode?i(!0):(console.log(t.message),i(!1))}))}))},t.prototype.changeCloudCamEnableActiveByUser=function(t,e,n){var o=this;return new Promise((function(i){o.vhmongo_firebase.clouds().changeCloudCamEnableActiveByUser(t,e,n).then((function(t){0===t.vcode?i(!0):(console.log(t.message),i(!1))}))}))},t.prototype.changeCloudCamURLbyUser=function(t,e,n){var o=this;return new Promise((function(i){o.vhmongo_firebase.clouds().changeCloudCamURLbyUser(t,e,n).then((function(t){0===t.vcode?i(!0):(console.log(t.message),i(!1))}))}))},t.prototype.addCloudCamByUser=function(t,e,n){var o=this;return new Promise((function(i){o.vhmongo_firebase.clouds().addCloudCamByUser(t,e,n).then((function(t){0===t.vcode?i(t.data):(console.log(t.message),i(null))}))}))},t.prototype.updateCloudCamDataByUser=function(t,e,n){var o=this;return new Promise((function(i){o.vhmongo_firebase.clouds().updateCloudCamDataByUser(t,e,n).then((function(t){0===t.vcode?i(!0):(console.log(t.message),i(!1))}))}))},t.prototype.createEUtokenByUser=function(){var t=this;return new Promise((function(e){t.vhmongo_firebase.clouds().createEUtokenByUser().then((function(t){0===t.vcode?e(t.eutoken):(console.log(t.message),e(!1))}))}))},t.prototype.getUtokenByUser=function(){var t=this;return new Promise((function(e){t.vhmongo_firebase.clouds().getUtokenByUser().then((function(t){0===t.vcode?e(t.utoken):(console.log(t.message),e(!1))}))}))},t.prototype.deleteCloudCamByUser=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.clouds().deleteCloudCamByUser(t).then((function(t){0===t.vcode?n(!0):(console.log(t.message),n(!1))}))}))},t.prototype.getCloudCamByUser=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.clouds().getCloudCamByUser(t).then((function(t){0===t.vcode?n(t.data):(console.log(t.message),n(null))}))}))},t.prototype.getCloudCamsbyUser=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.clouds().getCloudCamsByUser().then((function(n){0===n.vcode?t.cloudcams=n.data:(console.log(n.message),t.cloudcams=new Array),e(t.cloudcams)}),(function(t){n(t)}))}))},t.prototype.getPlaybackListCamByUser=function(t,e,n,o,i){var a=this;return new Promise((function(s,r){a.vhmongo_firebase.clouds().getPlaybackListCamByUser(t,e,n,o,i).then((function(t){0===t.vcode?s(t.data):(console.log(t.message),s([]))}),(function(t){r(t)}))}))},t.prototype.publishObservableEventRooms=function(){this.subjectrooms.next(this.rooms)},t.prototype.observableLocalRooms=function(){return this.subjectrooms},t.prototype.getObservableLocalRooms=function(){var t=this;return new c.Observable((function(e){t.observableLocalRooms().subscribe((function(t){e.next(t)})),t.publishObservableEventRooms()}))},t.prototype.getlocalRoom=function(t){for(var e=0;e<this.rooms.length;e++)if(this.rooms[e]._id===t)return this.rooms[e];return null},t.prototype.getlocalRooms=function(){return this.rooms},t.prototype.refreshLocalRooms=function(){var t=this;return new Promise((function(e){t.getRooms().then((function(){e(null)}))}))},t.prototype.addRoom=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("rooms",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateRoom=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("rooms",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteRoom=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("rooms",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getRoom=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("rooms",t).then((function(t){n(t)}))}))},t.prototype.getRooms=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("rooms").then((function(n){t.rooms=new Array,t.rooms=n,e(n)}),(function(t){n(t)}))}))},t.prototype.getlocalLog=function(t){for(var e=0;e<this.logs.length;e++)if(this.logs[e]._id===t)return this.logs[e];return null},t.prototype.getlocalLogs=function(){return this.logs},t.prototype.refreshLocalLogs=function(){var t=this;return new Promise((function(e){t.getLogs().then((function(){e(null)}))}))},t.prototype.addLog=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("logs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateLog=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("logs",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteLog=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("logs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getLog=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("logs",t).then((function(t){n(t)}))}))},t.prototype.getLogs=function(){var t=this;return new Promise((function(e,n){t.logs=new Array,t.vhmongo_firebase.database().getDocs("logs").then((function(n){t.logs=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventMainboards=function(){this.subjectmainboards.next(this.mainboards)},t.prototype.observableLocalMainboards=function(){return this.subjectmainboards},t.prototype.getObservableLocalMainboards=function(){var t=this;return new c.Observable((function(e){t.observableLocalMainboards().subscribe((function(t){e.next(t)})),t.publishObservableEventMainboards()}))},t.prototype.getlocalMainboard=function(t){for(var e=0;e<this.mainboards.length;e++)if(this.mainboards[e]._id===t)return this.mainboards[e];return null},t.prototype.getlocalMainboards=function(){return this.mainboards},t.prototype.refreshLocalMainboards=function(){var t=this;return new Promise((function(e){t.getMainboards().then((function(){e(null)}))}))},t.prototype.addMainboard=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("mainboards",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateMainboard=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("mainboards",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteMainboard=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("mainboards",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getMainboard=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("mainboards",t).then((function(t){n(t)}))}))},t.prototype.getMainboards=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("mainboards").then((function(n){t.mainboards=new Array,t.mainboards=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventFunctions=function(){this.subjectfunctions.next(this.functions)},t.prototype.observableLocalFunctions=function(){return this.subjectfunctions},t.prototype.getObservableLocalFunctions=function(){var t=this;return new c.Observable((function(e){t.observableLocalFunctions().subscribe((function(t){e.next(t)})),t.publishObservableEventFunctions()}))},t.prototype.getlocalFunction=function(t){for(var e=0;e<this.functions.length;e++)if(this.functions[e]._id===t)return this.functions[e];return null},t.prototype.getlocalFunctions=function(){return this.functions},t.prototype.refreshLocalFunctions=function(){var t=this;return new Promise((function(e){t.getFunctions().then((function(){e(null)}))}))},t.prototype.addFunction=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("functions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateFunction=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("functions",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteFunction=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("functions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getFunction=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("functions",t).then((function(t){n(t)}))}))},t.prototype.getFunctions=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("functions").then((function(n){t.functions=new Array,t.functions=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventComponents=function(){this.subjectcomponents.next(this.components)},t.prototype.observableLocalComponents=function(){return this.subjectcomponents},t.prototype.getObservableLocalComponents=function(){var t=this;return new c.Observable((function(e){t.observableLocalComponents().subscribe((function(t){e.next(t)})),t.publishObservableEventComponents()}))},t.prototype.getlocalComponent=function(t){for(var e=0;e<this.components.length;e++)if(this.components[e]._id===t)return this.components[e];return null},t.prototype.getlocalComponents=function(){return this.components},t.prototype.refreshLocalComponents=function(){var t=this;return new Promise((function(e){t.getComponents().then((function(){e(null)}))}))},t.prototype.addComponent=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("components",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateComponent=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("components",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteComponent=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("components",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getComponent=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("components",t).then((function(t){n(t)}))}))},t.prototype.getComponents=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("components").then((function(n){t.components=new Array,t.components=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventIcons=function(){this.subjecticons.next(this.icons)},t.prototype.observableLocalIcons=function(){return this.subjecticons},t.prototype.getObservableLocalIcons=function(){var t=this;return new c.Observable((function(e){t.observableLocalIcons().subscribe((function(t){e.next(t)})),t.publishObservableEventIcons()}))},t.prototype.getlocalIcon=function(t){for(var e=0;e<this.icons.length;e++)if(this.icons[e]._id===t)return this.icons[e];return null},t.prototype.getlocalIcons=function(){return this.icons},t.prototype.refreshLocalIcons=function(){var t=this;return new Promise((function(e){t.getIcons().then((function(){e(null)}))}))},t.prototype.addIcon=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("icons",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateIcon=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("icons",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteIcon=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("icons",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getIcon=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("icons",t).then((function(t){n(t)}))}))},t.prototype.getIcons=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("icons").then((function(n){t.icons=new Array,t.icons=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventAppSettingNameStations=function(){this.subjectappsettingstations.next()},t.prototype.observableLocalAppSettingNameStations=function(){return this.subjectappsettingstations},t.prototype.getObservableLocalAppSettingNameStations=function(){var t=this;return new c.Observable((function(e){t.observableLocalAppSettingNameStations().subscribe((function(){for(var n=new Array,o=0;o<t.appsettingstations.length;o++)n.push(t.appsettingstations[o].appsetting_name);e.next(n)})),t.publishObservableEventAppSettingNameStations()}))},t.prototype.getLocalAppSettingNameStations=function(){for(var t=new Array,e=0;e<this.appsettingstations.length;e++)t.push(this.appsettingstations[e].appsetting_name);return t},t.prototype.getLocalAppSettingNameStation=function(t){for(var e={},n=0;n<this.appsettingstations.length;n++)if(this.appsettingstations[n].appsetting_name===t){delete(e=Object.assign({},this.appsettingstations[n]))._id,delete e.appsetting_name;break}return e},t.prototype.getLocalAppSettingStation=function(t){for(var e=0;e<this.appsettingstations.length;e++)if(this.appsettingstations[e]._id===t)return this.appsettingstations[e];return null},t.prototype.refreshLocalAppSettingNameStations=function(){return new Promise((function(t,e){t(null)}))},t.prototype.getAppSettingStations=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocsByFields("appsettingstations",{uuid:{$eq:t.hwinfo.uuid}},{},{},0).then((function(n){n.length>0&&(t.appsettingstations=n),e(null)}),(function(t){n(t)}))}))},t.prototype.updateAppSettingNameStation=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().getDocsByFields("appsettingstations",{appsetting_name:{$eq:t},uuid:{$eq:n.hwinfo.uuid}},{},{},0).then((function(a){if(a.length>0)n.vhmongo_firebase.database().updateDoc("appsettingstations",a[0]._id,e).then((function(t){o(t)}),(function(t){i(t)}));else{var s=Object.assign({},e);s.appsetting_name=t,s.uuid=n.hwinfo.uuid,n.vhmongo_firebase.database().addDoc("appsettingstations",s).then((function(){o(!0)}),(function(t){i(t)}))}}))}))},t.prototype.deleteAppSettingNameStation=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("appsettingstations",{appsetting_name:{$eq:t},uuid:{$eq:e.hwinfo.uuid}},{},{},0).then((function(t){t.length>0?e.vhmongo_firebase.database().deleteDoc("appsettingstations",t[0]._id).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}))}))},t.prototype.getlocalScript=function(t){for(var e=0;e<this.scripts.length;e++)if(this.scripts[e]._id===t)return this.scripts[e];return null},t.prototype.getlocalScripts=function(){return this.scripts},t.prototype.refreshLocalScripts=function(){var t=this;return new Promise((function(e){t.getScripts().then((function(){e(null)}))}))},t.prototype.addScript=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("scripts",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateScript=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("scripts",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteScript=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("scripts",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getScript=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("scripts",t).then((function(t){n(t)}))}))},t.prototype.getScripts=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("scripts").then((function(n){t.scripts=new Array,t.scripts=n,e(n)}),(function(t){n(t)}))}))},t.prototype.getlocalScript_detail=function(t){for(var e=0;e<this.script_details.length;e++)if(this.script_details[e]._id===t)return this.script_details[e];return null},t.prototype.getlocalScript_details=function(){return this.script_details},t.prototype.refreshLocalScript_details=function(){var t=this;return new Promise((function(e){t.getScript_details().then((function(){e(null)}))}))},t.prototype.addScript_detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("script_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateScript_detail=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("script_details",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteScript_detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("script_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getScript_detail=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("script_details",t).then((function(t){n(t)}))}))},t.prototype.getScript_details=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("script_details").then((function(n){t.script_details=new Array,t.script_details=n,e(n)}),(function(t){n(t)}))}))},t}();H.decorators=[{type:e.Injectable}],H.ctorParameters=function(){return[{type:o.Vhmongo_firebase},{type:V},{type:F},{type:L}]};var G=function(){function t(t){this.vhmongo_firebase=t,this.productlistshopees=new Array,this.shoplistshopee=new Array,this.lazadapricecomparinglist=new Array,this.tikipricecomparinglist=new Array,this.sendopricecomparinglist=new Array,this.shopeepricecomparinglist=new Array}return t.prototype.getShippingDocumentShopee=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.shopee().getShippingDocumentShopee(t,e,Number(n)).then((function(t){i(t)}),(function(t){a(t)}))}))},t.prototype.getShippingParameterShopee=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.shopee().getShippingParameterShopee(t,e,Number(n)).then((function(t){i(t)}),(function(t){a(t)}))}))},t.prototype.confirmShippingByJSONShopee=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.shopee().confirmShippingByJSONShopee(t,e,Number(n)).then((function(t){i(t)}),(function(t){a(t)}))}))},t.prototype.observableLazadaPriceComparing=function(t){var e=this;return new c.Observable((function(n){e.callbacklazadapricecomparing=e.vhmongo_firebase.socketMongoDB().initSyncLazadaPriceComparing(t).subscribe((function(t){if("added"===t.type){var o=Object.assign({_id:t.doc.id},e.vhmongo_firebase.database().cvtDataFB2MG(t.doc.data()));e.lazadapricecomparinglist.push(o)}else if("modified"===t.type){o=Object.assign({_id:t.doc.id},e.vhmongo_firebase.database().cvtDataFB2MG(t.doc.data()));for(var i=0;i<e.lazadapricecomparinglist.length;i++)if(e.lazadapricecomparinglist[i]._id===o._id){e.lazadapricecomparinglist[i]=Object.assign(Object.assign({},e.lazadapricecomparinglist[i]),o);break}}else if("removed"===t.type)for(o={_id:t.doc.id},i=0;i<e.lazadapricecomparinglist.length;i++)if(e.lazadapricecomparinglist[i]._id===o._id){e.lazadapricecomparinglist.splice(i,1);break}n.next(!0)}))}))},t.prototype.closeLazadaPriceComparing=function(){this.callbacklazadapricecomparing.unsubscribe(),this.vhmongo_firebase.socketMongoDB().closeLazadaPriceComparing()},t.prototype.getLocalLazadaPriceComparing=function(){return JSON.parse(JSON.stringify(this.lazadapricecomparinglist))},t.prototype.restartEcommercePriceComparingMACHINE=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().restartEcommercePriceComparingMACHINE().then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.getAllShops=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("ecommerces",{id_branch:{$eq:t}},{},{},0).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateShop=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().getDoc("ecommerces",t).then((function(a){if(a){var s={};s=null!=a.data?Object.assign(Object.assign({},a.data),e):Object.assign({},e),n.vhmongo_firebase.database().updateDoc("ecommerces",t,{data:s}).then((function(e){for(var i=0;i<n.shoplistshopee.length;i++)if(n.shoplistshopee[i]._id===t){n.shoplistshopee[i].data=s;break}o(e)}),(function(t){i(t)}))}else o(!1)}))}))},t.prototype.signInShopee=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.shopee().signIn(t,e).then((function(t){window.location=t.data,o(!0)}),(function(t){i(t)}))}))},t.prototype.signOutShopee=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.shopee().signOut(t).then((function(i){if(0===i.vcode){for(var a=0;a<e.shoplistshopee.length;a++)if(e.shoplistshopee[a]._id===t){e.shoplistshopee.splice(a,1);break}for(a=0;a<e.productlistshopees.length;a++)if(e.productlistshopees[a]._id===t){e.productlistshopees.splice(a,1);break}n(!0)}else console.log(i.message),o(!1)}),(function(t){o(t)}))}))},t.prototype.refreshLocalProductListShopee=function(t,e){var n=this;return new Promise((function(o,i){""!=e&&null!=e?n.getProductListShopee(t,e).then((function(){o(null)})):n.getProductListShopees(t).then((function(){o(null)}))}))},t.prototype.getlocalShopListShopee=function(){return this.shoplistshopee},t.prototype.getProductListShopee=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.shopee().getShop(t,e).then((function(t){if(console.log("shopshopee",t),0===t.vcode){n.shoplistshopee=E(t.data),n.productlistshopees=E(t.data);for(var e=new Array,a=function(t){e[t]=new Promise((function(e,o){n.vhmongo_firebase.shopee().getProductList(n.productlistshopees[t].access_token,Number(n.productlistshopees[t]._id)).then((function(o){n.productlistshopees[t].productlist=o,e(null)}),(function(t){console.log(t),o(t)}))}))},s=0;s<n.productlistshopees.length;s++)a(s);Promise.all(e).then((function(){console.log("productlistshopees",n.productlistshopees),o(null)}))}else console.log(t.message),i(t.message)}),(function(t){i(t)}))}))},t.prototype.getProductListShopees=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.shopee().getShopList(t).then((function(t){if(0===t.vcode){e.shoplistshopee=E(t.data),e.productlistshopees=E(t.data);for(var i=new Array,a=function(t){i[t]=new Promise((function(n,o){e.vhmongo_firebase.shopee().getProductList(e.productlistshopees[t].access_token,Number(e.productlistshopees[t]._id)).then((function(o){e.productlistshopees[t].productlist=o,n(null)}),(function(t){console.log(t),o(t)}))}))},s=0;s<e.productlistshopees.length;s++)a(s);Promise.all(i).then((function(){console.log("productlistshopees",e.productlistshopees),n(null)}))}else console.log(t.message),o(t.message)}),(function(t){o(t)}))}))},t.prototype.getlocalProductListShopee=function(t){for(var e=0;e<this.productlistshopees.length;e++)if(this.productlistshopees[e]._id===t)return JSON.parse(JSON.stringify(this.productlistshopees[e].productlist));return[]},t.prototype.getProductByItem_idShopee=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.shopee().getProductByItem_id(t,e,Number(n)).then((function(t){if(0===t.vcode){for(var a=0;a<o.productlistshopees.length;a++)if(o.productlistshopees[a]._id===n)for(var s=0;s<o.productlistshopees[a].productlist.length;s++)if(o.productlistshopees[a].productlist[s].item_id===e){o.productlistshopees[a].productlist[s]=Object.assign(Object.assign({},o.productlistshopees[a].productlist[s]),t.data);break}i(t.data)}else console.log(t.message),i(null)}),(function(t){a(t)}))}))},t.prototype.getSalesOrderListShopee=function(t,e,n,o){var i=this;return t=new Date(t),e=new Date(e),new Promise((function(a,s){var r=new Promise((function(a,s){i.vhmongo_firebase.shopee().getOrderList(t.getTime()/1e3,e.getTime()/1e3,n,Number(o)).then((function(t){i.productlistshopees.forEach((function(e){e._id===o&&(e.salesorderdetaillist=t)})),a(t)}),(function(t){s(t)}))})),l=new Promise((function(n,a){var s={create_time:{$gte:new Date(t),$lte:new Date(e)}};i.vhmongo_firebase.database().getDocsByFields(o,s,{},{},0).then((function(t){n(t)}))}));Promise.all([r,l]).then((function(t){t[0].filter((function(e){var n=!0;return t[1].forEach((function(t){e.order_sn.toString()===t._id&&(n=!1)})),n})).forEach((function(t){i.vhmongo_firebase.database().addDocbyID(o.toString(),t.order_sn.toString(),{create_time:new Date(1e3*t.create_time)})}));for(var e=0;e<t[0].length;e++)for(var n=0;n<t[1].length;n++)if(t[0][e].order_sn===t[1][n]._id){var s=Object.assign({},t[1][n]);delete s._id,delete s.create_time,t[0][e]=Object.assign(Object.assign({},t[0][e]),s)}console.log("salesorderdetaillist",t[0]),a(t[0])}))}))},t.prototype.getSalesOrderDetailShopee=function(t,e,n){var o=this;return new Promise((function(i,a){var s=o.vhmongo_firebase.shopee().getOrders(t,e,n),r=o.vhmongo_firebase.database().getDoc(n,t);Promise.all([s,r]).then((function(t){t[0].length>0?(t[1]||o.vhmongo_firebase.database().addDocbyID(n,t[0].order_sn,{create_time:new Date(1e3*t[0].create_time)}),i(t[0][0])):i(null)}))}))},t.prototype.getTrackingNumberShopee=function(t,e,n){var o=this;return new Promise((function(i,a){var s=o.vhmongo_firebase.shopee().getTrackingNumber(t,e,n),r=o.vhmongo_firebase.database().getDoc(n,t);Promise.all([s,r]).then((function(e){e[1]&&o.vhmongo_firebase.database().updateDoc(n,t,{tracking_number:e[0].tracking_number}),i(e[0])}),(function(t){a(t)}))}))},t.prototype.addMergeShopeesProduct_model=function(t,e,n,o,i){var a=this;return new Promise((function(s,r){var l={item_id:e,id_shop:o,model:E(n)};null!=t[i]?void 0===t[i].shopees&&(t[i].shopees=new Array):(t[i]={},t[i].shopees=new Array);for(var c=!1,u=0;u<t[i].shopees.length;u++)if(t[i].shopees[u].item_id===e&&t[i].shopees[u].id_shop===o){var d;null!=t[i].shopees[u].model?t[i].shopees[u].model=E(t[i].shopees[u].model,n):t[i].shopees[u].model=E(n),(d={})[i]=t[i],a.vhmongo_firebase.database().updateDoc("products",t._id,Object.assign({},d)).then((function(){s(!0)}),(function(t){r(t)})),c=!0;break}c||(t[i].shopees.push(l),(d={})[i]=t[i],a.vhmongo_firebase.database().updateDoc("products",t._id,Object.assign({},d)).then((function(){s(!0)}),(function(t){r(t)})))}))},t.prototype.updateMergeShopeesProduct=function(t,e,n,o,i){var a=this;return new Promise((function(s,r){if(void 0===t[i])return s(!1);if(void 0===t[i].shopees)return s(!1);for(var l=!1,c=0;c<t[i].shopees.length;c++)if(t[i].shopees[c].item_id===e&&t[i].shopees[c].id_shop===o){t[i].shopees[c]=Object.assign(Object.assign({},t[i].shopees[c]),n);var u={};u[i]=t[i],a.vhmongo_firebase.database().updateDoc("products",t._id,Object.assign({},u)).then((function(t){s(t)}),(function(t){r(t)})),l=!0;break}l||s(!1)}))},t.prototype.updateMergeShopeesProduct_model=function(t,e,n,o,i,a){var s=this;return new Promise((function(r,l){if(void 0===t[a])return r(!1);if(void 0===t[a].shopees)return r(!1);for(var c=!1,u=0;u<t[a].shopees.length;u++)if(t[a].shopees[u].item_id===e&&t[a].shopees[u].id_shop===i&&null!=t[a].shopees[u].model)for(var d=0;d<t[a].shopees[u].model.length;d++)if(t[a].shopees[u].model[d].model_id===n){t[a].shopees[u].model[d]=Object.assign(Object.assign({},t[a].shopees[u].model[d]),o);var _={};_[a]=t[a],s.vhmongo_firebase.database().updateDoc("products",t._id,Object.assign({},_)).then((function(t){r(t)}),(function(t){l(t)})),c=!0;break}c||r(!1)}))},t.prototype.deleteMergeShopeeProduct_model=function(t,e,n,o,i){var a=this;return new Promise((function(s,r){if(void 0===t[i])return s(!1);if(void 0===t[i].shopees)return s(!1);for(var l=!1,c=0;c<t[i].shopees.length;c++)if(t[i].shopees[c].item_id===e&&t[i].shopees[c].id_shop===o&&null!=t[i].shopees[c].model){for(var u=0;u<t[i].shopees[c].model.length;u++)if(t[i].shopees[c].model[u].model_id===n){t[i].shopees[c].model.splice(u,1),(d={})[i]=t[i],a.vhmongo_firebase.database().updateDoc("products",t._id,Object.assign({},d)).then((function(t){s(t)}),(function(t){r(t)})),l=!0;break}var d;if(0===t[i].shopees[c].model.length)t[i].shopees.splice(c,1),(d={})[i]=t[i],a.vhmongo_firebase.database().updateDoc("products",t._id,Object.assign({},d)).then((function(t){s(t)}),(function(t){r(t)})),l=!0}l||s(!1)}))},t.prototype.updateProductInfoByJSONshopee=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.shopee().updateProductInfoByJSONshopee(t,e,Number(n)).then((function(t){0===t.vcode?i(t.data):(console.log(t.message),i(null))}),(function(t){a(t)}))}))},t.prototype.updateProductStockByJSONshopee=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.shopee().updateProductStockByJSONshopee(t,e,Number(n)).then((function(t){0===t.vcode?i(t.data):(console.log(t.message),i(null))}),(function(t){a(t)}))}))},t.prototype.updateProductPriceByJSONshopee=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.shopee().updateProductPriceByJSONshopee(t,e,Number(n)).then((function(t){0===t.vcode?i(t.data):(console.log(t.message),i(null))}),(function(t){a(t)}))}))},t.prototype.getSalesOrderShopee_fromViethas=function(t,e){var n=this;return new Promise((function(o,i){for(var a=new Array,s=0;s<t.length;s++)a[s]=n.vhmongo_firebase.database().getDoc(e,t[s]);Promise.all(a).then((function(t){o(t)}))}))},t.prototype.updateSalesOrderShopee=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.database().updateDoc(t,e,n).then((function(a){a&&o.productlistshopees.forEach((function(o){o._id===t&&o.salesorderdetaillist.forEach((function(t){t.order_sn===e&&(t=Object.assign(Object.assign({},t),n))}))})),i(a)}),(function(t){a(t)}))}))},t.prototype.updateSalesOrderShopee_byFile=function(t,e,n,o){var i=this;return new Promise((function(a,s){for(var r=new Array,l=function(a){r[a]=new Promise((function(s){i.vhmongo_firebase.shopee().getOrders(t[a],n,Number(o)).then((function(n){n?i.vhmongo_firebase.database().getDoc(o,t[a]).then((function(n){n?i.vhmongo_firebase.database().updateDoc(o,t[a],e).then((function(t){s(t)}),(function(){s(!1)})):i.vhmongo_firebase.database().addDocbyID(o,t[a],e).then((function(){s(!0)}))})):s(!1)}),(function(){s(!1)}))}))},c=0;c<t.length;c++)l(c);Promise.all(r).then((function(t){a(t)}))}))},t}();G.decorators=[{type:e.Injectable}],G.ctorParameters=function(){return[{type:o.Vhmongo_firebase}]};var Y=function(){function t(t,e,n,o,i,a){var s=this;this.vhmongo_firebase=t,this.vhQuery=e,this.vhAuth=n,this.vhAlgorithm=o,this.iap2=i,this.platform=a,this.restriction_main_package=null,this.restriction_ecommerce_package=null,this.restriction_facebook_package=null,this.restriction_warranty_package=null,this.productlistsendo=new Array,this.shoplistsendo=new Array,this.productlistlazada=new Array,this.shoplistlazada=new Array,this.productlisttikis=new Array,this.shoplisttiki=new Array,this.products=new Array,this.customers=new Array,this.suppliers=new Array,this.wallets=new Array,this.taxs=new Array,this.categorys=new Array,this.inventorytimes=new Array,this.warrantys=new Array,this.discount_bills=new Array,this.discount_saless=new Array,this.customer_classs=new Array,this.commissions=new Array,this.deliverys=new Array,this.addresss=new Array,this.incoming_groups=new Array,this.spending_groups=new Array,this.branchs=new Array,this.promotions=new Array,this.printers=new Array,this.hwinfo={},this.appsettingstations=new Array,this.appsettingbranchs=new Array,this.subjectwallets=new c.Subject,this.subjectappsettingstations=new c.Subject,this.subjectappsettingbranchs=new c.Subject,this.subjectbranchs=new c.Subject,this.subjectcategorys=new c.Subject,this.subjectcustomers=new c.Subject,this.subjectinventorytimes=new c.Subject,this.subjectprinters=new c.Subject,this.subjectproducts=new c.Subject,this.subjectpromotions=new c.Subject,this.subjectsuppliers=new c.Subject,this.subjecttaxs=new c.Subject,this.subjectwarrantys=new c.Subject,this.subjectdiscount_bills=new c.Subject,this.subjectcustomer_classs=new c.Subject,this.sync_code=Math.random().toString(36).substr(2,10).toUpperCase(),r.Device.getId().then((function(t){var e=s.vhAuth.localStorageGET("hwinfo");null!=e&&null!=e?s.hwinfo=e:(s.hwinfo=Object.assign({},t),s.vhAuth.localStorageSET("hwinfo",s.hwinfo))}))}return t.prototype.getSales_Management_Scope=function(){if(null!=this.vhAuth.getStore().sales_management_scope){var t=Object.assign({},this.vhAuth.getStore().sales_management_scope);return void 0===t.product_scope&&(t.product_scope=1),void 0===t.employee_scope&&(t.employee_scope=1),void 0===t.customer_scope&&(t.customer_scope=1),void 0===t.supplier_scope&&(t.supplier_scope=1),void 0===t.sales_program_scope&&(t.sales_program_scope=1),t}return{product_scope:1,employee_scope:1,customer_scope:1,supplier_scope:1,sales_program_scope:1}},t.prototype.updateSales_Management_Scope=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().updateDoc_onRootCollectionsFirebase("stores",e.vhmongo_firebase.auth().getDatabase(),{sales_management_scope:t}).then((function(){e.vhmongo_firebase.auth().setStore({sales_management_scope:t}),n(void 0)}),(function(t){o(t)}))}))},t.prototype.refreshLocalRestrictionMainPackage=function(){var t=this;return new Promise((function(e,n){var o=t.getDefaultBranch()._id,i=t.vhAuth.getStore()[o].main_package_expire.id_restriction;t.vhmongo_firebase.rootdatabase().getDoc("restrictions",i).then((function(n){n&&(t.restriction_main_package=Object.assign(Object.assign({},n),t.vhAuth.getStore()[o].main_package_expire),delete t.restriction_main_package.id_restriction,delete t.restriction_main_package._id,console.log("restriction_main_package",t.restriction_main_package)),e(null)}),(function(t){n(t)}))}))},t.prototype.getLocalRestrictionMainPackage=function(){return this.restriction_main_package},t.prototype.refreshLocalRestrictionEcommercePackage=function(){var t=this;return new Promise((function(e,n){var o=t.getDefaultBranch()._id,i=t.vhAuth.getStore()[o].ecommerce_package_expire.id_restriction;t.vhmongo_firebase.rootdatabase().getDoc("restrictions",i).then((function(n){n&&(t.restriction_ecommerce_package=Object.assign(Object.assign({},n),t.vhAuth.getStore()[o].ecommerce_package_expire),delete t.restriction_ecommerce_package.id_restriction,delete t.restriction_ecommerce_package._id,console.log("restriction_ecommerce_package",t.restriction_ecommerce_package)),e(null)}),(function(t){n(t)}))}))},t.prototype.getLocalRestrictionEcommercePackage=function(){return this.restriction_ecommerce_package},t.prototype.refreshLocalRestrictionFacebookPackage=function(){var t=this;return new Promise((function(e,n){var o=t.getDefaultBranch()._id,i=t.vhAuth.getStore()[o].facebook_package_expire.id_restriction;t.vhmongo_firebase.rootdatabase().getDoc("restrictions",i).then((function(n){n&&(t.restriction_facebook_package=Object.assign(Object.assign({},n),t.vhAuth.getStore()[o].facebook_package_expire),delete t.restriction_facebook_package.id_restriction,delete t.restriction_facebook_package._id,console.log("restriction_facebook_package",t.restriction_facebook_package)),e(null)}),(function(t){n(t)}))}))},t.prototype.getLocalRestrictionFacebookPackage=function(){return this.restriction_facebook_package},t.prototype.refreshLocalRestrictionWarrantyPackage=function(){var t=this;return new Promise((function(e,n){var o=t.getDefaultBranch()._id,i=t.vhAuth.getStore()[o].warranty_package_expire.id_restriction;t.vhmongo_firebase.rootdatabase().getDoc("restrictions",i).then((function(n){n&&(t.restriction_warranty_package=Object.assign(Object.assign({},n),t.vhAuth.getStore()[o].warranty_package_expire),delete t.restriction_warranty_package.id_restriction,delete t.restriction_warranty_package._id,console.log("restriction_warranty_package",t.restriction_warranty_package)),e(null)}),(function(t){n(t)}))}))},t.prototype.getLocalRestrictionWarrantyPackage=function(){return this.restriction_warranty_package},t.prototype.observableWebhookFeedFacebook=function(t){var e=this;return new c.Observable((function(n){e.vhmongo_firebase.socketFacebook().observableWebhookFeed(t).subscribe((function(t){n.next(t)}))}))},t.prototype.unsubscribeWebhookFeedFacebook=function(t){this.vhmongo_firebase.socketFacebook().unsubscribeWebhookFeed(t)},t.prototype.observableWebhookMessagesFacebook=function(t){var e=this;return new c.Observable((function(n){e.vhmongo_firebase.socketFacebook().observableWebhookMessages(t).subscribe((function(t){n.next(t)}))}))},t.prototype.unsubscribeWebhookMessagesFacebook=function(t){this.vhmongo_firebase.socketFacebook().unsubscribeWebhookMessages(t)},t.prototype.GetShippingStampForDropshipTiki=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.tiki().GetShippingStampForDropshipTiki(t,e,n).then((function(t){i(t)}),(function(t){a(t)}))}))},t.prototype.getSellerInventoriesForConfirmationTiki=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.tiki().getSellerInventoriesForConfirmationTiki(t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getExpectedPickupTimesTiki=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.tiki().getExpectedPickupTimesTiki(t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.ConfirmEnoughStockForDropShippingByJSONTiki=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.tiki().ConfirmEnoughStockForDropShippingByJSONTiki(t,e,n).then((function(t){i(t)}),(function(t){a(t)}))}))},t.prototype.getSalesOrderTiki_fromViethas=function(t,e){var n=this;return new Promise((function(o,i){for(var a=new Array,s=0;s<t.length;s++)a[s]=n.vhmongo_firebase.database().getDoc(e,t[s]);Promise.all(a).then((function(t){o(t)}))}))},t.prototype.updateSalesOrderTiki=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.database().updateDoc(t,e,n).then((function(a){a&&o.productlistlazada.forEach((function(o){o._id===t&&o.salesorderdetaillist.forEach((function(t){t.code===e&&(t=Object.assign(Object.assign({},t),n))}))})),i(a)}),(function(t){a(t)}))}))},t.prototype.updateSalesOrderTiki_byFile=function(t,e,n,o){var i=this;return new Promise((function(a,s){for(var r=new Array,l=function(a){r[a]=new Promise((function(s){i.vhmongo_firebase.tiki().getOrders(t[a],n).then((function(n){n?i.vhmongo_firebase.database().getDoc(o,t[a]).then((function(n){n?i.vhmongo_firebase.database().updateDoc(o,t[a],e).then((function(t){s(t)}),(function(){s(!1)})):i.vhmongo_firebase.database().addDocbyID(o,t[a],e).then((function(){s(!0)}))})):s(!1)}),(function(){s(!1)}))}))},c=0;c<t.length;c++)l(c);Promise.all(r).then((function(t){a(t)}))}))},t.prototype.updateProductByJSONTiki=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.tiki().updateProductByJSON(t,e).then((function(t){0===t.vcode?o(t.data):(console.log(t.message),o(null))}),(function(t){i(t)}))}))},t.prototype.updateProductsByJSONTiki=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.tiki().updateProductsByJSON(t,e).then((function(t){0===t.vcode?o(t.data):(console.log(t.message),o(null))}),(function(t){i(t)}))}))},t.prototype.getSalesOrderListTiki=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Promise((function(a,s){i.vhmongo_firebase.tiki().getOrderList(B(new Date(t),"YYYY-MM-dd HH:mm:ss"),B(new Date(e),"YYYY-MM-dd HH:mm:ss"),n).then((function(t){i.productlisttikis.forEach((function(e){e._id===o&&(e.salesorderdetaillist=t)})),a(t)}),(function(t){s(t)}))})),l=new Promise((function(n,a){var s={created_at:{$gte:new Date(t),$lte:new Date(e)}};i.vhmongo_firebase.database().getDocsByFields(o,s,{},{},0).then((function(t){n(t)}))}));Promise.all([r,l]).then((function(t){t[0].filter((function(e){var n=!0;return t[1].forEach((function(t){e.code.toString()===t._id&&(n=!1)})),n})).forEach((function(t){i.vhmongo_firebase.database().addDocbyID(o.toString(),t.code.toString(),{created_at:new Date(t.created_at)})}));for(var e=0;e<t[0].length;e++)for(var n=0;n<t[1].length;n++)if(t[0][e].code===t[1][n]._id){var s=Object.assign({},t[1][n]);delete s._id,delete s.created_at,t[0][e]=Object.assign(Object.assign({},t[0][e]),s)}a(t[0])}))}))},t.prototype.getSalesOrderDetailTiki=function(t,e,n){var o=this;return new Promise((function(i,a){var s=o.vhmongo_firebase.tiki().getOrders(t,e),r=o.vhmongo_firebase.database().getDoc(n,t);Promise.all([s,r]).then((function(t){t[0].length>0?(t[1]||o.vhmongo_firebase.database().addDocbyID(n,t[0].code,{created_at:new Date(t[0].created_at)}),i(t[0][0])):i(null)}))}))},t.prototype.getlocalProductListTiki=function(t){for(var e=0;e<this.productlisttikis.length;e++)if(this.productlisttikis[e]._id===t)return JSON.parse(JSON.stringify(this.productlisttikis[e].productlist));return[]},t.prototype.refreshLocalProductListTikis=function(t){var e=this;return new Promise((function(n,o){""!=t&&null!=t?e.getProductListTiki(t).then((function(){n(null)})):e.getProductListTikis().then((function(){n(null)}))}))},t.prototype.getProductListTiki=function(t){var e=this;return new Promise((function(n,o){var i=e.getDefaultBranch()._id;e.vhmongo_firebase.tiki().getShop(i,t).then((function(t){if(console.log("shoptiki",t),0===t.vcode){e.shoplisttiki=E(t.data),e.productlisttikis=E(t.data);for(var i=new Array,a=function(t){i[t]=new Promise((function(n,o){for(var i=new Array,a=function(n){i[n]=new Promise((function(o,i){var a=n+1;e.vhmongo_firebase.tiki().getProductPage(e.productlisttikis[t].access_token,a).then((function(t){0===t.vcode?o(t.data):(console.log(t.message),i(t.message))}),(function(t){i(t)}))}))},s=0;s<e.productlisttikis[t].product_page_total;s++)a(s);Promise.all(i).then((function(o){e.productlisttikis[t].productlist=o.flat(),n(null)}))}))},s=0;s<e.productlisttikis.length;s++)a(s);Promise.all(i).then((function(){console.log("productlisttikis",e.productlisttikis),n(null)}))}else console.log(t.message),o(t.message)}),(function(t){o(t)}))}))},t.prototype.getProductListTikis=function(){var t=this;return new Promise((function(e,n){var o=t.getDefaultBranch()._id;t.vhmongo_firebase.tiki().getShopList(o).then((function(o){if(0===o.vcode){t.shoplisttiki=E(o.data),t.productlisttikis=E(o.data);for(var i=new Array,a=function(e){i[e]=new Promise((function(n,o){for(var i=new Array,a=function(n){i[n]=new Promise((function(o,i){var a=n+1;t.vhmongo_firebase.tiki().getProductPage(t.productlisttikis[e].access_token,a).then((function(t){0===t.vcode?o(t.data):(console.log(t.message),i(t.message))}),(function(t){i(t)}))}))},s=0;s<t.productlisttikis[e].product_page_total;s++)a(s);Promise.all(i).then((function(o){t.productlisttikis[e].productlist=o.flat(),n(null)}))}))},s=0;s<t.productlisttikis.length;s++)a(s);Promise.all(i).then((function(){console.log("productlisttikis",t.productlisttikis),e(null)}))}else console.log(o.message),n(o.message)}),(function(t){n(t)}))}))},t.prototype.getProductByIdTiki=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.tiki().getProductByIdTiki(t,e).then((function(t){if(0===t.vcode){for(var a=0;a<o.productlisttikis.length;a++)if(o.productlisttikis[a]._id===n)for(var s=0;s<o.productlisttikis[a].productlist.length;s++)if(o.productlisttikis[a].productlist[s].product_id===e){o.productlisttikis[a].productlist[s]=Object.assign(Object.assign({},o.productlisttikis[a].productlist[s]),t.data);break}i(t.data)}else console.log(t.message),i(null)}),(function(t){a(t)}))}))},t.prototype.getHiddenProductListTiki=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.tiki().getHiddenProductList(t).then((function(t){0===t.vcode?n(t.data):(console.log(t.message),n([]))}),(function(t){o(t)}))}))},t.prototype.getlocalShopListTiki=function(){return this.shoplisttiki},t.prototype.getShopListTiki=function(){var t=this;return new Promise((function(e,n){var o=t.getDefaultBranch()._id;t.vhmongo_firebase.tiki().getShopList(o).then((function(o){0===o.vcode?(t.shoplisttiki=o.data,e(o.data)):(console.log(o.message),n(o.message))}),(function(t){n(t)}))}))},t.prototype.signInTiki=function(t){var e=this;return new Promise((function(n,o){var i=e.getDefaultBranch()._id;e.vhmongo_firebase.tiki().signIn(i,t).then((function(t){window.location=t.data,n(!0)}),(function(t){o(t)}))}))},t.prototype.signOutTiki=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.tiki().signOut(t).then((function(i){if(0===i.vcode){for(var a=0;a<e.shoplisttiki.length;a++)if(e.shoplisttiki[a]._id===t){e.shoplisttiki.splice(a,1);break}for(a=0;a<e.productlisttikis.length;a++)if(e.productlisttikis[a]._id===t){e.productlisttikis.splice(a,1);break}n(!0)}else console.log(i.message),o(!1)}),(function(t){o(t)}))}))},t.prototype.addMergeTikiProduct=function(t,e,n){var o=this;return new Promise((function(i,a){var s=o.getDefaultBranch()._id,r=o.getlocalProduct(t);null!=r[s]?void 0===r[s].tikis&&(r[s].tikis=new Array):(r[s]={},r[s].tikis=new Array);for(var l=new Array,c=0;c<e.length;c++){for(var u={product_id:e[c],id_shop:n},d=!1,_=0;_<r[s].tikis.length;_++)if(r[s].tikis[_].product_id===e[c]&&r[s].tikis[_].id_shop===n){d=!0;break}d||l.push(u)}if(l.length>0){r[s].tikis=E(r[s].tikis,l);var p={};p[s]=r[s],o.vhmongo_firebase.database().updateDoc("products",t,Object.assign({},p)).then((function(){i(!0)}),(function(t){a(t)}))}else i(!1)}))},t.prototype.updateMergeTikiProduct=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=i.getlocalProduct(t),l=i.getDefaultBranch()._id;if(void 0===r[l])return a(!1);if(void 0===r[l].tikis)return a(!1);for(var c=!1,u=0;u<r[l].tikis.length;u++)if(r[l].tikis[u].product_id===e&&r[l].tikis[u].id_shop===o){r[l].tikis[u]=Object.assign(Object.assign({},r[l].tikis[u]),n);var d={};d[l]=r[l],i.vhmongo_firebase.database().updateDoc("products",t,Object.assign({},d)).then((function(t){a(t)}),(function(t){s(t)})),c=!0;break}c||a(!1)}))},t.prototype.updateMergeTikiProduct_hidden=function(t,e,n){var o=this;return new Promise((function(i,a){for(var s=o.getDefaultBranch()._id,r=o.getlocalProducts(),l=null,c=0;c<r.length;c++)if(null!=r[c][s]&&null!=r[c][s].tikis)for(var u=0;u<r[c][s].tikis.length;u++)if(r[c][s].tikis[u].product_id===t&&r[c][s].tikis[u].id_shop===n){l=r[c];break}if(!l)return i(!1);if(void 0===l[s])return i(!1);if(void 0===l[s].tikis)return i(!1);var d=!1;for(c=0;c<l[s].tikis.length;c++)if(l[s].tikis[c].product_id===t&&l[s].tikis[c].id_shop===n){for(var _=0;_<o.productlisttikis.length;_++)if(o.productlisttikis[_]._id===n)for(var p=0;p<o.productlisttikis[_].productlist.length;p++)if(o.productlisttikis[_].productlist[p].product_id===t){o.productlisttikis[_].productlist[p].hidden=e;break}l[s].tikis[c].hidden=e;var b={};b[s]=l[s],o.vhmongo_firebase.database().updateDoc("products",l._id,Object.assign({},b)).then((function(t){i(t)}),(function(t){a(t)})),d=!0;break}d||i(!1)}))},t.prototype.deleteMergeTikiProduct=function(t,e,n){var o=this;return new Promise((function(i,a){var s=o.getlocalProduct(t),r=o.getDefaultBranch()._id;if(void 0===s[r])return i(!1);if(void 0===s[r].tikis)return i(!1);for(var l=!1,c=0;c<s[r].tikis.length;c++)if(s[r].tikis[c].product_id===e&&s[r].tikis[c].id_shop===n){s[r].tikis.splice(c,1);var u={};u[r]=s[r],o.vhmongo_firebase.database().updateDoc("products",s._id,Object.assign({},u)).then((function(t){i(t)}),(function(t){a(t)})),l=!0;break}l||i(!1)}))},t.prototype.updateProductByXMLLazada=function(t,e){var n=this;return new Promise((function(o,i){var a=t;n.vhmongo_firebase.lazada().updateProductByXMLLazada(a,e).then((function(t){0===t.vcode?o(t.data):(console.log(t.message),o(!1))}),(function(t){i(t)}))}))},t.prototype.setStatusPackedLazada=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.lazada().setStatusPackedLazada(t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.setStatusReadyToShipLazada=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.lazada().setStatusReadyToShipLazada(t,e,n).then((function(t){i(t)}),(function(t){a(t)}))}))},t.prototype.getlocalProductListLazada=function(t){for(var e=0;e<this.productlistlazada.length;e++)if(this.productlistlazada[e]._id===t)return JSON.parse(JSON.stringify(this.productlistlazada[e].productlist));return[]},t.prototype.refreshLocalProductListLazadas=function(t){var e=this;return new Promise((function(n,o){""!=t&&null!=t?e.getProductListLazada(t).then((function(){n(null)})):e.getProductListLazadas().then((function(){n(null)}))}))},t.prototype.getProductListLazada=function(t){var e=this;return new Promise((function(n,o){var i=e.getDefaultBranch()._id;e.vhmongo_firebase.lazada().getShop(i,t).then((function(t){if(console.log("shoplazada",t),0===t.vcode){e.shoplistlazada=E(t.data),e.productlistlazada=E(t.data);for(var i=new Array,a=function(t){i[t]=new Promise((function(n,o){e.vhmongo_firebase.lazada().getProducts(e.productlistlazada[t].access_token).then((function(o){e.productlistlazada[t].productlist=o,n(null)}),(function(t){o(t)}))}))},s=0;s<e.productlistlazada.length;s++)a(s);Promise.all(i).then((function(){console.log("productlistlazadas",e.productlistlazada),n(null)}))}else console.log(t.message),o(t.message)}),(function(t){o(t)}))}))},t.prototype.getProductListLazadas=function(){var t=this;return new Promise((function(e,n){var o=t.getDefaultBranch()._id;t.vhmongo_firebase.lazada().getShopList(o).then((function(o){if(0===o.vcode){t.shoplistlazada=E(o.data),t.productlistlazada=E(o.data);for(var i=new Array,a=function(e){i[e]=new Promise((function(n,o){t.vhmongo_firebase.lazada().getProducts(t.productlistlazada[e].access_token).then((function(o){t.productlistlazada[e].productlist=o,n(null)}),(function(t){o(t)}))}))},s=0;s<t.productlistlazada.length;s++)a(s);Promise.all(i).then((function(){console.log("productlistlazadas",t.productlistlazada),e(null)}))}else console.log(o.message),n(o.message)}),(function(t){n(t)}))}))},t.prototype.getProductDetailLazada=function(t,e,n){var o=this;return new Promise((function(i,a){for(var s=[],r=0;r<t.length;r++)s[r]=o.vhmongo_firebase.lazada().getProductItem(t[r],e);Promise.all(s).then((function(t){for(var e=0;e<o.productlistlazada.length;e++)if(o.productlistlazada[e]._id===n)for(var a=0;a<t.length;a++)for(var s=0;s<o.productlistlazada[e].productlist.length;s++)if(t[a].item_id===o.productlistlazada[e].productlist[s].item_id){o.productlistlazada[e].productlist[s]=Object.assign(Object.assign({},o.productlistlazada[e].productlist[s]),t[a]);break}i(t)}))}))},t.prototype.getlocalShopListLazada=function(){return this.shoplistlazada},t.prototype.getShopListLazada=function(){var t=this;return new Promise((function(e,n){var o=t.getDefaultBranch()._id;t.vhmongo_firebase.lazada().getShopList(o).then((function(o){0===o.vcode?(t.shoplistlazada=o.data,e(o.data)):(console.log(o.message),n(o.message))}),(function(t){n(t)}))}))},t.prototype.signInLazada=function(t){var e=this;return new Promise((function(n,o){var i=e.getDefaultBranch()._id;e.vhmongo_firebase.lazada().signIn(i,t).then((function(t){window.location=t.data,n(!0)}),(function(t){o(t)}))}))},t.prototype.signOutLazada=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.lazada().signOut(t).then((function(i){if(0===i.vcode){for(var a=0;a<e.shoplistlazada.length;a++)if(e.shoplistlazada[a]._id===t){e.shoplistlazada.splice(a,1);break}for(a=0;a<e.productlistlazada.length;a++)if(e.productlistlazada[a]._id===t){e.productlistlazada.splice(a,1);break}n(!0)}else console.log(i.message),o(!1)}),(function(t){o(t)}))}))},t.prototype.addMergeLazadasProduct_skus=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=i.getDefaultBranch()._id,l=i.getlocalProduct(t),c={item_id:e,id_shop:o,skus:E(n)};null!=l[r]?void 0===l[r].lazadas&&(l[r].lazadas=new Array):(l[r]={},l[r].lazadas=new Array);for(var u=!1,d=0;d<l[r].lazadas.length;d++)if(l[r].lazadas[d].item_id===e&&l[r].lazadas[d].id_shop===o){var _;null!=l[r].lazadas[d].skus?l[r].lazadas[d].skus=E(l[r].lazadas[d].skus,n):l[r].lazadas[d].skus=E(n),(_={})[r]=l[r],i.vhmongo_firebase.database().updateDoc("products",t,Object.assign({},_)).then((function(){a(!0)}),(function(t){s(t)})),u=!0;break}u||(l[r].lazadas.push(c),(_={})[r]=l[r],i.vhmongo_firebase.database().updateDoc("products",t,Object.assign({},_)).then((function(){a(!0)}),(function(t){s(t)})))}))},t.prototype.updateMergeLazadasProduct=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=i.getlocalProduct(t),l=i.getDefaultBranch()._id;if(void 0===r[l])return a(!1);if(void 0===r[l].lazadas)return a(!1);for(var c=!1,u=0;u<r[l].lazadas.length;u++)if(r[l].lazadas[u].item_id===e&&r[l].lazadas[u].id_shop===o){r[l].lazadas[u]=Object.assign(Object.assign({},r[l].lazadas[u]),n);var d={};d[l]=r[l],i.vhmongo_firebase.database().updateDoc("products",t,Object.assign({},d)).then((function(t){a(t)}),(function(t){s(t)})),c=!0;break}c||a(!1)}))},t.prototype.updateMergeLazadasProduct_hidden=function(t,e,n){var o=this;return new Promise((function(i,a){for(var s=o.getDefaultBranch()._id,r=o.getlocalProducts(),l=null,c=0;c<r.length;c++)if(null!=r[c][s]&&null!=r[c][s].lazadas)for(var u=0;u<r[c][s].lazadas.length;u++)if(r[c][s].lazadas[u].item_id===t&&r[c][s].lazadas[u].id_shop===n){l=r[c];break}if(!l)return i(!1);if(void 0===l[s])return i(!1);if(void 0===l[s].lazadas)return i(!1);var d=!1;for(c=0;c<l[s].lazadas.length;c++)if(l[s].lazadas[c].item_id===t&&l[s].lazadas[c].id_shop===n){for(var _=0;_<o.productlistlazada.length;_++)if(o.productlistlazada[_]._id===n)for(var p=0;p<o.productlistlazada[_].productlist.length;p++)if(o.productlistlazada[_].productlist[p].item_id===t){o.productlistlazada[_].productlist[p].hidden=e;break}l[s].lazadas[c].hidden=e;var b={};b[s]=l[s],o.vhmongo_firebase.database().updateDoc("products",l._id,Object.assign({},b)).then((function(t){i(t)}),(function(t){a(t)})),d=!0;break}d||i(!1)}))},t.prototype.updateMergeLazadasProduct_skus=function(t,e,n,o,i){var a=this;return new Promise((function(s,r){var l=a.getlocalProduct(t),c=a.getDefaultBranch()._id;if(void 0===l[c])return s(!1);if(void 0===l[c].lazadas)return s(!1);for(var u=!1,d=0;d<l[c].lazadas.length;d++)if(l[c].lazadas[d].item_id===e&&l[c].lazadas[d].id_shop===i&&null!=l[c].lazadas[d].skus)for(var _=0;_<l[c].lazadas[d].skus.length;_++)if(l[c].lazadas[d].skus[_].SkuId===n){l[c].lazadas[d].skus[_]=Object.assign(Object.assign({},l[c].lazadas[d].skus[_]),o);var p={};p[c]=l[c],a.vhmongo_firebase.database().updateDoc("products",t,Object.assign({},p)).then((function(t){s(t)}),(function(t){r(t)})),u=!0;break}u||s(!1)}))},t.prototype.deleteMergeLazadaProduct_skus=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=i.getlocalProduct(t),l=i.getDefaultBranch()._id;if(void 0===r[l])return a(!1);if(void 0===r[l].lazadas)return a(!1);for(var c=!1,u=0;u<r[l].lazadas.length;u++)if(r[l].lazadas[u].item_id===e&&r[l].lazadas[u].id_shop===o&&null!=r[l].lazadas[u].skus){for(var d=0;d<r[l].lazadas[u].skus.length;d++)if(r[l].lazadas[u].skus[d].SkuId===n){r[l].lazadas[u].skus.splice(d,1),(_={})[l]=r[l],i.vhmongo_firebase.database().updateDoc("products",r._id,Object.assign({},_)).then((function(t){a(t)}),(function(t){s(t)})),c=!0;break}var _;if(0===r[l].lazadas[u].skus.length)r[l].lazadas.splice(u,1),(_={})[l]=r[l],i.vhmongo_firebase.database().updateDoc("products",r._id,Object.assign({},_)).then((function(t){a(t)}),(function(t){s(t)})),c=!0}c||a(!1)}))},t.prototype.getSalesOrderListLazada=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Promise((function(a,s){i.vhmongo_firebase.lazada().getOrders(t,e,n).then((function(t){i.productlistlazada.forEach((function(e){e._id===o&&(e.salesorderdetaillist=t)})),a(t)}),(function(t){s(t)}))})),l=new Promise((function(n,a){var s={created_at:{$gte:new Date(t),$lte:new Date(e)}};i.vhmongo_firebase.database().getDocsByFields(o,s,{},{},0).then((function(t){n(t)}))}));Promise.all([r,l]).then((function(t){t[0].filter((function(e){var n=!0;return t[1].forEach((function(t){e.order_id.toString()===t._id&&(n=!1)})),n})).forEach((function(t){i.vhmongo_firebase.database().addDocbyID(o.toString(),t.order_id.toString(),{created_at:new Date(t.created_at)})}));for(var e=0;e<t[0].length;e++)for(var n=0;n<t[1].length;n++)if(t[0][e].order_id===t[1][n]._id){var s=Object.assign({},t[1][n]);delete s._id,t[0][e]=Object.assign(Object.assign({},t[0][e]),s)}console.log("salesorderdetaillist",t[0]),a(t[0])}))}))},t.prototype.getSalesOrderDetailListLazada=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Promise((function(a,s){i.vhmongo_firebase.lazada().getOrdersDetail(t,e,n).then((function(t){i.productlistlazada.forEach((function(e){e._id===o&&(e.salesorderdetaillist=t)})),a(t)}),(function(t){s(t)}))})),l=new Promise((function(n,a){var s={created_at:{$gte:new Date(t),$lte:new Date(e)}};i.vhmongo_firebase.database().getDocsByFields(o,s,{},{},0).then((function(t){n(t)}))}));Promise.all([r,l]).then((function(t){t[0].filter((function(e){var n=!0;return t[1].forEach((function(t){e.order_id.toString()===t._id&&(n=!1)})),n})).forEach((function(t){i.vhmongo_firebase.database().addDocbyID(o.toString(),t.order_id.toString(),{created_at:new Date(t.order_items[0].created_at)})}));for(var e=0;e<t[0].length;e++){delete t[0][e].order_number;for(var n=0;n<t[1].length;n++)if(String(t[0][e].order_id)===t[1][n]._id){var s=Object.assign({},t[1][n]);delete s._id,delete s.created_at,t[0][e]=Object.assign(Object.assign({},t[0][e]),s);break}}console.log("salesorderdetaillist",t[0]),a(t[0])}))}))},t.prototype.getSalesOrderDetailLazada=function(t,e,n){var o=this;return new Promise((function(i,a){var s=o.vhmongo_firebase.lazada().getOrderDetail(t,e),r=o.vhmongo_firebase.database().getDoc(n,t);Promise.all([s,r]).then((function(t){t[0]&&(t[1]||o.vhmongo_firebase.database().addDocbyID(n,t[0].order_id,{created_at:new Date(t[0].sales_order.created_at)})),i(t[0])}))}))},t.prototype.getSalesOrderLazada_fromViethas=function(t,e){var n=this;return new Promise((function(o,i){for(var a=new Array,s=0;s<t.length;s++)a[s]=n.vhmongo_firebase.database().getDoc(e,t[s]);Promise.all(a).then((function(t){o(t)}))}))},t.prototype.getSalesOrderDetailListLazada_fromViethas=function(t,e,n){var o=this;return new Promise((function(i,a){var s={order_date_time_stamp:{$gte:new Date(t),$lte:new Date(e)}};o.vhmongo_firebase.database().getDocsByFields(n,s,{},{order_date_time_stamp:1},0).then((function(t){i(t)}))}))},t.prototype.updateSalesOrderLazada=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.database().updateDoc(t,e,n).then((function(a){a&&o.productlistlazada.forEach((function(o){o._id===t&&o.salesorderdetaillist.forEach((function(t){t.order_id===e&&(t=Object.assign(Object.assign({},t),n))}))})),i(a)}),(function(t){a(t)}))}))},t.prototype.updateSalesOrderLazada_byFile=function(t,e,n,o){var i=this;return new Promise((function(a,s){for(var r=new Array,l=function(a){r[a]=new Promise((function(s){i.vhmongo_firebase.lazada().getOrderDetail(t[a],n).then((function(n){n?i.vhmongo_firebase.database().getDoc(o,t[a]).then((function(n){n?i.vhmongo_firebase.database().updateDoc(o,t[a],e).then((function(t){s(t)}),(function(){s(!1)})):i.vhmongo_firebase.database().addDocbyID(o,t[a],e).then((function(){s(!0)}))})):s(!1)}),(function(){s(!1)}))}))},c=0;c<t.length;c++)l(c);Promise.all(r).then((function(t){a(t)}))}))},t.prototype.getShopPartner=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("bills",{id_shop:{$eq:t}},{},{},1).then((function(t){0===t.length?n(null):n(e.getlocalCustomer(t[0].id_customer))}),(function(t){o(t)}))}))},t.prototype.updateShop=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().getDoc("ecommerces",t).then((function(a){if(a){var s={};s=null!=a.data?Object.assign(Object.assign({},a.data),e):Object.assign({},e),n.vhmongo_firebase.database().updateDoc("ecommerces",t,{data:s}).then((function(e){for(var i=0;i<n.shoplistlazada.length;i++)if(n.shoplistlazada[i]._id===t){n.shoplistlazada[i].data=s;break}for(i=0;i<n.shoplistsendo.length;i++)if(n.shoplistsendo[i]._id===t){n.shoplistsendo[i].data=s;break}for(i=0;i<n.shoplisttiki.length;i++)if(n.shoplisttiki[i]._id===t){n.shoplisttiki[i].data=s;break}o(e)}),(function(t){i(t)}))}else o(!1)}))}))},t.prototype.updateByJSONSendo=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.sendo().updateByJSONSendo(t,e).then((function(t){0===t.vcode?o(t.data):(console.log(t.message),o(null))}),(function(t){i(t)}))}))},t.prototype.updateOrderStatusSendo=function(t,e,n,o){var i=this;return new Promise((function(a,s){i.vhmongo_firebase.sendo().updateOrderStatusSendo(t,e,n,o).then((function(t){a(t)}),(function(t){s(t)}))}))},t.prototype.getSalesOrderDetailListSendo=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Promise((function(a,s){i.vhmongo_firebase.sendo().getSalesOrderPageTokensSendo(t,e,n).then((function(r){var l=r;i.vhmongo_firebase.sendo().getSalesOrderDetailPages(t,e,l,n).then((function(t){i.productlistsendo.forEach((function(e){e._id===o&&(e.salesorderdetaillist=t)})),a(t)}),(function(t){s(t)}))}),(function(t){s(t)}))})),l=new Promise((function(n,a){var s={order_date_time_stamp:{$gte:new Date(t),$lte:new Date(e)}};i.vhmongo_firebase.database().getDocsByFields(o,s).then((function(t){n(t)}))}));Promise.all([r,l]).then((function(t){var e=t[0].filter((function(e){var n=!0;return t[1].forEach((function(t){e.sales_order.order_number===t._id&&(n=!1)})),n})),n=(new Date).getTimezoneOffset();e.forEach((function(t){i.vhmongo_firebase.database().addDocbyID(o,t.sales_order.order_number,{order_date_time_stamp:new Date(1e3*(t.sales_order.order_date_time_stamp+60*n))})}));for(var s=0;s<t[0].length;s++)for(var r=0;r<t[1].length;r++)if(t[0][s].sales_order.order_number===t[1][r]._id){var l=Object.assign({},t[1][r]);delete l._id,delete l.order_date_time_stamp,t[0][s].sales_order=Object.assign(Object.assign({},t[0][s].sales_order),l)}a(t[0])}))}))},t.prototype.getSalesOrderDetailSendo=function(t,e,n){var o=this;return new Promise((function(i,a){var s=o.vhmongo_firebase.sendo().getSalesOrderDetail(t,e),r=o.vhmongo_firebase.database().getDoc(n,t);Promise.all([s,r]).then((function(t){if(t[0]){var e=(new Date).getTimezoneOffset();t[1]||o.vhmongo_firebase.database().addDocbyID(n,t[0].sales_order.order_number,{order_date_time_stamp:new Date(1e3*(t[0].sales_order.order_date_time_stamp+60*e))})}i(t[0])}))}))},t.prototype.getSalesOrderSendo_fromViethas=function(t,e){var n=this;return new Promise((function(o,i){for(var a=new Array,s=0;s<t.length;s++)a[s]=n.vhmongo_firebase.database().getDoc(e,t[s]);Promise.all(a).then((function(t){o(t)}))}))},t.prototype.getSalesOrderDetailListSendo_fromViethas=function(t,e,n){var o=this;return new Promise((function(i,a){var s={order_date_time_stamp:{$gte:new Date(t),$lte:new Date(e)}};o.vhmongo_firebase.database().getDocsByFields(n,s,{},{order_date_time_stamp:1},0).then((function(t){i(t)}))}))},t.prototype.updateSalesOrderSendo=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.database().updateDoc(t,e,n).then((function(a){a&&o.productlistsendo.forEach((function(o){o._id===t&&o.salesorderdetaillist.forEach((function(t){t.sales_order.order_number===e&&(t.sales_order=Object.assign(Object.assign({},t.sales_order),n))}))})),i(a)}),(function(t){a(t)}))}))},t.prototype.updateSalesOrderSendo_byFile=function(t,e,n,o){var i=this;return new Promise((function(a,s){for(var r=new Array,l=function(a){r[a]=new Promise((function(s){i.vhmongo_firebase.sendo().getSalesOrderDetail(t[a],n).then((function(n){n?i.vhmongo_firebase.database().getDoc(o,t[a]).then((function(n){n?i.vhmongo_firebase.database().updateDoc(o,t[a],e).then((function(t){s(t)}),(function(){s(!1)})):i.vhmongo_firebase.database().addDocbyID(o,t[a],e).then((function(){s(!0)}))})):s(!1)}),(function(){s(!1)}))}))},c=0;c<t.length;c++)l(c);Promise.all(r).then((function(t){a(t)}))}))},t.prototype.getlocalShopListSendo=function(){return this.shoplistsendo},t.prototype.getlocalProductListSendo=function(t){for(var e=0;e<this.productlistsendo.length;e++)if(this.productlistsendo[e]._id===t)return JSON.parse(JSON.stringify(this.productlistsendo[e].productlist));return[]},t.prototype.refreshLocalProductListSendo=function(t){var e=this;return new Promise((function(n,o){""!=t&&null!=t?e.getProductListSendo(t).then((function(){n(null)})):e.getProductListSendos().then((function(){n(null)}))}))},t.prototype.getProductListSendo=function(t){var e=this;return new Promise((function(n,o){var i=e.getDefaultBranch()._id;e.vhmongo_firebase.sendo().getShop(i,t).then((function(t){if(console.log("shopsendo",t),0===t.vcode){e.shoplistsendo=E(t.data),e.productlistsendo=E(t.data);for(var i=new Array,a=function(t){i[t]=new Promise((function(n,o){e.vhmongo_firebase.sendo().getProductListSendo(e.productlistsendo[t].token).then((function(o){e.productlistsendo[t].productlist=o,n(o)}))}))},s=0;s<e.productlistsendo.length;s++)a(s);Promise.all(i).then((function(){console.log("productlistsendo",e.productlistsendo),n(null)}))}else console.log("lỗi:",t.message),o(t.message)}),(function(t){o(t)}))}))},t.prototype.getProductListSendos=function(){var t=this;return new Promise((function(e,n){var o=t.getDefaultBranch()._id;t.vhmongo_firebase.sendo().getShopList(o).then((function(o){if(console.log("shoplist",o),0===o.vcode){t.shoplistsendo=E(o.data),t.productlistsendo=E(o.data);for(var i=new Array,a=function(e){i[e]=new Promise((function(n,o){t.vhmongo_firebase.sendo().getProductListSendo(t.productlistsendo[e].token).then((function(o){t.productlistsendo[e].productlist=o,n(o)}))}))},s=0;s<t.productlistsendo.length;s++)a(s);Promise.all(i).then((function(){console.log("productlistsendo",t.productlistsendo),e(null)}))}else console.log("lỗi:",o.message),n(o.message)}),(function(t){n(t)}))}))},t.prototype.getProductDetailSendo=function(t,e,n){var o=this;return new Promise((function(i,a){for(var s=[],r=0;r<t.length;r++)s[r]=o.vhmongo_firebase.sendo().getProductDetail(t[r],e);Promise.all(s).then((function(t){for(var e=0;e<o.productlistsendo.length;e++)if(o.productlistsendo[e]._id===n)for(var a=0;a<t.length;a++)for(var s=0;s<o.productlistsendo[e].productlist.length;s++)if(t[a].id===o.productlistsendo[e].productlist[s].id){o.productlistsendo[e].productlist[s]=Object.assign(Object.assign({},o.productlistsendo[e].productlist[s]),t[a]);break}i(t)}))}))},t.prototype.signInSendo=function(t,e,n){var o=this;return new Promise((function(i,a){var s=o.getDefaultBranch()._id;o.vhmongo_firebase.sendo().signIn(t,e,n,s).then((function(t){0===t.vcode?(o.shoplistsendo.push(t.data),i(t.data)):(console.log(t.message),i(null))}),(function(t){a(t)}))}))},t.prototype.signOutSendo=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.sendo().signOut(t).then((function(i){if(0===i.vcode){for(var a=0;a<e.shoplistsendo.length;a++)if(e.shoplistsendo[a]._id===t){e.shoplistsendo.splice(a,1);break}for(a=0;a<e.productlistsendo.length;a++)if(e.productlistsendo[a]._id===t){e.productlistsendo.splice(a,1);break}n(!0)}else console.log(i.message),o(!1)}),(function(t){o(t)}))}))},t.prototype.getShopListSendo=function(){var t=this;return new Promise((function(e,n){var o=t.getDefaultBranch()._id;t.vhmongo_firebase.sendo().getShopList(o).then((function(o){0===o.vcode?(t.shoplistsendo.push(o.data),e(o.data)):(console.log(o.message),n(o.message))}),(function(t){n(t)}))}))},t.prototype.addMergeSendoProduct_variants=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=i.getDefaultBranch()._id,l=i.getlocalProduct(t),c={id:e,id_shop:o,variants:E(n)};null!=l[r]?void 0===l[r].sendos&&(l[r].sendos=new Array):(l[r]={},l[r].sendos=new Array);for(var u=!1,d=0;d<l[r].sendos.length;d++)if(l[r].sendos[d].id===e&&l[r].sendos[d].id_shop===o){var _;null!=l[r].sendos[d].variants?l[r].sendos[d].variants=E(l[r].sendos[d].variants,n):l[r].sendos[d].variants=E(n),(_={})[r]=l[r],i.vhmongo_firebase.database().updateDoc("products",t,Object.assign({},_)).then((function(){a(!0)}),(function(t){s(t)})),u=!0;break}u||(l[r].sendos.push(c),(_={})[r]=l[r],i.vhmongo_firebase.database().updateDoc("products",t,Object.assign({},_)).then((function(){a(!0)}),(function(t){s(t)})))}))},t.prototype.updateMergeSendoProduct=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=i.getlocalProduct(t),l=i.getDefaultBranch()._id;if(void 0===r[l])return a(!1);if(void 0===r[l].sendos)return a(!1);for(var c=!1,u=0;u<r[l].sendos.length;u++)if(r[l].sendos[u].id===e&&r[l].sendos[u].id_shop===o){r[l].sendos[u]=Object.assign(Object.assign({},r[l].sendos[u]),n);var d={};d[l]=r[l],i.vhmongo_firebase.database().updateDoc("products",t,Object.assign({},d)).then((function(t){a(t)}),(function(t){s(t)})),c=!0;break}c||a(!1)}))},t.prototype.updateMergeSendoProduct_hidden=function(t,e,n){var o=this;return new Promise((function(i,a){for(var s=o.getDefaultBranch()._id,r=o.getlocalProducts(),l=null,c=0;c<r.length;c++)if(null!=r[c][s]&&null!=r[c][s].sendos)for(var u=0;u<r[c][s].sendos.length;u++)if(r[c][s].sendos[u].id===t&&r[c][s].sendos[u].id_shop===n){l=r[c];break}if(!l)return i(!1);if(void 0===l[s])return i(!1);if(void 0===l[s].sendos)return i(!1);var d=!1;for(c=0;c<l[s].sendos.length;c++)if(l[s].sendos[c].id===t&&l[s].sendos[c].id_shop===n){for(var _=0;_<o.productlistlazada.length;_++)if(o.productlistlazada[_]._id===n)for(var p=0;p<o.productlistlazada[_].productlist.length;p++)if(o.productlistlazada[_].productlist[p].id===t){o.productlistlazada[_].productlist[p].hidden=e;break}l[s].sendos[c].hidden=e;var b={};b[s]=l[s],o.vhmongo_firebase.database().updateDoc("products",l._id,Object.assign({},b)).then((function(t){i(t)}),(function(t){a(t)})),d=!0;break}d||i(!1)}))},t.prototype.updateMergeSendoProduct_variants=function(t,e,n,o,i){var a=this;return new Promise((function(s,r){var l=a.getlocalProduct(t),c=a.getDefaultBranch()._id;if(void 0===l[c])return s(!1);if(void 0===l[c].sendos)return s(!1);for(var u=!1,d=0;d<l[c].sendos.length;d++)if(l[c].sendos[d].id===e&&l[c].sendos[d].id_shop===i&&null!=l[c].sendos[d].variants)for(var _=0;_<l[c].sendos[d].variants.length;_++)if(l[c].sendos[d].variants[_].variant_attribute_hash===n){l[c].sendos[d].variants[_]=Object.assign(Object.assign({},l[c].sendos[d].variants[_]),o);var p={};p[c]=l[c],a.vhmongo_firebase.database().updateDoc("products",t,Object.assign({},p)).then((function(t){s(t)}),(function(t){r(t)})),u=!0;break}u||s(!1)}))},t.prototype.deleteMergeSendoProduct_variants=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=i.getlocalProduct(t),l=i.getDefaultBranch()._id;if(void 0===r[l])return a(!1);if(void 0===r[l].sendos)return a(!1);for(var c=!1,u=0;u<r[l].sendos.length;u++)if(r[l].sendos[u].id===e&&r[l].sendos[u].id_shop===o&&null!=r[l].sendos[u].variants){for(var d=0;d<r[l].sendos[u].variants.length;d++)if(r[l].sendos[u].variants[d].variant_attribute_hash===n){r[l].sendos[u].variants.splice(d,1),(_={})[l]=r[l],i.vhmongo_firebase.database().updateDoc("products",r._id,Object.assign({},_)).then((function(t){a(t)}),(function(t){s(t)})),c=!0;break}var _;if(0===r[l].sendos[u].variants.length)r[l].sendos.splice(u,1),(_={})[l]=r[l],i.vhmongo_firebase.database().updateDoc("products",r._id,Object.assign({},_)).then((function(t){a(t)}),(function(t){s(t)})),c=!0}c||a(!1)}))},t.prototype.getReportSales_Sendo=function(t,e,n,o,i){},t.prototype.fixOldVersion=function(t){var e=this;return 1===t?new Promise((function(t,n){var o=e.getDefaultBranch();e.vhmongo_firebase.database().getDocs("vhbill_details").then((function(n){var i=new Array;if(n.length>0){for(var a=0;a<n.length;a++)void 0===n[a].id_branch&&(i[i.length]=e.vhmongo_firebase.database().updateDoc("vhbill_details",n[a]._id,{id_branch:o._id}));Promise.all(i).then((function(e){console.log("array_promise.length",e.length),t(!0)}))}else t(!1)})).catch((function(t){n(t)}))})):2===t?new Promise((function(t,n){var o=e.getDefaultBranch();e.vhmongo_firebase.database().getDocs("wallets").then((function(n){var i=new Array;if(n.length>0){for(var a=0;a<n.length;a++)"id_cash"!=n[a]._id&&void 0===n[a].id_branch&&(i[i.length]=e.vhmongo_firebase.database().updateDoc("wallets",n[a]._id,{id_branch:o._id}));Promise.all(i).then((function(e){console.log("array_promise.length",e.length),t(!0)}))}else t(!1)})).catch((function(t){n(t)}))})):3===t?new Promise((function(t,n){e.vhmongo_firebase.database().getDocs("vhbill_details").then((function(n){var o=new Array;if(n.length>0){for(var i=0;i<n.length;i++)if(void 0===n[i].id_category&&null!=n[i].id_product){var a=e.getlocalProduct(n[i].id_product).id_category;o[o.length]=e.vhmongo_firebase.database().updateDoc("vhbill_details",n[i]._id,{id_category:a})}Promise.all(o).then((function(e){console.log("array_promise",e),t(!0)}))}else t(!1)})).catch((function(t){n(t)}))})):void 0},t.prototype.syncCollections_Mobile=function(){var t=this;return new Promise((function(e,n){t.initSyncCollections(),t.callbackCollectionInsert().subscribe(),t.callbackCollectionUpdate().subscribe(),t.callbackCollectionDelete().subscribe(),setTimeout((function(){t.checkExpireBranch_Sales(),e(!0)}),3e3)}))},t.prototype.syncCollections_Desktop=function(){var t=this;return new Promise((function(e,n){t.initSyncCollections(),t.callbackCollectionInsert().subscribe(),t.callbackCollectionUpdate().subscribe(),t.callbackCollectionDelete().subscribe(),setTimeout((function(){t.syncCashBookEveryDay_Stock1stDayOfMonth().then((function(){t.syncInventoryEveryDay_Stock1stDayOfMonth().then((function(){e(!0)})),t.checkExpireBranch_Sales()}))}),3e3)}))},t.prototype.checkExpireBranch_Sales=function(){if(this.getDefaultBranch()){var t=this.getDefaultBranch()._id;this.vhmongo_firebase.auth().checkExpireBranch_Sales(t).then((function(){console.log("success checkExpireBranch_Sales")}),(function(t){console.log("no success checkExpireBranch_Sales")}))}},t.prototype.fixBill=function(){var t=this;return new Promise((function(e,n){var o={date:{$gte:new Date("2021-12-09T05:24:00"),$lte:new Date("2021-12-09T05:24:00")}};t.vhmongo_firebase.database().getDocsByFields("bills",o,{},{date:1},0).then((function(n){if(n.length>0)for(var o=0;o<n.length;o++)t.vhmongo_firebase.database().getDocsByFields("vhbill_details",{id_bill:{$eq:n[o]._id}},{},{},0).then((function(e){for(var n=0;n<e.length;n++)if(void 0===e[n].ptype&&null!=e[n].id_product){var o=t.getlocalProduct(e[n].id_product);null!=o&&(console.log("product.type",o.type),t.vhmongo_firebase.database().updateDoc("vhbill_details",e[n]._id,{ptype:o.type}))}}));e(null)}))}))},t.prototype.initSyncCollections=function(){this.categorys=new Array,this.products=new Array,this.suppliers=new Array,this.customers=new Array,this.wallets=new Array,this.branchs=new Array,this.taxs=new Array,this.promotions=new Array,this.inventorytimes=new Array,this.appsettingbranchs=new Array,this.appsettingstations=new Array,this.printers=new Array,this.warrantys=new Array,this.vhAuth.clearLocalEmployeeFromSyncCollection();var t=new Array;return t[0]="categorys",t[1]="warrantys",t[2]="suppliers",t[3]="customers",t[4]="wallets",t[5]="branchs",t[6]="taxs",t[7]="vhemployees",t[8]="promotions",t[9]="inventorytimes",t[10]="appsettingstations",t[11]="appsettingbranchs",t[12]="printers",t[13]="products",t[14]="discount_bills",t[15]="customer_classs",this.vhmongo_firebase.socketMongoDB().initSyncCollections(t)},t.prototype.closeSyncCollections=function(){this.vhmongo_firebase.socketMongoDB().closeSyncCollections()},t.prototype.callbackCollectionInsert=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackCollectionInsert().subscribe((function(n){if("vhemployees"===n.colname&&(n.colname="employees"),"categorys"===n.colname)t.getlocalCategory(n._id)||((o=Object.assign({},n.data))._id=n._id,t.categorys.push(o),t.publishObservableEventCategorys(),e.next(n.colname));else if("products"===n.colname){if(!t.getlocalProduct(n._id))(o=Object.assign({},n.data))._id=n._id,t.products.push(o),t.publishObservableEventProducts(),e.next(n.colname);e.next(n.colname)}else if("suppliers"===n.colname){if(!t.getlocalSupplier(n._id))(o=Object.assign({},n.data))._id=n._id,t.suppliers.push(o),t.publishObservableEventSuppliers(),e.next(n.colname)}else if("customers"===n.colname){if(!t.getlocalCustomer(n._id))(o=Object.assign({},n.data))._id=n._id,t.customers.push(o),t.publishObservableEventCustomers(),e.next(n.colname)}else if("wallets"===n.colname){if(!t.getlocalWallet(n._id))(o=Object.assign({},n.data))._id=n._id,t.wallets.push(o),t.publishObservableEventWallets(),e.next(n.colname)}else if("branchs"===n.colname){if(!t.getlocalBranch(n._id))(o=Object.assign({},n.data))._id=n._id,t.branchs.push(o),t.publishObservableEventBranchs(),e.next(n.colname)}else if("taxs"===n.colname){if(!t.getlocalTax(n._id))(o=Object.assign({},n.data))._id=n._id,t.taxs.push(o),t.publishObservableEventTaxs(),e.next(n.colname)}else if("employees"===n.colname){(o=Object.assign({},n.data))._id=n._id,t.vhAuth.insertlocalEmployeeFromSyncCollection(o),t.vhAuth.publishObservableEventEmployees(),e.next(n.colname)}else if("promotions"===n.colname){if(!t.getlocalPromotion(n._id))(o=Object.assign({},n.data))._id=n._id,t.promotions.push(o),t.publishObservableEventPromotions(),e.next(n.colname)}else if("inventorytimes"===n.colname){if(!t.getlocalInventorytime(n._id))(o=Object.assign({},n.data))._id=n._id,t.inventorytimes.push(o),t.publishObservableEventInventorytimes(),e.next(n.colname)}else if("appsettingbranchs"===n.colname){if(!t.getLocalAppSettingBranch(n._id)&&n.data.id_branch===t.getDefaultBranch()._id){var o=Object.assign(Object.assign({},n.data),{_id:n._id});t.appsettingbranchs.push(o),t.publishObservableEventAppSettingNameBranchs(),e.next(n.colname)}}else if("appsettingstations"===n.colname){if(!t.getLocalAppSettingStation(n._id))if(n.data.uuid===t.hwinfo.uuid)(o=Object.assign({},n.data))._id=n._id,delete o.uuid,t.appsettingstations.push(o),t.publishObservableEventAppSettingNameStations(),e.next(n.colname)}else if("printers"===n.colname){if(!t.getlocalPrinter(n._id))if(n.data.uuid===t.hwinfo.uuid)(o=Object.assign({},n.data))._id=n._id,delete o.uuid,t.printers.push(o),t.publishObservableEventPrinters(),e.next(n.colname)}else if("warrantys"===n.colname){if(!t.getlocalWarranty(n._id))(o=Object.assign({},n.data))._id=n._id,t.warrantys.push(o),t.publishObservableEventWarrantys(),e.next(n.colname)}else if("discount_bills"===n.colname){if(!t.getlocalDiscount_bill(n._id))(o=Object.assign({},n.data))._id=n._id,t.discount_bills.push(o),t.publishObservableEventDiscount_bills(),e.next(n.colname)}else if("customer_classs"===n.colname){if(!t.getlocalCustomerClass(n._id))(o=Object.assign({},n.data))._id=n._id,t.customer_classs.push(o),t.publishObservableEventCustomerClasss(),e.next(n.colname)}console.log("inserted",n.colname)}))}))},t.prototype.callbackCollectionUpdate=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackCollectionUpdate().subscribe((function(n){if("vhemployees"===n.colname?n.colname="employees":"branchs"===n.colname?n.colname="branchs":"printers"===n.colname?n.colname="printers":"appsettingstations"===n.colname&&(n.colname="appsettingstations"),"categorys"===n.colname){for(var o=0;o<t.categorys.length;o++)if(t.categorys[o]._id===n._id){t.categorys[o]=Object.assign(Object.assign({},t.categorys[o]),n.data),t.publishObservableEventCategorys(),e.next(n.colname);break}}else if("products"===n.colname){for(o=0;o<t.products.length;o++)if(t.products[o]._id===n._id){t.products[o]=Object.assign(Object.assign({},t.products[o]),n.data),t.publishObservableEventProducts(),e.next(n.colname);break}}else if("suppliers"===n.colname){for(o=0;o<t.suppliers.length;o++)if(t.suppliers[o]._id===n._id){t.suppliers[o]=Object.assign(Object.assign({},t.suppliers[o]),n.data),t.publishObservableEventSuppliers(),e.next(n.colname);break}}else if("customers"===n.colname){for(o=0;o<t.customers.length;o++)if(t.customers[o]._id===n._id){t.customers[o]=Object.assign(Object.assign({},t.customers[o]),n.data),t.publishObservableEventCustomers(),e.next(n.colname);break}}else if("wallets"===n.colname){for(o=0;o<t.wallets.length;o++)if(t.wallets[o]._id===n._id){t.wallets[o]=Object.assign(Object.assign({},t.wallets[o]),n.data),t.publishObservableEventWallets(),e.next(n.colname);break}}else if("branchs"===n.colname){for(o=0;o<t.branchs.length;o++)if(t.branchs[o]._id===n._id){t.branchs[o]=Object.assign(Object.assign({},t.branchs[o]),n.data),t.publishObservableEventBranchs(),e.next(n.colname);break}}else if("taxs"===n.colname){for(o=0;o<t.taxs.length;o++)if(t.taxs[o]._id===n._id){t.taxs[o]=Object.assign(Object.assign({},t.taxs[o]),n.data),t.publishObservableEventTaxs(),e.next(n.colname);break}}else if("employees"===n.colname)t.vhAuth.updateLocalEmployeeFromSyncCollection(n._id,n.data),t.vhAuth.publishObservableEventEmployees(),e.next(n.colname);else if("promotions"===n.colname){for(o=0;o<t.promotions.length;o++)if(t.promotions[o]._id===n._id){t.promotions[o]=Object.assign(Object.assign({},t.promotions[o]),n.data),t.publishObservableEventPromotions(),e.next(n.colname);break}}else if("inventorytimes"===n.colname){for(o=0;o<t.inventorytimes.length;o++)if(t.inventorytimes[o]._id===n._id){t.inventorytimes[o]=Object.assign(Object.assign({},t.inventorytimes[o]),n.data),t.publishObservableEventInventorytimes(),e.next(n.colname);break}}else if("appsettingbranchs"===n.colname){for(o=0;o<t.appsettingbranchs.length;o++)if(t.appsettingbranchs[o]._id===n._id){t.appsettingbranchs[o]=Object.assign(Object.assign({},t.appsettingbranchs[o]),n.data),t.publishObservableEventAppSettingNameBranchs(),e.next(n.colname);break}}else if("appsettingstations"===n.colname){for(o=0;o<t.appsettingstations.length;o++)if(t.appsettingstations[o]._id===n._id){t.appsettingstations[o]=Object.assign(Object.assign({},t.appsettingstations[o]),n.data),t.publishObservableEventAppSettingNameStations(),e.next(n.colname);break}}else if("printers"===n.colname){for(o=0;o<t.printers.length;o++)if(t.printers[o]._id===n._id){t.printers[o]=Object.assign(Object.assign({},t.printers[o]),n.data),t.publishObservableEventPrinters(),e.next(n.colname);break}}else if("warrantys"===n.colname){for(o=0;o<t.warrantys.length;o++)if(t.warrantys[o]._id===n._id){t.warrantys[o]=Object.assign(Object.assign({},t.warrantys[o]),n.data),t.publishObservableEventWarrantys(),e.next(n.colname);break}}else if("discount_bills"===n.colname){for(o=0;o<t.discount_bills.length;o++)if(t.discount_bills[o]._id===n._id){t.discount_bills[o]=Object.assign(Object.assign({},t.discount_bills[o]),n.data),t.publishObservableEventDiscount_bills(),e.next(n.colname);break}}else if("customer_classs"===n.colname)for(o=0;o<t.customer_classs.length;o++)if(t.customer_classs[o]._id===n._id){t.customer_classs[o]=Object.assign(Object.assign({},t.customer_classs[o]),n.data),t.publishObservableEventCustomerClasss(),e.next(n.colname);break}console.log("updated",n.colname)}))}))},t.prototype.callbackCollectionDelete=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackCollectionDelete().subscribe((function(n){if("vhemployees"===n.colname&&(n.colname="employees"),"categorys"===n.colname){for(var o=0;o<t.categorys.length;o++)if(t.categorys[o]._id===n._id){t.categorys.splice(o,1),t.publishObservableEventCategorys(),e.next(n.colname);break}}else if("products"===n.colname){for(o=0;o<t.products.length;o++)if(t.products[o]._id===n._id){t.products.splice(o,1),t.publishObservableEventProducts(),e.next(n.colname);break}}else if("suppliers"===n.colname){for(o=0;o<t.suppliers.length;o++)if(t.suppliers[o]._id===n._id){t.suppliers.splice(o,1),t.publishObservableEventSuppliers(),e.next(n.colname);break}}else if("customers"===n.colname){for(o=0;o<t.customers.length;o++)if(t.customers[o]._id===n._id){t.customers.splice(o,1),t.publishObservableEventCustomers(),e.next(n.colname);break}}else if("wallets"===n.colname){for(o=0;o<t.wallets.length;o++)if(t.wallets[o]._id===n._id){t.wallets.splice(o,1),t.publishObservableEventWallets(),e.next(n.colname);break}}else if("branchs"===n.colname){for(o=0;o<t.branchs.length;o++)if(t.branchs[o]._id===n._id){t.branchs.splice(o,1),t.publishObservableEventBranchs(),e.next(n.colname);break}}else if("taxs"===n.colname){for(o=0;o<t.taxs.length;o++)if(t.taxs[o]._id===n._id){t.taxs.splice(o,1),t.publishObservableEventTaxs(),e.next(n.colname);break}}else if("employees"===n.colname)t.vhAuth.deleteLocalEmployeeFromSyncCollection(n._id),t.vhAuth.publishObservableEventEmployees(),e.next(n.colname);else if("promotions"===n.colname){for(o=0;o<t.promotions.length;o++)if(t.promotions[o]._id===n._id){t.promotions.splice(o,1),t.publishObservableEventPromotions(),e.next(n.colname);break}}else if("inventorytimes"===n.colname){for(o=0;o<t.inventorytimes.length;o++)if(t.inventorytimes[o]._id===n._id){t.inventorytimes.splice(o,1),t.publishObservableEventInventorytimes(),e.next(n.colname);break}}else if("appsettingbranchs"===n.colname){for(o=0;o<t.appsettingbranchs.length;o++)if(t.appsettingbranchs[o]._id===n._id){t.appsettingbranchs.splice(o,1),t.publishObservableEventAppSettingNameBranchs(),e.next(n.colname);break}}else if("appsettingstations"===n.colname){for(o=0;o<t.appsettingstations.length;o++)if(t.appsettingstations[o]._id===n._id){t.appsettingstations.splice(o,1),t.publishObservableEventAppSettingNameStations(),e.next(n.colname);break}}else if("printers"===n.colname){for(o=0;o<t.printers.length;o++)if(t.printers[o]._id===n._id){t.printers.splice(o,1),t.publishObservableEventPrinters(),e.next(n.colname);break}}else if("warrantys"===n.colname){for(o=0;o<t.warrantys.length;o++)if(t.warrantys[o]._id===n._id){t.warrantys.splice(o,1),t.publishObservableEventWarrantys(),e.next(n.colname);break}}else if("discount_bills"===n.colname){for(o=0;o<t.discount_bills.length;o++)if(t.discount_bills[o]._id===n._id){t.discount_bills.splice(o,1),t.publishObservableEventDiscount_bills(),e.next(n.colname);break}}else if("customer_classs"===n.colname)for(o=0;o<t.customer_classs.length;o++)if(t.customer_classs[o]._id===n._id){t.customer_classs.splice(o,1),t.publishObservableEventCustomerClasss(),e.next(n.colname);break}console.log("deleted",n.colname)}))}))},t.prototype.initChatToAppCare=function(){return this.vhmongo_firebase.socketMongoDB().initChat("vhmessages",{})},t.prototype.listeningChatToAppCare_Insert=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackChatInsert().subscribe((function(t){e.next(t)}))}))},t.prototype.listeningChatToAppCare_Update=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackChatUpdate().subscribe((function(t){e.next(t)}))}))},t.prototype.getOldMessages=function(t){return this.vhmongo_firebase.database().getDocsByFields("vhmessages",{},{},{date:1},t)},t.prototype.sendMessageToAppCare=function(t){var e=this;return new Promise((function(n,o){var i={msg:t,date:new Date,avatar:e.getLocalAppSettingNameStation("store_info").img,email:e.getLocalAppSettingNameStation("store_info").email,company:e.getLocalAppSettingNameStation("store_info").company,align:"left"};e.vhmongo_firebase.database().addDoc("vhmessages",i).then((function(t){n(t)}),(function(t){o(t)})),e.vhmongo_firebase.socketMongoDB().saytoAppCareFirebase()}))},t.prototype.sendImageToAppCare=function(t){var e=this;return new Promise((function(n,o){var i={img:t,date:new Date,avatar:e.getLocalAppSettingNameStation("store_info").img,email:e.getLocalAppSettingNameStation("store_info").email,company:e.getLocalAppSettingNameStation("store_info").company,align:"left"};e.vhmongo_firebase.database().addDoc("vhmessages",i).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.startLocalStorage=function(){var t=this;return new Promise((function(e){var n=new Array;n[0]=t.vhAuth.refreshLocalMyPermission(),n[1]=t.refreshLocalDeliverys(),n[2]=t.refreshLocalAddresss(),t.vhQuery.asyncPromiseAll(n).then((function(){e(null)}))}))},t.prototype.initPurchase=function(){var t=this;this.platform.ready().then((function(){t.iap2.verbosity=t.iap2.DEBUG,t.initPaymentOnAPPStore("in_vhsales_3days",3),t.initPaymentOnAPPStore("in_vhsales_30days",30),t.initPaymentOnAPPStore("in_vhsales_90days",90),t.initPaymentOnAPPStore("in_vhsales_180days",180),t.initPaymentOnAPPStore("in_vhsales_365days",365),t.iap2.refresh()}))},t.prototype.initPaymentOnAPPStore=function(t,e){this.iap2.register({id:t,alias:t,type:this.iap2.CONSUMABLE}),this.registerHandlersForPurchase(t,e)},t.prototype.registerHandlersForPurchase=function(t,e){var n=this;this.iap2.when(t).updated((function(t){})),this.iap2.when(t).registered((function(t){console.log("Registered1: "+JSON.stringify(t))})),this.iap2.when(t).owned((function(t){console.log("owned1: "+JSON.stringify(t))})),this.iap2.when(t).approved((function(o){console.log("approved1: "+JSON.stringify(o)),o.verify(),n.vhmongo_firebase.auth().createSubscribedTime(t,e).then((function(){}))})),this.iap2.when(t).refunded((function(t){console.log("refunded1: "+JSON.stringify(t))})),this.iap2.when(t).expired((function(t){console.log("expired1: "+JSON.stringify(t))})),this.iap2.when(t).verified((function(t){console.log("verified1: "+JSON.stringify(t)),t.finish()}))},t.prototype.paymentOnAPPStore=function(t){try{this.iap2.order(t).then((function(t){console.log("Purchase Succesful1"+JSON.stringify(t))})).catch((function(t){console.log("Error Ordering From Store1"+t)}))}catch(t){console.log("Error Ordering1 "+JSON.stringify(t))}},t.prototype.refreshPurchase=function(){this.iap2.refresh()},t.prototype.publishObservableEventProducts=function(){this.subjectproducts.next()},t.prototype.observableLocalProducts=function(){return this.subjectproducts},t.prototype.getObservableLocalProducts=function(t){var e=this;return new c.Observable((function(n){e.observableLocalProducts().subscribe((function(){n.next(e.getlocalProducts(t))})),e.publishObservableEventProducts()}))},t.prototype.getlocalProductAndCombos=function(t){for(var e=new Array,n=0;n<this.products.length;n++)if(this.products[n]._id===t&&e.push(Object.assign({},this.products[n])),null!=this.products[n].combos)for(var o=0;o<this.products[n].combos.length;o++)if(this.products[n].combos[o].id_product===t){e.push(Object.assign({},this.products[n]));break}return e},t.prototype.getlocalProduct=function(t){for(var e=0;e<this.products.length;e++)if(this.products[e]._id===t)return JSON.parse(JSON.stringify(this.products[e]));return null},t.prototype.getlocalProducts=function(t){var e=new Array;return e=this.products.filter((function(e){if(1===t||2===t||5===t){if(e.type===t)return!0}else if(15===t){if(1===e.type||5===e.type)return!0}else if(25===t){if(2===e.type||5===e.type)return!0}else{if(12!==t)return!0;if(1===e.type||2===e.type)return!0}})),JSON.parse(JSON.stringify(e))},t.prototype.refreshLocalProducts=function(){return new Promise((function(t,e){t(null)}))},t.prototype.addProduct=function(t){var e=this;return new Promise((function(n,o){1===(null==t?void 0:t.type)&&(t.quantity=0,t.quantity_branch={},e.branchs.forEach((function(e){t.quantity_branch[e._id]=0}))),e.vhmongo_firebase.database().addDoc("products",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.addProducts=function(t){var e=this;return new Promise((function(n,o){for(var i,a=new Array,s=function(n){1===(null===(i=t[n])||void 0===i?void 0:i.type)&&(t[n].quantity=0,t[n].quantity_branch={},e.branchs.forEach((function(e){t[n].quantity_branch[e._id]=0}))),a[n]=new Promise((function(o){e.vhmongo_firebase.database().addDoc("products",t[n]).then((function(t){o(t)}),(function(){o(null)}))}))},r=0;r<t.length;r++)s(r);Promise.all(a).then((function(t){var e=t.filter((function(t){return null!=t}));n(e)}))}))},t.prototype.updateProduct=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("products",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteProduct=function(t){var e=this;return new Promise((function(n,o){var i=new Array;e.getlocalProductAndCombos(t).forEach((function(t){i.push(t._id)})),1===i.length?e.vhmongo_firebase.database().getDocsByFields("vhbill_details",{id_product:{$in:i}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("products",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)})):(console.log("Bạn không thể xóa, vì sản phẩm đang liên kết với sản phẩm khác"),n(!1))}))},t.prototype.getProduct=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("products",t).then((function(t){n(t)}))}))},t.prototype.getProducts=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("products").then((function(n){t.products=n,e(n)}),(function(t){n(t)}))}))},t.prototype.addCombosProduct=function(t,e){for(var n,o=this,i=0;i<e.length;i++)null===(n=e[i])||void 0===n||delete n.name;return new Promise((function(n,i){for(var a=new Array,s=0;s<e.length;s++)a[s]=Object.assign(Object.assign({},e[s]),{_id:o.vhAlgorithm.ObjectId()});var r,l=!1,c=0,u=setInterval((function(){var e,s;if(c++,r=o.getlocalProduct(t)){l=!0,void 0===r.combos&&(r.combos=new Array);for(var d=0;d<r.combos.length;d++)null===(e=r.combos[d])||void 0===e||delete e.name,null===(s=r.combos[d])||void 0===s||delete s.img;var _=E(r.combos,a);o.vhmongo_firebase.database().updateDoc("products",t,{combos:_}).then((function(){for(var t=0;t<a.length;t++){var e=o.getlocalProduct(a[t].id_product);if(a[t].name=e.name,a[t].img=e.img,null!=a[t].id_subproduct)for(var i=0;i<e.subs.length;i++)if(a[t].id_subproduct===e.subs[i]._id){a[t].name=a[t].name+"("+e.subs[i].name+")";break}}n(a)}),(function(){i(null)}))}!0!==l&&20!==c||clearInterval(u)}),100)}))},t.prototype.updateComboProduct=function(t,e,n){var o=this;return null==n||delete n.name,null==n||delete n.quantity,new Promise((function(i,a){var s=o.getlocalProduct(t);if(null!=s.combos){s.combos.forEach((function(t){null==t||delete t.name,null==t||delete t.img}));for(var r=0;r<s.combos.length;r++)if(s.combos[r]._id===e){s.combos[r]=Object.assign(Object.assign({},s.combos[r]),n),o.vhmongo_firebase.database().updateDoc("products",s._id,{combos:s.combos}).then((function(t){i(t)}),(function(t){a(t)}));break}}}))},t.prototype.publishObservableEventCustomers=function(){this.subjectcustomers.next(this.customers)},t.prototype.observableLocalCustomers=function(){return this.subjectcustomers},t.prototype.getObservableLocalCustomers=function(){var t=this;return new c.Observable((function(e){t.observableLocalCustomers().subscribe((function(t){e.next(t)})),t.publishObservableEventCustomers()}))},t.prototype.getlocalCustomer=function(t){for(var e=0;e<this.customers.length;e++)if(this.customers[e]._id===t)return this.customers[e];return null},t.prototype.getlocalCustomers=function(){return this.customers},t.prototype.refreshLocalCustomers=function(){return new Promise((function(t){t(null)}))},t.prototype.addCustomer=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("customers",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.addCustomers=function(t){var e=this;return new Promise((function(n,o){for(var i=new Array,a=function(n){i[n]=new Promise((function(o){e.vhmongo_firebase.database().addDoc("customers",t[n]).then((function(t){o(t)}),(function(){o(null)}))}))},s=0;s<t.length;s++)a(s);Promise.all(i).then((function(t){var e=t.filter((function(t){return null!=t}));n(e)}))}))},t.prototype.updateCustomer=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("customers",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteCustomer=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("bills",{id_customer:{$eq:t}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("customers",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getCustomer=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("customers",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getCustomers=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("customers").then((function(n){t.customers=n,e(n)}),(function(t){n(t)}))}))},t.prototype.updateCustomer_byPoints=function(t,e){var n=this;return new Promise((function(o,i){var a=n.getlocalCustomer(t);a.earned_points,a.earned_points=e;var s=n.getDefaultBranch();null!=a.branch_earned_points?(a.branch_earned_points[s._id],a.branch_earned_points[s._id]=e):(a.branch_earned_points={},a.branch_earned_points[s._id]=e);var r={earned_points:a.earned_points,branch_earned_points:a.branch_earned_points};n.vhmongo_firebase.database().updateDoc("customers",t,Object.assign({},r)).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.updateCustomer_byEarnedPoints=function(t,e){var n=this;return new Promise((function(o,i){var a=n.getlocalCustomer(t);null!=a.earned_points?a.earned_points=a.earned_points+e:a.earned_points=e;var s=n.getDefaultBranch();null!=a.branch_earned_points?null!=a.branch_earned_points[s._id]?a.branch_earned_points[s._id]=a.branch_earned_points[s._id]+e:a.branch_earned_points[s._id]=e:(a.branch_earned_points={},a.branch_earned_points[s._id]=e);var r={earned_points:a.earned_points,branch_earned_points:a.branch_earned_points};n.vhmongo_firebase.database().updateDoc("customers",t,Object.assign({},r)).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.getlocalCustomerPoints=function(t){for(var e=this.getDefaultBranch(),n=0;n<this.customers.length;n++)if(this.customers[n]._id===t){if(1===this.getSales_Management_Scope().sales_program_scope)return null!=this.customers[n].earned_points?this.customers[n].earned_points:0;if(2===this.getSales_Management_Scope().sales_program_scope)return null!=this.customers[n].branch_earned_points&&null!=this.customers[n].branch_earned_points[e._id]?this.customers[n].branch_earned_points[e._id]:0;break}},t.prototype.publishObservableEventSuppliers=function(){this.subjectsuppliers.next(this.suppliers)},t.prototype.observableLocalSuppliers=function(){return this.subjectsuppliers},t.prototype.getObservableLocalSuppliers=function(){var t=this;return new c.Observable((function(e){t.observableLocalSuppliers().subscribe((function(t){e.next(E(t))})),t.publishObservableEventSuppliers()}))},t.prototype.getlocalSupplier=function(t){for(var e=0;e<this.suppliers.length;e++)if(this.suppliers[e]._id===t)return this.suppliers[e];return null},t.prototype.getlocalSuppliers=function(){return E(this.suppliers)},t.prototype.refreshLocalSuppliers=function(){return new Promise((function(t){t(null)}))},t.prototype.addSupplier=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("suppliers",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.addSuppliers=function(t){var e=this;return new Promise((function(n,o){for(var i=new Array,a=function(n){i[n]=new Promise((function(o){e.vhmongo_firebase.database().addDoc("suppliers",t[n]).then((function(t){o(t)}),(function(){o(null)}))}))},s=0;s<t.length;s++)a(s);Promise.all(i).then((function(t){var e=t.filter((function(t){return null!=t}));n(e)}))}))},t.prototype.updateSupplier=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("suppliers",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteSupplier=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("bills",{id_supplier:{$eq:t}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("suppliers",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getSupplier=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("suppliers",t).then((function(t){n(t)}))}))},t.prototype.getSuppliers=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("suppliers").then((function(n){t.suppliers=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventWallets=function(){this.subjectwallets.next(this.wallets)},t.prototype.observableLocalWallets=function(){return this.subjectwallets},t.prototype.getObservableLocalWallets=function(){var t=this;return new c.Observable((function(e){t.observableLocalWallets().subscribe((function(t){e.next(t)})),t.publishObservableEventWallets()}))},t.prototype.getlocalWallet=function(t){for(var e=0;e<this.wallets.length;e++)if(this.wallets[e]._id===t)return this.wallets[e];return null},t.prototype.getlocalWallets=function(){return E(this.wallets)},t.prototype.refreshLocalWallets=function(){return new Promise((function(t){t(null)}))},t.prototype.addWallet=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("wallets",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateWallet=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("wallets",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteWallet=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("bills",{id_wallet:{$eq:t}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("wallets",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getWallet=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("wallets",t).then((function(t){n(t)}))}))},t.prototype.getWallets=function(){var t=this;return new Promise((function(e,n){t.wallets=new Array,t.vhmongo_firebase.database().getDocs("wallets").then((function(n){t.wallets=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventTaxs=function(){this.subjecttaxs.next(this.taxs)},t.prototype.observableLocalTaxs=function(){return this.subjecttaxs},t.prototype.getObservableLocalTaxs=function(){var t=this;return new c.Observable((function(e){t.observableLocalTaxs().subscribe((function(t){e.next(t)})),t.publishObservableEventTaxs()}))},t.prototype.getlocalTax=function(t){for(var e=0;e<this.taxs.length;e++)if(this.taxs[e]._id===t)return this.taxs[e];return null},t.prototype.getlocalTaxs=function(){return this.taxs},t.prototype.refreshLocalTaxs=function(){return new Promise((function(t){t(null)}))},t.prototype.addTax=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("taxs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateTax=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("taxs",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteTax=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("taxs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getTax=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("taxs",t).then((function(t){n(t)}))}))},t.prototype.getTaxs=function(){var t=this;return new Promise((function(e,n){t.taxs=new Array,t.vhmongo_firebase.database().getDocs("taxs").then((function(n){t.taxs=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventCategorys=function(){this.subjectcategorys.next()},t.prototype.observableLocalCategorys=function(){return this.subjectcategorys},t.prototype.getObservableLocalCategorys=function(t){var e=this;return new c.Observable((function(n){e.observableLocalCategorys().subscribe((function(){n.next(e.getlocalCategorys(t))})),e.publishObservableEventCategorys()}))},t.prototype.getlocalCategory=function(t){for(var e=0;e<this.categorys.length;e++)if(this.categorys[e]._id===t)return Object.assign({},this.categorys[e]);return null},t.prototype.getlocalCategorys=function(t){var e=new Array;return 1===t||2===t||5===t?this.categorys.forEach((function(n){n.type===t&&e.push(Object.assign({},n))})):12===t?this.categorys.forEach((function(t){1!==t.type&&2!==t.type||e.push(Object.assign({},t))})):this.categorys.forEach((function(t){e.push(Object.assign({},t))})),e},t.prototype.refreshLocalCategorys=function(){return new Promise((function(t){t(null)}))},t.prototype.addCategory=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("categorys",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.addCategorys=function(t){var e=this;return new Promise((function(n,o){for(var i=new Array,a=function(n){i[n]=new Promise((function(o){e.vhmongo_firebase.database().addDoc("categorys",t[n]).then((function(t){o(t)}),(function(){o(null)}))}))},s=0;s<t.length;s++)a(s);Promise.all(i).then((function(t){var e=t.filter((function(t){return null!=t}));n(e)}))}))},t.prototype.updateCategory=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("categorys",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteCategory=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("products",{id_category:{$eq:t}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("categorys",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getCategory=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("categorys",t).then((function(t){n(t)}))}))},t.prototype.getCategorys=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("categorys").then((function(n){t.categorys=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventInventorytimes=function(){this.subjectinventorytimes.next(this.inventorytimes)},t.prototype.observableLocalInventorytimes=function(){return this.subjectinventorytimes},t.prototype.getObservableLocalInventorytimes=function(){var t=this;return new c.Observable((function(e){t.observableLocalInventorytimes().subscribe((function(t){e.next(t)})),t.publishObservableEventInventorytimes()}))},t.prototype.getlocalInventorytime=function(t){for(var e=0;e<this.inventorytimes.length;e++)if(this.inventorytimes[e]._id===t)return this.inventorytimes[e];return null},t.prototype.getlocalInventorytimes=function(){return this.inventorytimes},t.prototype.refreshLocalInventorytimes=function(){return new Promise((function(t){t(null)}))},t.prototype.addInventorytime=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("inventorytimes",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateInventorytime=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("inventorytimes",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteInventorytime=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("inventorytimes",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getInventorytime=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("inventorytimes",t).then((function(t){n(t)}))}))},t.prototype.getInventorytimes=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("inventorytimes").then((function(n){t.inventorytimes=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventWarrantys=function(){this.subjectwarrantys.next(this.warrantys)},t.prototype.observableLocalWarrantys=function(){return this.subjectwarrantys},t.prototype.getObservableLocalWarrantys=function(){var t=this;return new c.Observable((function(e){t.observableLocalWarrantys().subscribe((function(t){e.next(t)})),t.publishObservableEventWarrantys()}))},t.prototype.getlocalWarranty=function(t){for(var e=0;e<this.warrantys.length;e++)if(this.warrantys[e]._id===t)return this.warrantys[e];return null},t.prototype.getlocalWarrantys=function(){return this.warrantys},t.prototype.refreshLocalWarrantys=function(){return new Promise((function(t){t(null)}))},t.prototype.addWarranty=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("warrantys",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateWarranty=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("warrantys",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteWarranty=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("warrantys",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getWarranty=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("warrantys",t).then((function(t){n(t)}))}))},t.prototype.getWarrantys=function(){var t=this;return new Promise((function(e,n){t.warrantys=new Array,t.vhmongo_firebase.database().getDocs("warrantys").then((function(n){t.warrantys=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventCustomerClasss=function(){this.subjectcustomer_classs.next(this.customer_classs)},t.prototype.observableLocalCustomerClasss=function(){return this.subjectcustomer_classs},t.prototype.getObservableLocalCustomerClasss=function(){var t=this;return new c.Observable((function(e){t.observableLocalCustomerClasss().subscribe((function(t){e.next(t)})),t.publishObservableEventCustomerClasss()}))},t.prototype.getlocalCustomerClass=function(t){for(var e=0;e<this.customer_classs.length;e++)if(this.customer_classs[e]._id===t)return JSON.parse(JSON.stringify(this.customer_classs[e]));return null},t.prototype.getlocalCustomerClasss=function(){return JSON.parse(JSON.stringify(this.customer_classs))},t.prototype.addCustomerClass=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("customer_classs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateCustomerClass=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("customer_classs",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteCustomerClass=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("customer_classs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.publishObservableEventDiscount_bills=function(){this.subjectdiscount_bills.next(this.discount_bills)},t.prototype.observableLocalDiscount_bills=function(){return this.subjectdiscount_bills},t.prototype.getObservableLocalDiscount_bills=function(){var t=this;return new c.Observable((function(e){t.observableLocalDiscount_bills().subscribe((function(t){e.next(t)})),t.publishObservableEventDiscount_bills()}))},t.prototype.getlocalDiscount_bill=function(t){for(var e=0;e<this.discount_bills.length;e++)if(this.discount_bills[e]._id===t)return JSON.parse(JSON.stringify(this.discount_bills[e]));return null},t.prototype.getlocalDiscount_bills=function(){return JSON.parse(JSON.stringify(this.discount_bills))},t.prototype.addDiscount_bill=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("discount_bills",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateDiscount_bill=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("discount_bills",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteDiscount_bill=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("discount_bills",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.addDiscount_sales=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("discount_saless",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateDiscount_sales=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("discount_saless",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteDiscount_sales=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("discount_saless",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getDiscount_sales=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("discount_saless",t).then((function(t){n(t)}))}))},t.prototype.getDiscount_saless=function(){var t=this;return new Promise((function(e,n){t.discount_saless=new Array,t.vhmongo_firebase.database().getDocs("discount_saless").then((function(n){t.discount_saless=n,e(n)}),(function(t){n(t)}))}))},t.prototype.addCommission=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("commissions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateCommission=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("commissions",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteCommission=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("commissions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getCommission=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("commissions",t).then((function(t){n(t)}))}))},t.prototype.getCommissions=function(){var t=this;return new Promise((function(e,n){t.commissions=new Array,t.vhmongo_firebase.database().getDocs("commissions").then((function(n){t.commissions=n,e(n)}),(function(t){n(t)}))}))},t.prototype.getlocalDelivery=function(t){for(var e=0;e<this.deliverys.length;e++)if(this.deliverys[e]._id===t)return this.deliverys[e];return null},t.prototype.getlocalDeliverys=function(){return this.deliverys},t.prototype.refreshLocalDeliverys=function(){var t=this;return new Promise((function(e){t.getDeliverys().then((function(){e(null)}))}))},t.prototype.addDelivery=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("deliverys",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateDelivery=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("deliverys",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteDelivery=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("deliverys",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getDelivery=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("deliverys",t).then((function(t){n(t)}))}))},t.prototype.getDeliverys=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("deliverys").then((function(n){t.deliverys=n,e(n)}),(function(t){n(t)}))}))},t.prototype.addAdss=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("adss",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateAds=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("adss",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteAds=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("adss",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getAds=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("adss",t).then((function(t){n(t)}))}))},t.prototype.getAdss=function(){var t=this;return new Promise((function(e){t.vhmongo_firebase.database().getDocs("adss").then((function(t){e(t)}))}))},t.prototype.getAdss_byFields=function(t,e,n,o){var i=this;return new Promise((function(a,s){void 0===e&&(e={}),void 0===n&&(n={}),void 0===o&&(o=0),i.vhmongo_firebase.database().getDocsByFields("adss",t,e,n,o).then((function(t){a(t)}),(function(t){s(t)}))}))},t.prototype.getlocalAddress=function(t){for(var e=0;e<this.addresss.length;e++)if(this.addresss[e]._id===t)return this.addresss[e];return null},t.prototype.getlocalAddresss=function(){return this.addresss},t.prototype.refreshLocalAddresss=function(){var t=this;return new Promise((function(e){t.getAddresss().then((function(){e(null)}))}))},t.prototype.addAddress=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("addresss",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateAddress=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("addresss",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteAddress=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("addresss",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getAddress=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("addresss",t).then((function(t){n(t)}))}))},t.prototype.getShippingAhamoveURL=function(){return this.vhmongo_firebase.auth().getShippingCloudURL()+"ahamove"},t.prototype.getShippingGHTKURL=function(){return this.vhmongo_firebase.auth().getShippingCloudURL()+"ghtk"},t.prototype.getAddresss=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("addresss").then((function(n){t.addresss=n,e(n)}),(function(t){n(t)}))}))},t.prototype.getlocalIncoming_group=function(t){for(var e=0;e<this.incoming_groups.length;e++)if(this.incoming_groups[e]._id===t)return Object.assign({},this.incoming_groups[e]);return null},t.prototype.getlocalIncoming_groups=function(){return E(this.incoming_groups)},t.prototype.refreshLocalIncoming_groups=function(){var t=this;return new Promise((function(e){t.getIncoming_groups().then((function(){e(null)}))}))},t.prototype.addIncoming_group=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("incoming_groups",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateIncoming_group=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("incoming_groups",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteIncoming_group=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("bills",{id_incoming_group:{$eq:t}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("incoming_groups",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getIncoming_groups=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("incoming_groups").then((function(n){t.incoming_groups=n,t.incoming_groups=t.vhAlgorithm.sortVietnamesebyASC(t.incoming_groups,"name"),e(t.incoming_groups)}),(function(t){n(t)}))}))},t.prototype.getlocalSpending_group=function(t){for(var e=0;e<this.spending_groups.length;e++)if(this.spending_groups[e]._id===t)return Object.assign({},this.spending_groups[e]);return null},t.prototype.getlocalSpending_groups=function(){return E(this.spending_groups)},t.prototype.refreshLocalSpending_groups=function(){var t=this;return new Promise((function(e){t.getSpending_groups().then((function(){e(null)}))}))},t.prototype.addSpending_group=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("spending_groups",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateSpending_group=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("spending_groups",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteSpending_group=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("bills",{id_spending_group:{$eq:t}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("spending_groups",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getSpending_groups=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("spending_groups").then((function(n){t.spending_groups=n,t.spending_groups=t.vhAlgorithm.sortVietnamesebyASC(t.spending_groups,"name"),e(t.spending_groups)}),(function(t){n(t)}))}))},t.prototype.updateDebtAtBeginningCustomer=function(t,e,n){var o=this;return new Promise((function(i,a){var s=o.getlocalCustomer(t),r={};null!=s[e]?r[e]=s[e]:r[e]={},r[e].debt_beginning=n,o.vhmongo_firebase.database().updateDoc("customers",t,Object.assign({},r)).then((function(t){i(t)}),(function(t){a(t)}))}))},t.prototype.getDebtAtBeginningCustomers_byIDcustomer=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("debt_at_beginning_customers",{id_customer:{$eq:t}},{}).then((function(t){n(t)})).catch((function(t){o(t)}))}))},t.prototype.getDebtAtBeginningCustomers_byIDbranch=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("debt_at_beginning_customers",{id_branch:{$eq:t}},{}).then((function(t){n(t)})).catch((function(t){o(t)}))}))},t.prototype.getDebtAtBeginningCustomers_byIDcustomer_byIDbranch=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().getDocsByFields("debt_at_beginning_customers",{id_customer:{$eq:t},id_branch:{$eq:e}},{}).then((function(t){o(t)})).catch((function(t){i(t)}))}))},t.prototype.getDebtAtBeginningCustomers=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("debt_at_beginning_customers").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.updateDebtAtBeginningSupplier=function(t,e,n){var o=this;return new Promise((function(i,a){var s=o.getlocalSupplier(t),r={};null!=s[e]?r[e]=s[e]:r[e]={},r[e].debt_beginning=n,o.vhmongo_firebase.database().updateDoc("suppliers",t,Object.assign({},r)).then((function(t){i(t)}),(function(t){a(t)}))}))},t.prototype.getDebtAtBeginningSuppliers_byIDsupplier=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("debt_at_beginning_suppliers",{id_supplier:{$eq:t}},{}).then((function(t){n(t)})).catch((function(t){o(t)}))}))},t.prototype.getDebtAtBeginningSuppliers_byIDbranch=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("debt_at_beginning_suppliers",{id_branch:{$eq:t}},{}).then((function(t){n(t)})).catch((function(t){o(t)}))}))},t.prototype.getDebtAtBeginningSuppliers_byIDsupplier_byIDbranch=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().getDocsByFields("debt_at_beginning_suppliers",{id_supplier:{$eq:t},id_branch:{$eq:e}},{}).then((function(t){o(t)})).catch((function(t){i(t)}))}))},t.prototype.getDebtAtBeginningSuppliers=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("debt_at_beginning_suppliers").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.setDefaultBranch=function(t){for(var e=0;e<this.branchs.length;e++)if(this.branchs[e]._id===t){localStorage.setItem(this.vhmongo_firebase.auth().getProjectName()+"_default_branch",JSON.stringify(this.branchs[e]));break}},t.prototype.getDefaultBranch=function(){return 0==this.branchs.length?null:localStorage.getItem(this.vhmongo_firebase.auth().getProjectName()+"_default_branch")?JSON.parse(localStorage.getItem(this.vhmongo_firebase.auth().getProjectName()+"_default_branch")):null},t.prototype.clearDefaultBranch=function(){localStorage.setItem(this.vhmongo_firebase.auth().getProjectName()+"_default_branch",null)},t.prototype.isChains=function(){return 0==this.branchs.length?null:1!=this.branchs.length},t.prototype.publishObservableEventBranchs=function(){this.subjectbranchs.next(this.branchs)},t.prototype.observableLocalBranchs=function(){return this.subjectbranchs},t.prototype.getObservableLocalBranchs=function(){var t=this;return new c.Observable((function(e){t.observableLocalBranchs().subscribe((function(t){e.next(t)})),t.publishObservableEventBranchs()}))},t.prototype.getlocalBranch=function(t){for(var e=0;e<this.branchs.length;e++)if(this.branchs[e]._id===t)return this.branchs[e];return null},t.prototype.getlocalBranchs=function(){var t=new Array;return this.branchs.forEach((function(e){t.push(Object.assign({},e))})),t},t.prototype.refreshLocalBranchs=function(){var t=this;return new Promise((function(e){t.getBranchs().then((function(){e(null)}))}))},t.prototype.addBranch=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("branchs",t).then((function(t){var i=new Array,a=e.getlocalProducts(1),s=Object.assign(Object.assign({},t),{opentime:"8h:00 AM",closetime:"10h:00 PM",img:"",tax_number:""});s.appsetting_name="store_info",s.id_branch=t._id,delete s._id,i.push(e.vhmongo_firebase.database().addDoc("appsettingbranchs",s));for(var r=0;r<a.length;r++)a[r].quantity_branch[t._id]=0,i.push(e.updateProduct(a[r]._id,{quantity_branch:a[r].quantity_branch}));Promise.all(i).then((function(){e.vhAuth.getStore();var i={};i[t._id]={ecommerce_expire:{ecommerce_package:"advanced",ecommerce_package_expire:!1},ecommerce_restriction:{shop_number:4,show_report_duration:92},main_expire:{main_package:"advanced",main_package_expire:!0},main_restriction:{show_report_duration:92,user_number:3}},e.vhmongo_firebase.database().updateDoc_onRootCollectionsFirebase("stores",e.vhmongo_firebase.auth().getDatabase(),Object.assign({},i)).then((function(){n(t)}),(function(t){o(t)}))}))}),(function(t){o(t)}))}))},t.prototype.updateBranch=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("branchs",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteBranch=function(t){var e=this;return new Promise((function(n,o){var i=new Array;i[0]=e.vhmongo_firebase.database().getDocsByFields("wallets",{id_branch:{$eq:t}},{},{},1),i[1]=e.vhmongo_firebase.database().getDocsByFields("bills",{id_branch:{$eq:t}},{},{},1),i[2]=e.vhmongo_firebase.database().getDocsByFields("bills",{id_branch_receive:{$eq:t}},{},{},1),Promise.all(i).then((function(i){0===i[0].length&&0===i[1].length&&0===i[2].length?e.vhmongo_firebase.database().deleteDoc("branchs",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getBranch=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("branchs",t).then((function(t){n(t)}))}))},t.prototype.getBranchs=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("branchs").then((function(n){t.branchs=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventPrinters=function(){this.subjectprinters.next(this.printers)},t.prototype.observableLocalPrinters=function(){return this.subjectprinters},t.prototype.getObservableLocalPrinters=function(){var t=this;return new c.Observable((function(e){t.observableLocalPrinters().subscribe((function(t){e.next(t)})),t.publishObservableEventPrinters()}))},t.prototype.getlocalPrinter=function(t){for(var e=0;e<this.printers.length;e++)if(this.printers[e]._id===t)return this.printers[e];return null},t.prototype.getlocalPrinters=function(){return this.printers},t.prototype.refreshLocalPrinters=function(){return new Promise((function(t,e){t(null)}))},t.prototype.addPrinter=function(t){var e=this;return new Promise((function(n,o){var i=Object.assign({},t);i.uuid=e.hwinfo.uuid,e.vhmongo_firebase.database().addDoc("printers",i).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updatePrinter=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("printers",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deletePrinter=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("printers",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPrinter=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("printers",t).then((function(t){t&&(null==t||delete t.uuid),n(t)}),(function(t){o(t)}))}))},t.prototype.getPrinters=function(){var t=this;return new Promise((function(e){t.vhmongo_firebase.database().getDocsByFields("printers",{uuid:{$eq:t.hwinfo.uuid}},{},{},0).then((function(n){t.printers=new Array,n.length>0&&n.forEach((function(e){null==e||delete e.uuid,t.printers.push(e)})),e(t.printers)}))}))},t.prototype.createBill_Billdetail_51=function(t,e){var n=this;return new Promise((function(o,i){n.sync_code=Math.random().toString(36).substr(2,10).toUpperCase(),t.sync_code=n.sync_code,t.date=new Date,t.bill_type=51,t.bill_code=n.vhAlgorithm.createBillCode(null==t?void 0:t.date),n.vhmongo_firebase.database().addDoc("bills",t).then((function(i){if(i){for(var a=new Array,s=0;s<e.length;s++){var r=e[s];r.id_bill=i._id,t.bill_code&&(r.bill_code=t.bill_code),t.date&&(r.date=t.date),"number"==typeof t.tax&&(r.tax=t.tax),r.bill_type=51,t.id_cashier&&(r.id_cashier=t.id_cashier),t.id_employee&&(r.id_employee=t.id_employee),t.id_customer&&(r.id_customer=t.id_customer),t.id_branch&&(r.id_branch=t.id_branch),a[s]=n.vhmongo_firebase.database().addDoc("vhbill_details",r)}n.vhQuery.asyncPromiseAll(a).then((function(){if(51===t.bill_type){for(var a=JSON.parse(JSON.stringify(e)),s=0;s<a.length;s++)if(!a[s].dev_checked)for(var r=s+1;r<a.length;r++)a[s].id_product===a[r].id_product&&(a[s].quantity=a[s].quantity+a[r].quantity,a[r].dev_checked=!0);n.getPaymentCardCode(a[0].id_payment_card_code).then((function(e){for(var s=0;s<a.length;s++)if(!a[s].dev_checked)for(var r=0;r<e.products.length;r++)e.products[r].id_product===a[s].id_product&&(e.products[r].outquantity=e.products[r].outquantity+a[s].quantity);var l={};l.products=e.products,n.updatePaymentCardCode(e._id,Object.assign(Object.assign({},l),{date_used:t.date,status:4})).then((function(){o(i)}))}),(function(t){console.log("error",t)}))}}))}}))}))},t.prototype.createBill_Billdetail_41=function(t,e){var n=this;return new Promise((function(o,i){n.sync_code=Math.random().toString(36).substr(2,10).toUpperCase(),t.sync_code=n.sync_code,t.date=new Date,t.bill_type=41,t.bill_code=n.vhAlgorithm.createBillCode(null==t?void 0:t.date),n.vhmongo_firebase.database().addDoc("bills",t).then((function(i){if(i){for(var a=new Array,s=0;s<e.length;s++){var r=e[s];r.id_bill=i._id,t.bill_code&&(r.bill_code=t.bill_code),t.date&&(r.date=t.date),"number"==typeof t.tax&&(r.tax=t.tax),r.bill_type=41,t.id_cashier&&(r.id_cashier=t.id_cashier),t.id_employee&&(r.id_employee=t.id_employee),t.id_customer&&(r.id_customer=t.id_customer),t.id_branch&&(r.id_branch=t.id_branch),a[s]=n.vhmongo_firebase.database().addDoc("vhbill_details",r)}n.vhQuery.asyncPromiseAll(a).then((function(){if(41===t.bill_type){for(var a=new Array,s=0;s<e.length;s++)a[s]=n.updateVoucherCode(e[s].id_voucher_code,{date_used:t.date,status:4});n.vhQuery.asyncPromiseAll(a).then((function(){o(i)}))}}))}else o(null)}),(function(t){i(t)}))}))},t.prototype.createBill_Billdetail=function(t,e){var n=this;return new Promise((function(o,i){n.sync_code=Math.random().toString(36).substr(2,10).toUpperCase(),t.sync_code=n.sync_code,t.bill_code=n.vhAlgorithm.createBillCode(null==t?void 0:t.date),n.vhmongo_firebase.database().addDoc("bills",t).then((function(a){if(a){for(var s=new Array,r=0;r<e.length;r++){var l=e[r];l.id_bill=a._id,t.bill_code&&(l.bill_code=t.bill_code),t.date&&(l.date=t.date),"number"==typeof t.tax&&(l.tax=t.tax),"number"==typeof t.bill_type&&(l.bill_type=t.bill_type),t.id_cashier&&(l.id_cashier=t.id_cashier),t.id_employee&&(l.id_employee=t.id_employee),t.id_supplier&&(l.id_supplier=t.id_supplier),t.id_customer&&(l.id_customer=t.id_customer),t.id_inventorytime&&(l.id_inventorytime=t.id_inventorytime),t.id_branch&&(l.id_branch=t.id_branch),s[r]=n.vhmongo_firebase.database().addDoc("vhbill_details",l)}n.vhQuery.asyncPromiseAll(s).then((function(i){if(1===t.bill_type||10===t.bill_type||15===t.bill_type||30===t.bill_type){for(var s=new Array,r=0;r<e.length;r++)if(1===e[r].ptype){if(!e[r].calculated){var l=e[r].quantity;e[r].calculated=!0;for(var c=0;c<e.length;c++)if(e[c].id_product===e[r].id_product&&(e[c].calculated||(l+=e[c].quantity,e[c].calculated=!0)),5===e[c].ptype)for(var u=0;u<e[c].combos.length;u++)e[c].combos[u].id_product===e[r].id_product&&(e[c].combos[u].calculated||(l+=e[c].quantity*e[c].combos[u].quantity,e[c].combos[u].calculated=!0));var d={};null!=(b=n.getlocalProduct(e[r].id_product)).quantity_branch?(d=b.quantity_branch,null!=b.quantity_branch[t.id_branch]?d[t.id_branch]=d[t.id_branch]-l:d[t.id_branch]=-l):d[t.id_branch]=-l;var _=b.quantity-l;s[s.length]=n.vhmongo_firebase.database().updateDoc("products",b._id,{quantity:_,quantity_branch:d})}}else if(5===e[r].ptype){for(var p=0;p<e[r].combos.length;p++)if(!e[r].combos[p].calculated){l=e[r].quantity*e[r].combos[p].quantity;e[r].combos[p].calculated=!0;for(c=0;c<e.length;c++)if(e[c].id_product===e[r].combos[p].id_product&&(e[c].calculated||(l+=e[c].quantity,e[c].calculated=!0)),5===e[c].ptype)for(u=0;u<e[c].combos.length;u++)e[c].combos[u].id_product===e[r].combos[p].id_product&&(e[c].combos[u].calculated||(l+=e[c].quantity*e[c].combos[u].quantity,e[c].combos[u].calculated=!0));d={};null!=(b=n.getlocalProduct(e[r].combos[p].id_product)).quantity_branch?(d=b.quantity_branch,null!=b.quantity_branch[t.id_branch]?d[t.id_branch]=d[t.id_branch]-l:d[t.id_branch]=-l):d[t.id_branch]=-l;_=b.quantity-l;s[s.length]=n.vhmongo_firebase.database().updateDoc("products",b._id,{quantity:_,quantity_branch:d})}}else s[s.length]=new Promise((function(t){t(null)}));n.vhQuery.asyncPromiseAll(s).then((function(){o(a)}))}else if(2===t.bill_type||3===t.bill_type||31===t.bill_type){for(s=new Array,r=0;r<e.length;r++)if(1===e[r].ptype){if(!e[r].calculated){l=e[r].quantity;e[r].calculated=!0;for(c=0;c<e.length;c++)if(e[c].id_product===e[r].id_product&&(e[c].calculated||(l+=e[c].quantity,e[c].calculated=!0)),5===e[c].ptype)for(u=0;u<e[c].combos.length;u++)e[c].combos[u].id_product===e[r].id_product&&(e[c].combos[u].calculated||(l+=e[c].quantity*e[c].combos[u].quantity,e[c].combos[u].calculated=!0));d={};null!=(b=n.getlocalProduct(e[r].id_product)).quantity_branch?(d=b.quantity_branch,null!=b.quantity_branch[t.id_branch]?d[t.id_branch]=d[t.id_branch]+l:d[t.id_branch]=l):d[t.id_branch]=l;_=b.quantity+l;s[s.length]=n.vhmongo_firebase.database().updateDoc("products",b._id,{quantity:_,quantity_branch:d})}}else if(5===e[r].ptype){for(p=0;p<e[r].combos.length;p++)if(!e[r].combos[p].calculated){l=e[r].quantity*e[r].combos[p].quantity;e[r].combos[p].calculated=!0;for(c=0;c<e.length;c++)if(e[c].id_product===e[r].combos[p].id_product&&(e[c].calculated||(l+=e[c].quantity,e[c].calculated=!0)),5===e[c].ptype)for(u=0;u<e[c].combos.length;u++)e[c].combos[u].id_product===e[r].combos[p].id_product&&(e[c].combos[u].calculated||(l+=e[c].quantity*e[c].combos[u].quantity,e[c].combos[u].calculated=!0));var b;d={};null!=(b=n.getlocalProduct(e[r].combos[p].id_product)).quantity_branch?(d=b.quantity_branch,null!=b.quantity_branch[t.id_branch]?d[t.id_branch]=d[t.id_branch]+l:d[t.id_branch]=l):d[t.id_branch]=l;_=b.quantity+l;s[s.length]=n.vhmongo_firebase.database().updateDoc("products",b._id,{quantity:_,quantity_branch:d})}}else s[s.length]=new Promise((function(t){t(null)}));n.vhQuery.asyncPromiseAll(s).then((function(){o(a)}))}else if(9===t.bill_type){s=new Array;var f=function(o){s[o]=new Promise((function(i){var a;if(1===e[o].ptype){var s=n.getlocalProduct(e[o].id_product),r={};null!=s.quantity_branch?(r=s.quantity_branch,null!=s.quantity_branch[t.id_branch]?r[t.id_branch]=r[t.id_branch]+e[o].quantity:r[t.id_branch]=e[o].quantity):r[t.id_branch]=e[o].quantity;var l=s.quantity+e[o].quantity,c={};null!=s[t.id_branch]&&null!=s[t.id_branch].inventory&&(c[t.id_branch]=s[t.id_branch],null===(a=c[t.id_branch])||void 0===a||delete a.inventory),n.vhmongo_firebase.database().updateDoc("products",s._id,Object.assign({quantity:l,quantity_branch:r},c)).then((function(){i(null)}))}else i(null)}))};for(r=0;r<e.length;r++)f(r);n.vhQuery.asyncPromiseAll(s).then((function(){o(a)}))}else 5!==t.bill_type&&6!==t.bill_type&&13!==t.bill_type&&14!==t.bill_type&&16!==t.bill_type&&18!==t.bill_type&&19!==t.bill_type&&20!==t.bill_type&&21!==t.bill_type&&29!==t.bill_type||o(a)}))}else i({message:"Invoice creation failed"})}),(function(t){i(t)}))}))},t.prototype.createBill_Detail=function(t){var e=this;return new Promise((function(n,o){t.id_bill?e.vhmongo_firebase.database().getDoc("bills",t.id_bill).then((function(i){var a=t;i.bill_code&&(a.bill_code=i.bill_code),i.id_branch&&(a.id_branch=i.id_branch),"number"==typeof i.bill_type&&(a.bill_type=i.bill_type),e.vhmongo_firebase.database().addDoc("vhbill_details",a).then((function(t){n(t)}),(function(t){o(t)}))}),(function(t){console.log("error",t)})):console.log("error","không tồn tại id_bill trong data")}))},t.prototype.updateBill_Detail=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("vhbill_details",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteBill_Detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("vhbill_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.saveBill_Billdetail=function(t){var e=this;return new Promise((function(n,o){e.sync_code=Math.random().toString(36).substr(2,10).toUpperCase();var i=e.vhmongo_firebase.database().getDoc("bills",t),a=e.vhmongo_firebase.database().getDocsByFields("vhbill_details",{id_bill:{$eq:t}},{},{},0);Promise.all([i,a]).then((function(o){if(5===o[0].bill_type){for(var i=new Array,a=0;a<o[1].length;a++){var s=Object.assign({},o[1][a]);s.id_bill=o[0]._id,s.bill_type=1,o[0].date&&(s.date=o[0].date),"number"==typeof o[0].tax&&(s.tax=o[0].tax),"number"==typeof o[0].bill_type&&(s.bill_type=1),o[0].id_cashier&&(s.id_cashier=o[0].id_cashier),o[0].id_employee&&(s.id_employee=o[0].id_employee),o[0].id_supplier&&(s.id_supplier=o[0].id_supplier),o[0].id_customer&&(s.id_customer=o[0].id_customer),i[a]=e.vhmongo_firebase.database().updateDoc("vhbill_details",o[1][a]._id,s)}i[o[1].length]=e.vhmongo_firebase.database().updateDoc("bills",t,{bill_type:1,uuid:null,sync_code:e.sync_code}),Promise.all(i).then((function(){for(var t=new Array,i=0;i<o[1].length;i++)if(1===o[1][i].ptype){if(!o[1][i].calculated){var a=o[1][i].quantity;o[1][i].calculated=!0;for(var s=0;s<o[1].length;s++)if(o[1][s].id_product===o[1][i].id_product&&(o[1][s].calculated||(a+=o[1][s].quantity,o[1][s].calculated=!0)),5===o[1][s].ptype)for(var r=0;r<o[1][s].combos.length;r++)o[1][s].combos[r].id_product===o[1][i].id_product&&(o[1][s].combos[r].calculated||(a+=o[1][s].quantity*o[1][s].combos[r].quantity,o[1][s].combos[r].calculated=!0));var l={};null!=(d=e.getlocalProduct(o[1][i].id_product)).quantity_branch?(l=d.quantity_branch,null!=d.quantity_branch[o[0].id_branch]?l[o[0].id_branch]=l[o[0].id_branch]-a:l[o[0].id_branch]=-a):l[o[0].id_branch]=-a;var c=d.quantity-a;t[t.length]=e.vhmongo_firebase.database().updateDoc("products",d._id,{quantity:c,quantity_branch:l})}}else if(5===o[1][i].ptype){for(var u=0;u<o[1][i].combos.length;u++)if(!o[1][i].combos[u].calculated){a=o[1][i].quantity*o[1][i].combos[u].quantity;o[1][i].combos[u].calculated=!0;for(s=0;s<o[1].length;s++)if(o[1][s].id_product===o[1][i].combos[u].id_product&&(o[1][s].calculated||(a+=o[1][s].quantity,o[1][s].calculated=!0)),5===o[1][s].ptype)for(r=0;r<o[1][s].combos.length;r++)o[1][s].combos[r].id_product===o[1][i].combos[u].id_product&&(o[1][s].combos[r].calculated||(a+=o[1][s].quantity*o[1][s].combos[r].quantity,o[1][s].combos[r].calculated=!0));var d;l={};null!=(d=e.getlocalProduct(o[1][i].combos[u].id_product)).quantity_branch?(l=d.quantity_branch,null!=d.quantity_branch[o[0].id_branch]?l[o[0].id_branch]=l[o[0].id_branch]-a:l[o[0].id_branch]=-a):l[o[0].id_branch]=-a;c=d.quantity-a;t[t.length]=e.vhmongo_firebase.database().updateDoc("products",d._id,{quantity:c,quantity_branch:l})}}else t[t.length]=new Promise((function(t){t(null)}));e.vhQuery.asyncPromiseAll(t).then((function(){n(o)}))}))}}))}))},t.prototype.updateBill_Billdetail=function(t,e,n){var o=this;return new Promise((function(i,a){o.sync_code=Math.random().toString(36).substr(2,10).toUpperCase(),e.sync_code=o.sync_code,new Promise((function(n){var i=o.vhmongo_firebase.database().getDoc("bills",t),s=o.vhmongo_firebase.database().getDocsByFields("vhbill_details",{id_bill:{$eq:t}},{},{},0);o.vhQuery.asyncPromiseAll([i,s]).then((function(t){if(1===t[0].bill_type||10===t[0].bill_type||15===t[0].bill_type){for(var i=new Array,s=0;s<t[1].length;s++)i[s]=o.vhmongo_firebase.database().deleteDoc("vhbill_details",t[1][s]._id);o.vhQuery.asyncPromiseAll(i).then((function(){for(var e=new Array,i=0;i<t[1].length;i++)if(1===t[1][i].ptype){if(!t[1][i].calculated){var a=t[1][i].quantity;t[1][i].calculated=!0;for(var s=0;s<t[1].length;s++)if(t[1][s].id_product===t[1][i].id_product&&(t[1][s].calculated||(a+=t[1][s].quantity,t[1][s].calculated=!0)),5===t[1][s].ptype)for(var r=0;r<t[1][s].combos.length;r++)t[1][s].combos[r].id_product===t[1][i].id_product&&(t[1][s].combos[r].calculated||(a+=t[1][s].quantity*t[1][s].combos[r].quantity,t[1][s].combos[r].calculated=!0));var l={};null!=(d=o.getlocalProduct(t[1][i].id_product)).quantity_branch?(l=d.quantity_branch,null!=d.quantity_branch[t[0].id_branch]?l[t[0].id_branch]=l[t[0].id_branch]+a:l[t[0].id_branch]=a):l[t[0].id_branch]=a;var c=d.quantity+a;e[e.length]=o.vhmongo_firebase.database().updateDoc("products",d._id,{quantity:c,quantity_branch:l})}}else if(5===t[1][i].ptype){for(var u=0;u<t[1][i].combos.length;u++)if(!t[1][i].combos[u].calculated){a=t[1][i].quantity*t[1][i].combos[u].quantity;t[1][i].combos[u].calculated=!0;for(s=0;s<t[1].length;s++)if(t[1][s].id_product===t[1][i].combos[u].id_product&&(t[1][s].calculated||(a+=t[1][s].quantity,t[1][s].calculated=!0)),5===t[1][s].ptype)for(r=0;r<t[1][s].combos.length;r++)t[1][s].combos[r].id_product===t[1][i].combos[u].id_product&&(t[1][s].combos[r].calculated||(a+=t[1][s].quantity*t[1][s].combos[r].quantity,t[1][s].combos[r].calculated=!0));var d;l={};null!=(d=o.getlocalProduct(t[1][i].combos[u].id_product)).quantity_branch?(l=d.quantity_branch,null!=d.quantity_branch[t[0].id_branch]?l[t[0].id_branch]=l[t[0].id_branch]+a:l[t[0].id_branch]=a):l[t[0].id_branch]=a;c=d.quantity+a;e[e.length]=o.vhmongo_firebase.database().updateDoc("products",d._id,{quantity:c,quantity_branch:l})}}else e[e.length]=new Promise((function(t){t(null)}));o.vhQuery.asyncPromiseAll(e).then((function(){n(t)}))}))}else if(2===t[0].bill_type||3===t[0].bill_type){for(i=new Array,s=0;s<t[1].length;s++)i[s]=o.vhmongo_firebase.database().deleteDoc("vhbill_details",t[1][s]._id);o.vhQuery.asyncPromiseAll(i).then((function(){for(var e=new Array,i=0;i<t[1].length;i++)if(1===t[1][i].ptype){if(!t[1][i].calculated){var a=t[1][i].quantity;t[1][i].calculated=!0;for(var s=0;s<t[1].length;s++)if(t[1][s].id_product===t[1][i].id_product&&(t[1][s].calculated||(a+=t[1][s].quantity,t[1][s].calculated=!0)),5===t[1][s].ptype)for(var r=0;r<t[1][s].combos.length;r++)t[1][s].combos[r].id_product===t[1][i].id_product&&(t[1][s].combos[r].calculated||(a+=t[1][s].quantity*t[1][s].combos[r].quantity,t[1][s].combos[r].calculated=!0));var l={};null!=(d=o.getlocalProduct(t[1][i].id_product)).quantity_branch?(l=d.quantity_branch,null!=d.quantity_branch[t[0].id_branch]?l[t[0].id_branch]=l[t[0].id_branch]-a:l[t[0].id_branch]=-a):l[t[0].id_branch]=-a;var c=d.quantity-a;e[e.length]=o.vhmongo_firebase.database().updateDoc("products",d._id,{quantity:c,quantity_branch:l})}}else if(5===t[1][i].ptype){for(var u=0;u<t[1][i].combos.length;u++)if(!t[1][i].combos[u].calculated){a=t[1][i].quantity*t[1][i].combos[u].quantity;t[1][i].combos[u].calculated=!0;for(s=0;s<t[1].length;s++)if(t[1][s].id_product===t[1][i].combos[u].id_product&&(t[1][s].calculated||(a+=t[1][s].quantity,t[1][s].calculated=!0)),5===t[1][s].ptype)for(r=0;r<t[1][s].combos.length;r++)t[1][s].combos[r].id_product===t[1][i].combos[u].id_product&&(t[1][s].combos[r].calculated||(a+=t[1][s].quantity*t[1][s].combos[r].quantity,t[1][s].combos[r].calculated=!0));var d;l={};null!=(d=o.getlocalProduct(t[1][i].combos[u].id_product)).quantity_branch?(l=d.quantity_branch,null!=d.quantity_branch[t[0].id_branch]?l[t[0].id_branch]=l[t[0].id_branch]-a:l[t[0].id_branch]=-a):l[t[0].id_branch]=-a;c=d.quantity-a;e[e.length]=o.vhmongo_firebase.database().updateDoc("products",d._id,{quantity:c,quantity_branch:l})}}else e[e.length]=new Promise((function(t){t(null)}));o.vhQuery.asyncPromiseAll(e).then((function(){n(t)}))}))}else if(9===t[0].bill_type){for(i=new Array,s=0;s<t[1].length;s++)i[s]=o.vhmongo_firebase.database().deleteDoc("vhbill_details",t[1][s]._id);o.vhQuery.asyncPromiseAll(i).then((function(){for(var i=new Array,a=function(n){i[n]=new Promise((function(i){var a;if(1===t[1][n].ptype){var s=o.getlocalProduct(t[1][n].id_product),r={};null!=s.quantity_branch?(r=s.quantity_branch,null!=s.quantity_branch[e.id_branch]?r[e.id_branch]=r[e.id_branch]-t[1][n].quantity:r[e.id_branch]=-t[1][n].quantity):r[e.id_branch]=-t[1][n].quantity;var l=s.quantity-t[1][n].quantity,c={};null!=s[e.id_branch]&&null!=s[e.id_branch].inventory&&(c[e.id_branch]=s[e.id_branch],null===(a=c[e.id_branch])||void 0===a||delete a.inventory),o.vhmongo_firebase.database().updateDoc("products",s._id,Object.assign({quantity:l,quantity_branch:r},c)).then((function(){i(null)}))}else i(null)}))},s=0;s<t[1].length;s++)a(s);o.vhQuery.asyncPromiseAll(i).then((function(){n(t)}))}))}else if(5===t[0].bill_type||6===t[0].bill_type||13===t[0].bill_type||14===t[0].bill_type||16===t[0].bill_type||18===t[0].bill_type||19===t[0].bill_type||20===t[0].bill_type||21===t[0].bill_type||29===t[0].bill_type){for(i=new Array,s=0;s<t[1].length;s++)i[s]=o.vhmongo_firebase.database().deleteDoc("vhbill_details",t[1][s]._id);o.vhQuery.asyncPromiseAll(i).then((function(){n(t)}))}else a("Lưu không thành công, vui lòng kiểm tra lại.")}))})).then((function(a){if(1===e.bill_type||10===e.bill_type||15===e.bill_type){var s=new Array;(l=Object.assign({},e)).bill_code=a[0].bill_code,l.id_branch=a[0].id_branch,l.date||(l.date=a[0].date),s[n.length]=o.vhmongo_firebase.database().updateDoc("bills",t,l);for(var r=0;r<n.length;r++){(_=Object.assign({},n[r])).id_bill=t,a[0].bill_code&&(_.bill_code=a[0].bill_code),a[0].id_branch&&(_.id_branch=a[0].id_branch),a[0].date&&(_.date=a[0].date),e.date&&(_.date=e.date),"number"==typeof e.tax&&(_.tax=e.tax),"number"==typeof e.bill_type&&(_.bill_type=e.bill_type),e.id_cashier&&(_.id_cashier=e.id_cashier),e.id_employee&&(_.id_employee=e.id_employee),e.id_supplier&&(_.id_supplier=e.id_supplier),e.id_customer&&(_.id_customer=e.id_customer),e.id_inventorytime&&(_.id_inventorytime=e.id_inventorytime),s[r]=o.vhmongo_firebase.database().addDoc("vhbill_details",_)}o.vhQuery.asyncPromiseAll(s).then((function(){for(var a=new Array,s=0;s<n.length;s++)if(1===n[s].ptype){if(!n[s].calculated){var r=n[s].quantity;n[s].calculated=!0;for(var l=0;l<n.length;l++)if(n[l].id_product===n[s].id_product&&(n[l].calculated||(r+=n[l].quantity,n[l].calculated=!0)),5===n[l].ptype)for(var c=0;c<n[l].combos.length;c++)n[l].combos[c].id_product===n[s].id_product&&(n[l].combos[c].calculated||(r+=n[l].quantity*n[l].combos[c].quantity,n[l].combos[c].calculated=!0));var u={};null!=(p=o.getlocalProduct(n[s].id_product)).quantity_branch?(u=p.quantity_branch,null!=p.quantity_branch[e.id_branch]?u[e.id_branch]=u[e.id_branch]-r:u[e.id_branch]=-r):u[e.id_branch]=-r;var d=p.quantity-r;a[a.length]=o.vhmongo_firebase.database().updateDoc("products",p._id,{quantity:d,quantity_branch:u})}}else if(5===n[s].ptype){for(var _=0;_<n[s].combos.length;_++)if(!n[s].combos[_].calculated){r=n[s].quantity*n[s].combos[_].quantity;n[s].combos[_].calculated=!0;for(l=0;l<n.length;l++)if(n[l].id_product===n[s].combos[_].id_product&&(n[l].calculated||(r+=n[l].quantity,n[l].calculated=!0)),5===n[l].ptype)for(c=0;c<n[l].combos.length;c++)n[l].combos[c].id_product===n[s].combos[_].id_product&&(n[l].combos[c].calculated||(r+=n[l].quantity*n[l].combos[c].quantity,n[l].combos[c].calculated=!0));var p;u={};null!=(p=o.getlocalProduct(n[s].combos[_].id_product)).quantity_branch?(u=p.quantity_branch,null!=p.quantity_branch[e.id_branch]?u[e.id_branch]=u[e.id_branch]-r:u[e.id_branch]=-r):u[e.id_branch]=-r;d=p.quantity-r;a[a.length]=o.vhmongo_firebase.database().updateDoc("products",p._id,{quantity:d,quantity_branch:u})}}else a[a.length]=new Promise((function(t){t(null)}));o.vhQuery.asyncPromiseAll(a).then((function(){i(t)}))}))}else if(2===e.bill_type||3===e.bill_type){s=new Array;(l=Object.assign({},e)).bill_code=a[0].bill_code,l.id_branch=a[0].id_branch,l.date||(l.date=a[0].date),s[n.length]=o.vhmongo_firebase.database().updateDoc("bills",t,l);for(r=0;r<n.length;r++){(_=Object.assign({},n[r])).id_bill=t,a[0].bill_code&&(_.bill_code=a[0].bill_code),a[0].id_branch&&(_.id_branch=a[0].id_branch),a[0].date&&(_.date=a[0].date),e.date&&(_.date=e.date),"number"==typeof e.tax&&(_.tax=e.tax),"number"==typeof e.bill_type&&(_.bill_type=e.bill_type),e.id_cashier&&(_.id_cashier=e.id_cashier),e.id_employee&&(_.id_employee=e.id_employee),e.id_supplier&&(_.id_supplier=e.id_supplier),e.id_customer&&(_.id_customer=e.id_customer),e.id_inventorytime&&(_.id_inventorytime=e.id_inventorytime),s[r]=o.vhmongo_firebase.database().addDoc("vhbill_details",_)}o.vhQuery.asyncPromiseAll(s).then((function(){for(var a=new Array,s=0;s<n.length;s++)if(1===n[s].ptype){if(!n[s].calculated){var r=n[s].quantity;n[s].calculated=!0;for(var l=0;l<n.length;l++)if(n[l].id_product===n[s].id_product&&(n[l].calculated||(r+=n[l].quantity,n[l].calculated=!0)),5===n[l].ptype)for(var c=0;c<n[l].combos.length;c++)n[l].combos[c].id_product===n[s].id_product&&(n[l].combos[c].calculated||(r+=n[l].quantity*n[l].combos[c].quantity,n[l].combos[c].calculated=!0));var u={};null!=(p=o.getlocalProduct(n[s].id_product)).quantity_branch?(u=p.quantity_branch,null!=p.quantity_branch[e.id_branch]?u[e.id_branch]=u[e.id_branch]+r:u[e.id_branch]=+r):u[e.id_branch]=+r;var d=p.quantity+r;a[a.length]=o.vhmongo_firebase.database().updateDoc("products",p._id,{quantity:d,quantity_branch:u})}}else if(5===n[s].ptype){for(var _=0;_<n[s].combos.length;_++)if(!n[s].combos[_].calculated){r=n[s].quantity*n[s].combos[_].quantity;n[s].combos[_].calculated=!0;for(l=0;l<n.length;l++)if(n[l].id_product===n[s].combos[_].id_product&&(n[l].calculated||(r+=n[l].quantity,n[l].calculated=!0)),5===n[l].ptype)for(c=0;c<n[l].combos.length;c++)n[l].combos[c].id_product===n[s].combos[_].id_product&&(n[l].combos[c].calculated||(r+=n[l].quantity*n[l].combos[c].quantity,n[l].combos[c].calculated=!0));var p;u={};null!=(p=o.getlocalProduct(n[s].combos[_].id_product)).quantity_branch?(u=p.quantity_branch,null!=p.quantity_branch[e.id_branch]?u[e.id_branch]=u[e.id_branch]+r:u[e.id_branch]=+r):u[e.id_branch]=+r;d=p.quantity+r;a[a.length]=o.vhmongo_firebase.database().updateDoc("products",p._id,{quantity:d,quantity_branch:u})}}else a[a.length]=new Promise((function(t){t(null)}));o.vhQuery.asyncPromiseAll(a).then((function(){i(t)}))}))}else if(9===e.bill_type){s=new Array;(l=Object.assign({},e)).bill_code=a[0].bill_code,l.id_branch=a[0].id_branch,l.date||(l.date=a[0].date),s[n.length]=o.vhmongo_firebase.database().updateDoc("bills",t,l);for(r=0;r<n.length;r++){(_=Object.assign({},n[r])).id_bill=t,a[0].bill_code&&(_.bill_code=a[0].bill_code),a[0].id_branch&&(_.id_branch=a[0].id_branch),a[0].date&&(_.date=a[0].date),e.date&&(_.date=e.date),"number"==typeof e.tax&&(_.tax=e.tax),"number"==typeof e.bill_type&&(_.bill_type=e.bill_type),e.id_cashier&&(_.id_cashier=e.id_cashier),e.id_employee&&(_.id_employee=e.id_employee),e.id_supplier&&(_.id_supplier=e.id_supplier),e.id_customer&&(_.id_customer=e.id_customer),e.id_inventorytime&&(_.id_inventorytime=e.id_inventorytime),s[r]=o.vhmongo_firebase.database().addDoc("vhbill_details",_)}o.vhQuery.asyncPromiseAll(s).then((function(){for(var a=new Array,s=function(t){a[t]=new Promise((function(i){var a;if(1===n[t].ptype){var s=o.getlocalProduct(n[t].id_product),r={};null!=s.quantity_branch?(r=s.quantity_branch,null!=s.quantity_branch[e.id_branch]?r[e.id_branch]=r[e.id_branch]+n[t].quantity:r[e.id_branch]=n[t].quantity):r[e.id_branch]=n[t].quantity;var l=s.quantity+n[t].quantity,c={};null!=s[e.id_branch]&&null!=s[e.id_branch].inventory&&(c[e.id_branch]=s[e.id_branch],null===(a=c[e.id_branch])||void 0===a||delete a.inventory),o.vhmongo_firebase.database().updateDoc("products",s._id,Object.assign({quantity:l,quantity_branch:r},c)).then((function(){i(null)}))}else i(null)}))},r=0;r<n.length;r++)s(r);o.vhQuery.asyncPromiseAll(a).then((function(){i(t)}))}))}else if(5===e.bill_type||6===e.bill_type||13===e.bill_type||14===e.bill_type||16===e.bill_type||18===e.bill_type||19===e.bill_type||20===e.bill_type||21===e.bill_type||29===e.bill_type){var l;s=new Array;(l=Object.assign({},e)).bill_code=a[0].bill_code,l.id_branch=a[0].id_branch,l.date||(l.date=a[0].date),s[n.length]=o.vhmongo_firebase.database().updateDoc("bills",t,l);for(r=0;r<n.length;r++){(_=Object.assign({},n[r])).id_bill=t,a[0].bill_code&&(_.bill_code=a[0].bill_code),a[0].id_branch&&(_.id_branch=a[0].id_branch),a[0].date&&(_.date=a[0].date),e.date&&(_.date=e.date),"number"==typeof e.tax&&(_.tax=e.tax),"number"==typeof e.bill_type&&(_.bill_type=e.bill_type),e.id_cashier&&(_.id_cashier=e.id_cashier),e.id_employee&&(_.id_employee=e.id_employee),e.id_supplier&&(_.id_supplier=e.id_supplier),e.id_customer&&(_.id_customer=e.id_customer),e.id_inventorytime&&(_.id_inventorytime=e.id_inventorytime),s[r]=o.vhmongo_firebase.database().addDoc("vhbill_details",_)}o.vhQuery.asyncPromiseAll(s).then((function(){i(t)}))}else if(3031===e.bill_type){var c=new Array,u=new Array,d=Object.assign({},a[0]);d.bill_type=30,u[n.length]=o.vhmongo_firebase.database().updateDoc("bills",t,d);for(r=0;r<n.length;r++){var _;(_=Object.assign({},n[r])).id_bill=t,a[0].bill_code&&(_.bill_code=a[0].bill_code),a[0].date&&(_.date=a[0].date),a[0].id_branch&&(_.id_branch=a[0].id_branch),"number"==typeof e.tax&&(_.tax=e.tax),_.bill_type=30,e.id_cashier&&(_.id_cashier=e.id_cashier),e.id_employee&&(_.id_employee=e.id_employee),e.id_supplier&&(_.id_supplier=e.id_supplier),e.id_customer&&(_.id_customer=e.id_customer),e.id_inventorytime&&(_.id_inventorytime=e.id_inventorytime),u[r]=o.vhmongo_firebase.database().addDoc("vhbill_details",_)}o.vhQuery.asyncPromiseAll(u).then((function(){for(var t=new Array,i=0;i<n.length;i++)if(1===n[i].ptype){if(!n[i].calculated){var a=n[i].quantity;n[i].calculated=!0;for(var s=0;s<n.length;s++)if(n[s].id_product===n[i].id_product&&(n[s].calculated||(a+=n[s].quantity,n[s].calculated=!0)),5===n[s].ptype)for(var r=0;r<n[s].combos.length;r++)n[s].combos[r].id_product===n[i].id_product&&(n[s].combos[r].calculated||(a+=n[s].quantity*n[s].combos[r].quantity,n[s].combos[r].calculated=!0));var l={};null!=(_=o.getlocalProduct(n[i].id_product)).quantity_branch?(l=_.quantity_branch,null!=_.quantity_branch[e.id_branch]?l[e.id_branch]=l[e.id_branch]-a:l[e.id_branch]=-a):l[e.id_branch]=-a;var u=_.quantity-a;t[t.length]=o.vhmongo_firebase.database().updateDoc("products",_._id,{quantity:u,quantity_branch:l})}}else if(5===n[i].ptype){for(var d=0;d<n[i].combos.length;d++)if(!n[i].combos[d].calculated){a=n[i].quantity*n[i].combos[d].quantity;n[i].combos[d].calculated=!0;for(s=0;s<n.length;s++)if(n[s].id_product===n[i].combos[d].id_product&&(n[s].calculated||(a+=n[s].quantity,n[s].calculated=!0)),5===n[s].ptype)for(r=0;r<n[s].combos.length;r++)n[s].combos[r].id_product===n[i].combos[d].id_product&&(n[s].combos[r].calculated||(a+=n[s].quantity*n[s].combos[r].quantity,n[s].combos[r].calculated=!0));var _;l={};null!=(_=o.getlocalProduct(n[i].combos[d].id_product)).quantity_branch?(l=_.quantity_branch,null!=_.quantity_branch[e.id_branch]?l[e.id_branch]=l[e.id_branch]-a:l[e.id_branch]=-a):l[e.id_branch]=-a;u=_.quantity-a;t[t.length]=o.vhmongo_firebase.database().updateDoc("products",_._id,{quantity:u,quantity_branch:l})}}else t[t.length]=new Promise((function(t){t(null)}));c[0]=o.vhQuery.asyncPromiseAll(t)}));var p=new Array,b=Object.assign({},e);null==b||delete b.id_branch_receive,b.bill_type=31,b.bill_code=a[0].bill_code,b.id_branch=a[0].id_branch_receive,b.id_branch_send=a[0].id_branch,b.date=a[0].date,o.vhmongo_firebase.database().addDoc("bills",b).then((function(t){for(var i=0;i<n.length;i++){var s=Object.assign({},n[i]);s.id_bill=t._id,a[0].bill_code&&(s.bill_code=a[0].bill_code),a[0].date&&(s.date=a[0].date),a[0].id_branch&&(s.id_branch=a[0].id_branch_receive),"number"==typeof e.tax&&(s.tax=e.tax),s.bill_type=31,e.id_cashier&&(s.id_cashier=e.id_cashier),e.id_employee&&(s.id_employee=e.id_employee),e.id_supplier&&(s.id_supplier=e.id_supplier),e.id_customer&&(s.id_customer=e.id_customer),e.id_inventorytime&&(s.id_inventorytime=e.id_inventorytime),p[i]=o.vhmongo_firebase.database().addDoc("vhbill_details",s)}o.vhQuery.asyncPromiseAll(p).then((function(){for(var t=new Array,i=0;i<n.length;i++)if(1===n[i].ptype){if(!n[i].calculated){var a=n[i].quantity;n[i].calculated=!0;for(var s=0;s<n.length;s++)if(n[s].id_product===n[i].id_product&&(n[s].calculated||(a+=n[s].quantity,n[s].calculated=!0)),5===n[s].ptype)for(var r=0;r<n[s].combos.length;r++)n[s].combos[r].id_product===n[i].id_product&&(n[s].combos[r].calculated||(a+=n[s].quantity*n[s].combos[r].quantity,n[s].combos[r].calculated=!0));var l={};null!=(_=o.getlocalProduct(n[i].id_product)).quantity_branch?(l=_.quantity_branch,null!=_.quantity_branch[e.id_branch]?l[e.id_branch]=l[e.id_branch]+a:l[e.id_branch]=+a):l[e.id_branch]=+a;var u=_.quantity+a;t[t.length]=o.vhmongo_firebase.database().updateDoc("products",_._id,{quantity:u,quantity_branch:l})}}else if(5===n[i].ptype){for(var d=0;d<n[i].combos.length;d++)if(!n[i].combos[d].calculated){a=n[i].quantity*n[i].combos[d].quantity;n[i].combos[d].calculated=!0;for(s=0;s<n.length;s++)if(n[s].id_product===n[i].combos[d].id_product&&(n[s].calculated||(a+=n[s].quantity,n[s].calculated=!0)),5===n[s].ptype)for(r=0;r<n[s].combos.length;r++)n[s].combos[r].id_product===n[i].combos[d].id_product&&(n[s].combos[r].calculated||(a+=n[s].quantity*n[s].combos[r].quantity,n[s].combos[r].calculated=!0));var _;l={};null!=(_=o.getlocalProduct(n[i].combos[d].id_product)).quantity_branch?(l=_.quantity_branch,null!=_.quantity_branch[e.id_branch]?l[e.id_branch]=l[e.id_branch]+a:l[e.id_branch]=a):l[e.id_branch]=a;u=_.quantity+a;t[t.length]=o.vhmongo_firebase.database().updateDoc("products",_._id,{quantity:u,quantity_branch:l})}}else t[t.length]=new Promise((function(t){t(null)}));c[1]=o.vhQuery.asyncPromiseAll(t)}))}),(function(t){console.log("error",t)})),o.vhQuery.asyncPromiseAll(c).then((function(){i(t)}))}}),(function(t){return a(t)}))}))},t.prototype.deleteBill_Billdetail=function(t){var e=this;return new Promise((function(n,o){var i=e.vhmongo_firebase.database().getDoc("bills",t),a=e.vhmongo_firebase.database().getDocsByFields("vhbill_details",{id_bill:{$eq:t}},{},{},0);e.vhQuery.asyncPromiseAll([i,a]).then((function(i){var a=new Array;if(!i[0])return o({message:"id_bill "+t+" không tồn tại"});if(1===i[0].bill_type){for(var s=0;s<i[1].length;s++)a[s]=e.vhmongo_firebase.database().deleteDoc("vhbill_details",i[1][s]._id);a[i[1].length]=e.vhmongo_firebase.database().deleteDoc("bills",t),null!=i[0].id_shop&&null!=i[0].order_number_ecommerce&&e.vhmongo_firebase.database().updateDoc(i[0].id_shop,i[0].order_number_ecommerce,{id_bill_delivered_goods:null})}else if(2===i[0].bill_type){for(s=0;s<i[1].length;s++)a[s]=e.vhmongo_firebase.database().deleteDoc("vhbill_details",i[1][s]._id);a[i[1].length]=e.vhmongo_firebase.database().deleteDoc("bills",t)}else if(3===i[0].bill_type){for(s=0;s<i[1].length;s++)a[s]=e.vhmongo_firebase.database().deleteDoc("vhbill_details",i[1][s]._id);a[i[1].length]=e.vhmongo_firebase.database().deleteDoc("bills",t),null!=i[0].id_shop&&null!=i[0].order_number_ecommerce&&e.vhmongo_firebase.database().updateDoc(i[0].id_shop,i[0].order_number_ecommerce,{id_bill_received_goods:null})}else if(10===i[0].bill_type){for(s=0;s<i[1].length;s++)a[s]=e.vhmongo_firebase.database().deleteDoc("vhbill_details",i[1][s]._id);a[i[1].length]=e.vhmongo_firebase.database().deleteDoc("bills",t)}else if(15===i[0].bill_type){for(s=0;s<i[1].length;s++)a[s]=e.vhmongo_firebase.database().deleteDoc("vhbill_details",i[1][s]._id);a[i[1].length]=e.vhmongo_firebase.database().deleteDoc("bills",t)}else if(9===i[0].bill_type){for(s=0;s<i[1].length;s++)a[s]=e.vhmongo_firebase.database().deleteDoc("vhbill_details",i[1][s]._id);a[i[1].length]=e.vhmongo_firebase.database().deleteDoc("bills",t)}else{if(5!==i[0].bill_type&&6!==i[0].bill_type&&13!==i[0].bill_type&&14!==i[0].bill_type&&16!==i[0].bill_type&&18!==i[0].bill_type&&19!==i[0].bill_type&&20!==i[0].bill_type&&21!==i[0].bill_type&&29!==i[0].bill_type)return 7===i[0].bill_type||8===i[0].bill_type||11===i[0].bill_type||12===i[0].bill_type?o({message:"Loại bill_type "+i[0].bill_type+"này không phát sinh bill_detail dùng hàm deleteBill xóa"}):o({message:"Loại bill_type "+i[0].bill_type+" này không thể xóa hoặc liên hệ anh Huy"});for(s=0;s<i[1].length;s++)a[s]=e.vhmongo_firebase.database().deleteDoc("vhbill_details",i[1][s]._id);a[i[1].length]=e.vhmongo_firebase.database().deleteDoc("bills",t)}1===i[0].bill_type||10===i[0].bill_type||15===i[0].bill_type?e.vhQuery.asyncPromiseAll(a).then((function(){for(var t=new Array,o=0;o<i[1].length;o++)if(1===i[1][o].ptype){if(!i[1][o].calculated){var a=i[1][o].quantity;i[1][o].calculated=!0;for(var s=0;s<i[1].length;s++)if(i[1][s].id_product===i[1][o].id_product&&(i[1][s].calculated||(a+=i[1][s].quantity,i[1][s].calculated=!0)),5===i[1][s].ptype)for(var r=0;r<i[1][s].combos.length;r++)i[1][s].combos[r].id_product===i[1][o].id_product&&(i[1][s].combos[r].calculated||(a+=i[1][s].quantity*i[1][s].combos[r].quantity,i[1][s].combos[r].calculated=!0));var l={};null!=(d=e.getlocalProduct(i[1][o].id_product)).quantity_branch?(l=d.quantity_branch,null!=d.quantity_branch[i[0].id_branch]?l[i[0].id_branch]=l[i[0].id_branch]+a:l[i[0].id_branch]=a):l[i[0].id_branch]=a;var c=d.quantity+a;t[t.length]=e.vhmongo_firebase.database().updateDoc("products",d._id,{quantity:c,quantity_branch:l})}}else if(5===i[1][o].ptype){for(var u=0;u<i[1][o].combos.length;u++)if(!i[1][o].combos[u].calculated){a=i[1][o].quantity*i[1][o].combos[u].quantity;i[1][o].combos[u].calculated=!0;for(s=0;s<i[1].length;s++)if(i[1][s].id_product===i[1][o].combos[u].id_product&&(i[1][s].calculated||(a+=i[1][s].quantity,i[1][s].calculated=!0)),5===i[1][s].ptype)for(r=0;r<i[1][s].combos.length;r++)i[1][s].combos[r].id_product===i[1][o].combos[u].id_product&&(i[1][s].combos[r].calculated||(a+=i[1][s].quantity*i[1][s].combos[r].quantity,i[1][s].combos[r].calculated=!0));var d;l={};null!=(d=e.getlocalProduct(i[1][o].combos[u].id_product)).quantity_branch?(l=d.quantity_branch,null!=d.quantity_branch[i[0].id_branch]?l[i[0].id_branch]=l[i[0].id_branch]+a:l[i[0].id_branch]=a):l[i[0].id_branch]=a;c=d.quantity+a;t[t.length]=e.vhmongo_firebase.database().updateDoc("products",d._id,{quantity:c,quantity_branch:l})}}else t[t.length]=new Promise((function(t){t(null)}));e.vhQuery.asyncPromiseAll(t).then((function(){n(null)}))})):2===i[0].bill_type||3===i[0].bill_type?e.vhQuery.asyncPromiseAll(a).then((function(){for(var t=new Array,o=0;o<i[1].length;o++)if(1===i[1][o].ptype){if(!i[1][o].calculated){var a=i[1][o].quantity;i[1][o].calculated=!0;for(var s=0;s<i[1].length;s++)if(i[1][s].id_product===i[1][o].id_product&&(i[1][s].calculated||(a+=i[1][s].quantity,i[1][s].calculated=!0)),5===i[1][s].ptype)for(var r=0;r<i[1][s].combos.length;r++)i[1][s].combos[r].id_product===i[1][o].id_product&&(i[1][s].combos[r].calculated||(a+=i[1][s].quantity*i[1][s].combos[r].quantity,i[1][s].combos[r].calculated=!0));var l={};null!=(d=e.getlocalProduct(i[1][o].id_product)).quantity_branch?(l=d.quantity_branch,null!=d.quantity_branch[i[0].id_branch]?l[i[0].id_branch]=l[i[0].id_branch]-a:l[i[0].id_branch]=-a):l[i[0].id_branch]=-a;var c=d.quantity-a;t[t.length]=e.vhmongo_firebase.database().updateDoc("products",d._id,{quantity:c,quantity_branch:l})}}else if(5===i[1][o].ptype){for(var u=0;u<i[1][o].combos.length;u++)if(!i[1][o].combos[u].calculated){a=i[1][o].quantity*i[1][o].combos[u].quantity;i[1][o].combos[u].calculated=!0;for(s=0;s<i[1].length;s++)if(i[1][s].id_product===i[1][o].combos[u].id_product&&(i[1][s].calculated||(a+=i[1][s].quantity,i[1][s].calculated=!0)),5===i[1][s].ptype)for(r=0;r<i[1][s].combos.length;r++)i[1][s].combos[r].id_product===i[1][o].combos[u].id_product&&(i[1][s].combos[r].calculated||(a+=i[1][s].quantity*i[1][s].combos[r].quantity,i[1][s].combos[r].calculated=!0));var d;l={};null!=(d=e.getlocalProduct(i[1][o].combos[u].id_product)).quantity_branch?(l=d.quantity_branch,null!=d.quantity_branch[i[0].id_branch]?l[i[0].id_branch]=l[i[0].id_branch]-a:l[i[0].id_branch]=-a):l[i[0].id_branch]=-a;c=d.quantity-a;t[t.length]=e.vhmongo_firebase.database().updateDoc("products",d._id,{quantity:c,quantity_branch:l})}}else t[t.length]=new Promise((function(t){t(null)}));e.vhQuery.asyncPromiseAll(t).then((function(){n(null)}))})):9===i[0].bill_type?e.vhQuery.asyncPromiseAll(a).then((function(){for(var t=new Array,o=function(n){t[n]=new Promise((function(t){var o;if(1===i[1][n].ptype){var a=e.getlocalProduct(i[1][n].id_product),s={};null!=a.quantity_branch?(s=a.quantity_branch,null!=a.quantity_branch[i[0].id_branch]?s[i[0].id_branch]=s[i[0].id_branch]-i[1][n].quantity:s[i[0].id_branch]=-i[1][n].quantity):s[i[0].id_branch]=-i[1][n].quantity;var r=a.quantity-i[1][n].quantity,l={};null!=a[i[0].id_branch]&&null!=a[i[0].id_branch].inventory&&(l[i[0].id_branch]=a[i[0].id_branch],null===(o=l[i[0].id_branch])||void 0===o||delete o.inventory),e.vhmongo_firebase.database().updateDoc("products",a._id,Object.assign({quantity:r,quantity_branch:s},l)).then((function(){t(null)}))}else t(null)}))},a=0;a<i[1].length;a++)o(a);e.vhQuery.asyncPromiseAll(t).then((function(){n(null)}))})):e.vhQuery.asyncPromiseAll(a).then((function(){n(null)}))}),(function(t){console.log("error",t),o(t)}))}))},t.prototype.getBill_details_byId_bill=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("vhbill_details",{id_bill:{$eq:t}},{},{},0).then((function(t){var e=new Array;if(t.length>0)for(var o=0;o<t.length;o++){var i=Object.assign({},t[o]);null==i||delete i.bill_code,null==i||delete i.date,null==i||delete i.tax,null==i||delete i.bill_type,null==i||delete i.id_cashier,null==i||delete i.id_employee,null==i||delete i.id_supplier,null==i||delete i.id_customer,null==i||delete i.id_inventorytime,null==i||delete i.id_branch,e.push(i)}n(e)}),(function(t){o(t)}))}))},t.prototype.getBill_detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("vhbill_details",t).then((function(t){if(t){var e=Object.assign({},t);null==e||delete e.bill_code,null==e||delete e.date,null==e||delete e.tax,null==e||delete e.bill_type,null==e||delete e.id_cashier,null==e||delete e.id_employee,null==e||delete e.id_supplier,null==e||delete e.id_customer,null==e||delete e.id_inventorytime,null==e||delete e.id_branch,n(e)}else n(t)}),(function(t){o(t)}))}))},t.prototype.getBill_details=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("vhbill_details").then((function(t){var n=new Array;if(t.length>0)for(var o=0;o<t.length;o++){var i=Object.assign({},t[o]);null==i||delete i.bill_code,null==i||delete i.date,null==i||delete i.tax,null==i||delete i.bill_type,null==i||delete i.id_cashier,null==i||delete i.id_employee,null==i||delete i.id_supplier,null==i||delete i.id_customer,null==i||delete i.id_inventorytime,null==i||delete i.id_branch,n.push(i)}e(n)}),(function(t){n(t)}))}))},t.prototype.getBill=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("bills",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getBills=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.database().getDocsByFields("bills",t,{},n,o).then((function(t){e(t)})).catch((function(t){a(t)}))}))},t.prototype.getBills_byFields=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.database().getDocsByFields("bills",t,{},n,o).then((function(t){e(t)})).catch((function(t){a(t)}))}))},t.prototype.createBill=function(t){var e=this;return new Promise((function(n,o){e.sync_code=Math.random().toString(36).substr(2,10).toUpperCase(),t.sync_code=e.sync_code,e.vhmongo_firebase.database().addDoc("bills",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateBill=function(t,e){var n=this;return new Promise((function(o,i){n.sync_code=Math.random().toString(36).substr(2,10).toUpperCase(),e.sync_code=n.sync_code,"3334"===(null==e?void 0:e.bill_type)?n.vhmongo_firebase.database().getDoc("bills",t).then((function(a){32===a.bill_type?n.vhmongo_firebase.database().getDoc("bills",t).then((function(a){var s=new Array;s[0]=n.vhmongo_firebase.database().updateDoc("bills",t,{bill_type:33,sync_code:n.sync_code});var r=Object.assign({},e);null==r||delete r.id_branch_receive,r.bill_type=34,r.bill_code=a.bill_code,r.id_branch=a.id_branch_receive,r.id_branch_send=a.id_branch,r.date=a.date,s[1]=n.vhmongo_firebase.database().addDoc("bills",r),Promise.all(s).then((function(){o(!0)})).catch((function(t){i(t)}))})):i("Lưu không thành công, vui lòng kiểm tra lại.")})):n.vhmongo_firebase.database().updateDoc("bills",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteBill=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("bills",t).then((function(i){if(i){var a=void 0;(7===i.bill_type||8===i.bill_type||11===i.bill_type||12===i.bill_type||32===i.bill_type)&&(a=e.vhmongo_firebase.database().deleteDoc("bills",t)),a.then((function(t){return n(t)}))}else o({message:t+" no exist"})}))}))},t.prototype.observableSyncOpeningBill=function(t,e){var n=this;return new c.Observable((function(o){var i=0;n.callbacksyncopeningbill=n.vhmongo_firebase.socketMongoDB().initSyncOpeningBill(t).subscribe((function(a){if(a.exists)if(a.data().sync_code!=n.sync_code)if(a.data().bill_type===e){if(i++){var s=Object.assign(Object.assign({},n.vhmongo_firebase.database().cvtDataFB2MG(a.data())),{_id:a.id});console.log("id_bill",t),o.next({vcode:0,message:"repaired bill by another device",data:s})}}else console.log("id_bill",t),o.next({vcode:1,message:"changed bill_type by another device"});else i++;else console.log("id_bill",t),o.next({vcode:2,message:"deleted bill by unknown device"})}))}))},t.prototype.closeSyncOpeningBill=function(){this.callbacksyncopeningbill.unsubscribe(),this.vhmongo_firebase.socketMongoDB().closeSyncOpeningBill()},t.prototype.createPaymentVnpay=function(t,e,n,o){this.vhmongo_firebase.paymentVNPAY().createPaymentVnpay(t,e,n,o).then((function(t){window.location=t.data}),(function(t){console.log("error",t)}))},t.prototype.createPaymentVnpay_iFrame=function(t,e,n,o){var i=this;return new Promise((function(a,s){i.vhmongo_firebase.paymentVNPAY().Create_Payment_Url_Vnpay_iFrame(t,e,n,o).then((function(t){a(t.data)}),(function(t){s(t)}))}))},t.prototype.createPayment=function(t){var e=this;return new Promise((function(n,o){t.payment_code=e.vhAlgorithm.createPaymentCode(null==t?void 0:t.date),t.id_store=e.vhmongo_firebase.auth().getDatabase(),e.vhmongo_firebase.rootdatabase().addDoc("payments",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updatePayment=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.rootdatabase().updateDoc("payments",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deletePayment=function(t){var e=this;return new Promise((function(n,o){var i={id_payment:{$eq:t}};e.vhmongo_firebase.rootdatabase().getDocsByFields("payment_details",i,{},{},0).then((function(t){if(t.length>0)for(var n=0;n<t.length;n++)e.vhmongo_firebase.rootdatabase().deleteDoc("payment_details",t[n]._id)}),(function(t){console.log(t,t)})),e.vhmongo_firebase.rootdatabase().deleteDoc("payments",t).then((function(t){n(t)}),(function(t){console.log(t,t)}))}))},t.prototype.getPayments=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.rootdatabase().getDocsByFields("payments",t,{},n,o).then((function(t){e(t)}),(function(t){console.log(t,t)}))}))},t.prototype.getPayment=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.rootdatabase().getDoc("payments",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.createPayment_Detail=function(t){var e=this;return new Promise((function(n,o){null!=t.id_payment&&null!=t.id_payment?e.vhmongo_firebase.rootdatabase().getDoc("payments",t.id_payment).then((function(i){var a=t;a.activating=!1,a.invalid=!1,a.date=i.date,i.id_store&&(a.id_store=i.id_store),"number"==typeof i.payment_type&&(a.payment_type=i.payment_type),e.vhmongo_firebase.rootdatabase().addDoc("payment_details",a).then((function(t){n(t)}),(function(t){o(t)}))}),(function(t){console.log("error",t)})):console.log("error","không tồn tại id_bill trong data")}))},t.prototype.updatePayment_Detail=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.rootdatabase().updateDoc("payment_details",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.getPayment_details=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.rootdatabase().getDocsByFields("payment_details",t,{},n,o).then((function(t){e(t)}),(function(t){console.log(t,t)}))}))},t.prototype.getPayment_detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.rootdatabase().getDoc("payment_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.deletePayment_Detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.rootdatabase().deleteDoc("payment_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPackage=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.rootdatabase().getDoc("packages",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.publishObservableEventPromotions=function(){this.subjectpromotions.next(this.promotions)},t.prototype.observableLocalPromotions=function(){return this.subjectpromotions},t.prototype.getObservableLocalPromotions=function(){var t=this;return new c.Observable((function(e){t.observableLocalPromotions().subscribe((function(t){e.next(t)})),t.publishObservableEventPromotions()}))},t.prototype.getlocalPromotion=function(t){for(var e=0;e<this.promotions.length;e++)if(this.promotions[e]._id===t)return this.suppliers[e];return null},t.prototype.getlocalPromotions=function(){return this.promotions},t.prototype.refreshLocalPromotions=function(){return new Promise((function(t,e){t(null)}))},t.prototype.addPromotion=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("promotions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updatePromotion=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("promotions",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deletePromotion=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("promotions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPromotion=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("promotions",t).then((function(t){n(t)}))}))},t.prototype.getPromotions=function(){var t=this;return new Promise((function(e){t.vhmongo_firebase.database().getDocs("promotions").then((function(n){t.promotions=n,e(n)}))}))},t.prototype.addPromotion_detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("promotion_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updatePromotion_detail=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("promotion_details",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deletePromotion_detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("promotion_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPromotion_detail=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("promotion_details",t).then((function(t){n(t)}))}))},t.prototype.getPromotion_details=function(){var t=this;return new Promise((function(e){t.vhmongo_firebase.database().getDocs("promotion_details").then((function(t){e(t)}))}))},t.prototype.addPromotion_Promotiondetail=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().addDoc("promotions",t).then((function(t){for(var a=new Array,s=0;s<e.length;s++){var r=e[s];r.id_promotion=t._id,a[s]=n.vhmongo_firebase.database().addDoc("promotion_details",r)}Promise.all(a).then((function(){o(t)})).catch((function(t){i(t)}))}),(function(t){i(t)}))}))},t.prototype.updatePromotion_Promotiondetail=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.database().getDocsByFields("promotion_details",{id_promotion:{$eq:t}},{},{},0).then((function(s){for(var r=new Array,l=0;l<s.length;l++)r[l]=o.vhmongo_firebase.database().deleteDoc("promotion_details",s[l]._id);var c=Object.assign({},e);r[s.length]=o.vhmongo_firebase.database().updateDoc("promotions",t,c);for(l=0;l<n.length;l++){var u=n[l];u.id_promotion=t,r[l+s.length+1]=o.vhmongo_firebase.database().addDoc("promotion_details",u)}Promise.all(r).then((function(){i(!0)})).catch((function(t){a(t)}))})).catch((function(){i(!1)}))}))},t.prototype.deletePromotion_Promotiondetail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("promotion_details",{id_promotion:{$eq:t}},{},{},0).then((function(i){for(var a=new Array,s=0;s<i.length;s++)a[s]=e.vhmongo_firebase.database().deleteDoc("promotion_details",i[s]._id);a[i.length]=e.vhmongo_firebase.database().deleteDoc("promotions",t),Promise.all(a).then((function(){n(!0)})).catch((function(t){o(t)}))})).catch((function(){n(!1)}))}))},t.prototype.getPromotion_details_byId_promotion=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDocsByFields("promotion_details",{id_promotion:{$eq:t}},{},{},0).then((function(t){n(t)})).catch((function(){n(!1)}))}))},t.prototype.checkNewPromotion=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.database().getDocs("promotions").then((function(s){var r=new Array,l=new Array;if(s.length>0){for(var c=0;c<s.length;c++)new Date(t)<new Date(s[c].date_start)?new Date(e)>=new Date(s[c].date_start)&&r.push(s[c]._id):new Date(t)>=new Date(s[c].date_start)&&new Date(t)<=new Date(s[c].date_end)&&r.push(s[c]._id);r.length>0?o.vhmongo_firebase.database().getDocsByFields("promotion_details",{id_promotion:{$in:r}},{},{},0).then((function(t){if(t.length){for(var e=0;e<n.length;e++)for(var o=0;o<t.length;o++)if(n[e]===t[o].id_product){l.push(n[e]);break}i(l)}else i(l)})).catch((function(t){a(t)})):i(l)}else i(l)}),(function(t){console.log("error",t)}))}))},t.prototype.checkOldPromotion=function(t,e,n,o){var i=this;return new Promise((function(a,s){i.vhmongo_firebase.database().getDocs("promotions").then((function(s){var r=new Array,l=new Array;if(s.length>0){for(var c=0;c<s.length;c++)new Date(t)<new Date(s[c].date_start)?new Date(e)>=new Date(s[c].date_start)&&s[c]._id!=o&&r.push(s[c]._id):new Date(t)>=new Date(s[c].date_start)&&new Date(t)<=new Date(s[c].date_end)&&s[c]._id!=o&&r.push(s[c]._id);r.length>0?i.vhmongo_firebase.database().getDocsByFields("promotion_details",{id_promotion:{$in:r}},{},{},0).then((function(t){if(t.length>0){for(var e=0;e<n.length;e++)for(var o=0;o<t.length;o++)if(n[e]===t[o].id_product){l.push(n[e]);break}a(l)}else a(l)}),(function(t){console.log("error",t)})):a(l)}else a(l)}))}))},t.prototype.publishObservableEventAppSettingNameStations=function(){this.subjectappsettingstations.next()},t.prototype.observableLocalAppSettingNameStations=function(){return this.subjectappsettingstations},t.prototype.getObservableLocalAppSettingNameStations=function(){var t=this;return new c.Observable((function(e){t.observableLocalAppSettingNameStations().subscribe((function(){for(var n=new Array,o=0;o<t.appsettingstations.length;o++)n.push(t.appsettingstations[o].appsetting_name);e.next(n)})),t.publishObservableEventAppSettingNameStations()}))},t.prototype.getLocalAppSettingNameStations=function(){for(var t=new Array,e=0;e<this.appsettingstations.length;e++)t.push(this.appsettingstations[e].appsetting_name);return t},t.prototype.getLocalAppSettingNameStation=function(t){for(var e={},n=0;n<this.appsettingstations.length;n++)if(this.appsettingstations[n].appsetting_name===t){delete(e=Object.assign({},this.appsettingstations[n]))._id,delete e.appsetting_name;break}return e},t.prototype.getLocalAppSettingStation=function(t){for(var e=0;e<this.appsettingstations.length;e++)if(this.appsettingstations[e]._id===t)return this.appsettingstations[e];return null},t.prototype.refreshLocalAppSettingNameStations=function(){return new Promise((function(t,e){t(null)}))},t.prototype.getAppSettingStations=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocsByFields("appsettingstations",{uuid:{$eq:t.hwinfo.uuid}},{},{},0).then((function(n){n.length>0&&(t.appsettingstations=n),e(null)}),(function(t){n(t)}))}))},t.prototype.updateAppSettingNameStation=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().getDocsByFields("appsettingstations",{appsetting_name:{$eq:t},uuid:{$eq:n.hwinfo.uuid}},{},{},0).then((function(a){if(a.length>0)n.vhmongo_firebase.database().updateDoc("appsettingstations",a[0]._id,e).then((function(t){o(t)}),(function(t){i(t)}));else{var s=Object.assign({},e);s.appsetting_name=t,s.uuid=n.hwinfo.uuid,n.vhmongo_firebase.database().addDoc("appsettingstations",s).then((function(){o(!0)}),(function(t){i(t)}))}}))}))},t.prototype.deleteAppSettingNameStation=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("appsettingstations",{appsetting_name:{$eq:t},uuid:{$eq:e.hwinfo.uuid}},{},{},0).then((function(t){t.length>0?e.vhmongo_firebase.database().deleteDoc("appsettingstations",t[0]._id).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}))}))},t.prototype.publishObservableEventAppSettingNameBranchs=function(){this.subjectappsettingbranchs.next()},t.prototype.observableLocalAppSettingNameBranchs=function(){return this.subjectappsettingbranchs},t.prototype.getObservableLocalAppSettingNameBranchs=function(){var t=this;return new c.Observable((function(e){t.observableLocalAppSettingNameBranchs().subscribe((function(){for(var n=new Array,o=0;o<t.appsettingbranchs.length;o++)n.push(t.appsettingbranchs[o].appsetting_name);e.next(n)})),t.publishObservableEventAppSettingNameBranchs()}))},t.prototype.getLocalAppSettingNameBranchs=function(){for(var t=new Array,e=0;e<this.appsettingbranchs.length;e++)t.push(this.appsettingbranchs[e].appsetting_name);return t},t.prototype.getLocalAppSettingNameBranch=function(t){for(var e={},n=0;n<this.appsettingbranchs.length;n++)if(this.appsettingbranchs[n].appsetting_name===t){delete(e=Object.assign({},this.appsettingbranchs[n]))._id,delete e.appsetting_name,delete e.id_branch;break}return e},t.prototype.getLocalAppSettingBranch=function(t){for(var e=0;e<this.appsettingbranchs.length;e++)if(this.appsettingbranchs[e]._id==t)return this.appsettingbranchs[e];return null},t.prototype.updateAppSettingNameBranch=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().getDocsByFields("appsettingbranchs",{appsetting_name:{$eq:t},id_branch:{$eq:n.getDefaultBranch()._id}},{},{},1).then((function(a){if(a.length>0)n.vhmongo_firebase.database().updateDoc("appsettingbranchs",a[0]._id,e).then((function(t){o(t)}),(function(t){i(t)}));else{var s=Object.assign({},e);s.appsetting_name=t,s.id_branch=n.getDefaultBranch()._id,n.vhmongo_firebase.database().addDoc("appsettingbranchs",s).then((function(){o(!0)}),(function(t){i(t)}))}}))}))},t.prototype.deleteAppSettingNameBranch=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("appsettingbranchs",{appsetting_name:{$eq:t},id_branch:{$eq:e.getDefaultBranch()._id}},{},{},0).then((function(t){t.length>0?e.vhmongo_firebase.database().deleteDoc("appsettingbranchs",t[0]._id).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}))}))},t.prototype.getReportSales_Categorys_byCategorys=function(t,e,n,o,i){var a=this;return console.log("type",o),o="all"===n?12:this.getlocalCategory(n).type,new Promise((function(s,r){var l,c,u={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};1===o?(c=1,l=[1,5]):2===o?(c=2,l=[2,5]):5===o?(c=5,l=[5]):12===o&&(c=12,l=[1,2,5]);var d,_=new Array,p=new Array;"all"===n?_=a.getlocalCategorys(c):_.push(a.getlocalCategory(n));for(var b=[1,3,15],f=0;f<b.length;f++)d="all"===i||void 0===i?{date:{$gte:t,$lte:e},ptype:{$in:l},bill_type:{$eq:b[f]}}:{date:{$gte:t,$lte:e},ptype:{$in:l},bill_type:{$eq:b[f]},id_branch:{$eq:i}},p[f]=a.vhmongo_firebase.database().getDocsByFields("vhbill_details",d,{},{date:1},0);_.length>0?Promise.all(p).then((function(t){var e=t.flat();if(e.length>0)for(var n=0;n<_.length;n++){for(var i=!1,a=Object.assign({},_[n]),r={id_category:a._id,name:a.name,sales_btax:0,sales_atax:0,quantity:0},l=0;l<e.length;l++)if(3==e[l].bill_type){if(1===o||2===o)if(5===e[l].ptype){if(null!=e[l].combos)for(var c=0;c<e[l].combos.length;c++)_[n]._id===e[l].combos[c].id_category&&(r.quantity=r.quantity-e[l].combos[c].quantity*e[l].quantity,r.sales_btax=r.sales_btax-e[l].combos[c].price*e[l].combos[c].quantity*e[l].quantity,r.sales_atax=r.sales_atax-e[l].combos[c].price*e[l].combos[c].quantity*e[l].quantity*(1+e[l].tax/100))}else _[n]._id===e[l].id_category&&(i=!0,r.quantity=r.quantity-e[l].quantity,r.sales_btax=r.sales_btax-e[l].price*e[l].quantity,r.sales_atax=r.sales_atax-e[l].price*e[l].quantity*(1+e[l].tax/100));else if(5===o){if(5===e[l].ptype&&null!=e[l].combos)for(c=0;c<e[l].combos.length;c++)_[n]._id===e[l].combos[c].id_category&&(r.quantity=r.quantity-e[l].combos[c].quantity*e[l].quantity,r.sales_btax=r.sales_btax-e[l].combos[c].price*e[l].combos[c].quantity*e[l].quantity,r.sales_atax=r.sales_atax-e[l].combos[c].price*e[l].combos[c].quantity*e[l].quantity*(1+e[l].tax/100))}else if(12===o)if(1===e[l].ptype)1===_[n].type&&_[n]._id===e[l].id_category&&(i=!0,r.quantity=r.quantity-e[l].quantity,r.sales_btax=r.sales_btax-e[l].price*e[l].quantity,r.sales_atax=r.sales_atax-e[l].price*e[l].quantity*(1+e[l].tax/100));else if(2===e[l].ptype)_[n]._id===e[l].id_category&&(i=!0,r.quantity=r.quantity-e[l].quantity,r.sales_btax=r.sales_btax-e[l].price*e[l].quantity,r.sales_atax=r.sales_atax-e[l].price*e[l].quantity*(1+e[l].tax/100));else if(5===e[l].ptype)for(c=0;c<e[l].combos.length;c++)_[n]._id===e[l].combos[c].id_category&&(i=!0,r.quantity=r.quantity-e[l].combos[c].quantity*e[l].quantity,r.sales_btax=r.sales_btax-e[l].combos[c].price*e[l].combos[c].quantity*e[l].quantity,r.sales_atax=r.sales_atax-e[l].combos[c].price*e[l].combos[c].quantity*e[l].quantity*(1+e[l].tax/100))}else if(1===o||2===o)if(5===e[l].ptype){if(null!=e[l].combos)for(c=0;c<e[l].combos.length;c++)_[n]._id===e[l].combos[c].id_category&&(r.quantity=r.quantity+e[l].combos[c].quantity*e[l].quantity,r.sales_btax=r.sales_btax+e[l].combos[c].price*e[l].combos[c].quantity*e[l].quantity,r.sales_atax=r.sales_atax+e[l].combos[c].price*e[l].combos[c].quantity*e[l].quantity*(1+e[l].tax/100))}else _[n]._id===e[l].id_category&&(i=!0,r.quantity=r.quantity+e[l].quantity,r.sales_btax=r.sales_btax+e[l].price*e[l].quantity,r.sales_atax=r.sales_atax+e[l].price*e[l].quantity*(1+e[l].tax/100));else if(5===o){if(5===e[l].ptype&&null!=e[l].combos)for(c=0;c<e[l].combos.length;c++)_[n]._id===e[l].combos[c].id_category&&(r.quantity=r.quantity+e[l].combos[c].quantity*e[l].quantity,r.sales_btax=r.sales_btax+e[l].combos[c].price*e[l].combos[c].quantity*e[l].quantity,r.sales_atax=r.sales_atax+e[l].combos[c].price*e[l].combos[c].quantity*e[l].quantity*(1+e[l].tax/100))}else if(12===o)if(1===e[l].ptype)1===_[n].type&&_[n]._id===e[l].id_category&&(i=!0,r.quantity=r.quantity+e[l].quantity,r.sales_btax=r.sales_btax+e[l].price*e[l].quantity,r.sales_atax=r.sales_atax+e[l].price*e[l].quantity*(1+e[l].tax/100));else if(2===e[l].ptype)_[n]._id===e[l].id_category&&(i=!0,r.quantity=r.quantity+e[l].quantity,r.sales_btax=r.sales_btax+e[l].price*e[l].quantity,r.sales_atax=r.sales_atax+e[l].price*e[l].quantity*(1+e[l].tax/100));else if(5===e[l].ptype){console.log("vhbill_details[j]",e[l]);for(c=0;c<e[l].combos.length;c++)_[n]._id===e[l].combos[c].id_category&&(console.log("data",r),i=!0,r.quantity=r.quantity+e[l].combos[c].quantity*e[l].quantity,r.sales_btax=r.sales_btax+e[l].combos[c].price*e[l].combos[c].quantity*e[l].quantity,r.sales_atax=r.sales_atax+e[l].combos[c].price*e[l].combos[c].quantity*e[l].quantity*(1+e[l].tax/100))}i&&(r.sales_atax=Math.round(1e6*r.sales_atax)/1e6,null!=r.subs&&r.subs.forEach((function(t){t.sales_atax=Math.round(1e6*t.sales_atax)/1e6})),null!=r.combos&&r.combos.forEach((function(t){t.sales_atax=Math.round(1e6*t.sales_atax)/1e6})),u.quantity=u.quantity+r.quantity,u.sales_btax=u.sales_btax+r.sales_btax,u.sales_atax=u.sales_atax+r.sales_atax,r.index=u.size+1,u.docs.push(r),u.size++,u.empty=!1)}console.log("getReportSales_Categorys_byCategorys"),s(u)})):s(u)}))},t.prototype.getReportSales_Categorys_byProducts=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l,c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0},u=i.getlocalProducts().filter((function(t){if(t.id_category===n)return!0})),d=i.getlocalCategory(n).type;1===d?r=[1,5]:2===d?r=[2,5]:5===d&&(r=[5]);for(var _=new Array,p=[1,3,15],b=0;b<p.length;b++)l="all"===o||void 0===o?{date:{$gte:t,$lte:e},ptype:{$in:r},bill_type:{$eq:p[b]}}:{date:{$gte:t,$lte:e},ptype:{$in:r},bill_type:{$eq:p[b]},id_branch:{$eq:o}},_[b]=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",l,{},{date:1},0);u.length>0?Promise.all(_).then((function(t){var e,n=t.flat();if(n.length>0)for(var o=0;o<u.length;o++){var i=!1,s=Object.assign({},u[o]),r={id_product:s._id,name:s.name,unit:s.unit,barcode:s.barcode,img:s.img,sales_btax:0,sales_atax:0,quantity:0};if(null!=s.combos){r.combos=new Array;for(var l=0;l<s.combos.length;l++){var _={id_product:s.combos[l].id_product,name:null===(e=s.combos[l])||void 0===e?void 0:e.name,sales_btax:0,sales_atax:0,quantity:0};null!=s.combos[l].id_subproduct&&(_.id_subproduct=s.combos[l].id_subproduct),r.combos.push(_)}}for(var p=0;p<n.length;p++)if(3==n[p].bill_type){if(1===d||2===d){if(1===n[p].ptype||2===n[p].ptype)u[o]._id===n[p].id_product&&(i=!0,r.quantity=r.quantity-n[p].quantity,r.sales_btax=r.sales_btax-n[p].price*n[p].quantity,r.sales_atax=r.sales_atax-n[p].price*n[p].quantity*(1+n[p].tax/100));else if(5===n[p].ptype)for(var b=0;b<n[p].combos.length;b++)u[o]._id===n[p].combos[b].id_product&&(i=!0,r.quantity=r.quantity-n[p].combos[b].quantity*n[p].quantity,r.sales_btax=r.sales_btax-n[p].combos[b].price*n[p].combos[b].quantity*n[p].quantity,r.sales_atax=r.sales_atax-n[p].combos[b].price*n[p].combos[b].quantity*n[p].quantity*(1+n[p].tax/100))}else if(5===d&&5===n[p].ptype&&u[o]._id===n[p].id_product&&(i=!0,r.quantity=r.quantity-n[p].quantity,r.sales_btax=r.sales_btax-n[p].price*n[p].quantity,r.sales_atax=r.sales_atax-n[p].price*n[p].quantity*(1+n[p].tax/100),null!=r.combos))for(l=0;l<r.combos.length;l++)u[o].combos[l].id_product===n[p].combos[l].id_product&&(r.combos[l].quantity=r.combos[l].quantity-n[p].combos[l].quantity*n[p].quantity,r.combos[l].sales_btax=r.combos[l].sales_btax-n[p].combos[l].price*n[p].combos[l].quantity*n[p].quantity,r.combos[l].sales_atax=r.combos[l].sales_atax-n[p].combos[l].price*n[p].combos[l].quantity*n[p].quantity*(1+n[p].tax/100))}else if(1===d||2===d){if(1===n[p].ptype||2===n[p].ptype)u[o]._id===n[p].id_product&&(i=!0,r.quantity=r.quantity+n[p].quantity,r.sales_btax=r.sales_btax+n[p].price*n[p].quantity,r.sales_atax=r.sales_atax+n[p].price*n[p].quantity*(1+n[p].tax/100));else if(5===n[p].ptype)for(b=0;b<n[p].combos.length;b++)u[o]._id===n[p].combos[b].id_product&&(i=!0,r.quantity=r.quantity+n[p].combos[b].quantity*n[p].quantity,r.sales_btax=r.sales_btax+n[p].combos[b].price*n[p].combos[b].quantity*n[p].quantity,r.sales_atax=r.sales_atax+n[p].combos[b].price*n[p].combos[b].quantity*n[p].quantity*(1+n[p].tax/100))}else if(5===d&&5===n[p].ptype&&u[o]._id===n[p].id_product&&(i=!0,r.quantity=r.quantity+n[p].quantity,r.sales_btax=r.sales_btax+n[p].price*n[p].quantity,r.sales_atax=r.sales_atax+n[p].price*n[p].quantity*(1+n[p].tax/100),null!=r.combos))for(l=0;l<r.combos.length;l++)u[o].combos[l].id_product===n[p].combos[l].id_product&&(r.combos[l].quantity=r.combos[l].quantity+n[p].combos[l].quantity*n[p].quantity,r.combos[l].sales_btax=r.combos[l].sales_btax+n[p].combos[l].price*n[p].combos[l].quantity*n[p].quantity,r.combos[l].sales_atax=r.combos[l].sales_atax+n[p].combos[l].price*n[p].combos[l].quantity*n[p].quantity*(1+n[p].tax/100));i&&(r.sales_atax=Math.round(1e6*r.sales_atax)/1e6,null!=r.subs&&r.subs.forEach((function(t){t.sales_atax=Math.round(1e6*t.sales_atax)/1e6})),null!=r.combos&&r.combos.forEach((function(t){t.sales_atax=Math.round(1e6*t.sales_atax)/1e6})),c.quantity=c.quantity+r.quantity,c.sales_btax=c.sales_btax+r.sales_btax,c.sales_atax=c.sales_atax+r.sales_atax,r.index=c.size+1,c.docs.push(r),c.size++,c.empty=!1)}console.log("jsons",c),a(c)})):a(c)}))},t.prototype.getReportSales_Categorys_byProduct=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0},l=i.getlocalProduct(n),c=new Array;i.getlocalProductAndCombos(n).forEach((function(t){c.push(t._id)}));for(var u,d=l.type,_=new Array,p=[1,3,15],b=0;b<p.length;b++)u="all"===o||void 0===o?{date:{$gte:t,$lte:e},id_product:{$in:c},bill_type:{$eq:p[b]}}:{date:{$gte:t,$lte:e},id_product:{$in:c},bill_type:{$eq:p[b]},id_branch:{$eq:o}},_[b]=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0);Promise.all(_).then((function(t){var e,n=t.flat();if(n.length>0)for(var o=0;o<n.length;o++){var s=new Array;if(s[0]={id_product:l._id,name:l.name,unit:l.unit,barcode:l.barcode,img:l.img,bill_code:n[o].bill_code,bill_type:n[o].bill_type,id_bill:n[o].id_bill,date:n[o].date,tax:n[o].tax,salesman:null===(e=i.vhAuth.getlocalEmployee(n[o].id_employee))||void 0===e?void 0:e.name,customer:i.getlocalCustomer(n[o].id_customer).name},3==n[o].bill_type)if(1===d||2===d)if(null!=n[o].combos)for(var c=0;c<n[o].combos.length;c++)n[o].combos[c].id_product===l._id&&(s[0].quantity=-n[o].combos[c].quantity*n[o].quantity,s[0].price=n[o].combos[c].price);else s[0].quantity=-n[o].quantity,s[0].price=n[o].price;else 5===d&&(s[0].quantity=-n[o].quantity,s[0].price=n[o].price);else if(1===d||2===d)if(null!=n[o].combos)for(c=0;c<n[o].combos.length;c++)n[o].combos[c].id_product===l._id&&(s[0].quantity=n[o].combos[c].quantity*n[o].quantity,s[0].price=n[o].combos[c].price);else s[0].quantity=n[o].quantity,s[0].price=n[o].price;else 5===d&&(s[0].quantity=n[o].quantity,s[0].price=n[o].price);s.forEach((function(t){t.sales_btax=t.price*t.quantity,t.sales_atax=t.price*t.quantity*(1+t.tax/100),t.index=r.size+1,r.docs.push(t),r.size++,r.empty=!1,r.quantity=r.quantity+t.quantity,r.sales_btax=r.sales_btax+t.price*t.quantity,r.sales_atax=r.sales_atax+t.price*t.quantity*(1+Number(t.tax)/100)}))}console.log("getReportSales_Categorys_byProduct"),a(r)}))}))},t.prototype.getReportSales_Products_byProducts=function(t,e,n,o,i){var a=this;return console.log("type",o),new Promise((function(s,r){var l,c,u={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};1===o?(c=1,l=[1,5]):2===o?(c=2,l=[2,5]):5===o?(c=5,l=[5]):12===o&&(c=12,l=[1,2]);var d,_=new Array,p=new Array,b=new Array;"all"===n?_=a.getlocalProducts(c):(_.push(a.getlocalProduct(n)),b=new Array,a.getlocalProductAndCombos(n).forEach((function(t){b.push(t._id)})));for(var f=[1,3,15],h=0;h<f.length;h++)d="all"===n?"all"===i||void 0===i?{date:{$gte:t,$lte:e},ptype:{$in:l},bill_type:{$eq:f[h]}}:{date:{$gte:t,$lte:e},ptype:{$in:l},bill_type:{$eq:f[h]},id_branch:{$eq:i}}:"all"===i||void 0===i?{date:{$gte:t,$lte:e},id_product:{$in:b},bill_type:{$eq:f[h]}}:{date:{$gte:t,$lte:e},id_product:{$in:b},bill_type:{$eq:f[h]},id_branch:{$eq:i}},p[h]=a.vhmongo_firebase.database().getDocsByFields("vhbill_details",d,{},{date:1},0);_.length>0?Promise.all(p).then((function(t){var e,n=t.flat();if(n.length>0)for(var i=0;i<_.length;i++){var a=!1,r=Object.assign({},_[i]),l={id_product:r._id,name:r.name,unit:r.unit,barcode:r.barcode,img:r.img,sales_btax:0,sales_atax:0,quantity:0};if(null!=r.combos){l.combos=new Array;for(var c=0;c<r.combos.length;c++){var d={id_product:r.combos[c].id_product,name:null===(e=r.combos[c])||void 0===e?void 0:e.name,sales_btax:0,sales_atax:0,quantity:0};l.combos.push(d)}}for(var p=0;p<n.length;p++)if(3==n[p].bill_type){if(1===o||2===o){if(1===n[p].ptype||2===n[p].ptype)_[i]._id===n[p].id_product&&(a=!0,l.quantity=l.quantity-n[p].quantity,l.sales_btax=l.sales_btax-n[p].price*n[p].quantity,l.sales_atax=l.sales_atax-n[p].price*n[p].quantity*(1+n[p].tax/100));else if(5===n[p].ptype)for(var b=0;b<n[p].combos.length;b++)_[i]._id===n[p].combos[b].id_product&&(a=!0,l.quantity=l.quantity-n[p].combos[b].quantity*n[p].quantity,l.sales_btax=l.sales_btax-n[p].combos[b].price*n[p].combos[b].quantity*n[p].quantity,l.sales_atax=l.sales_atax-n[p].combos[b].price*n[p].combos[b].quantity*n[p].quantity*(1+n[p].tax/100))}else if(5===o){if(5===n[p].ptype&&_[i]._id===n[p].id_product&&(a=!0,l.quantity=l.quantity-n[p].quantity,l.sales_btax=l.sales_btax-n[p].price*n[p].quantity,l.sales_atax=l.sales_atax-n[p].price*n[p].quantity*(1+n[p].tax/100),null!=l.combos))for(c=0;c<l.combos.length;c++)_[i].combos[c].id_product===n[p].combos[c].id_product&&(l.combos[c].quantity=l.combos[c].quantity-n[p].combos[c].quantity*n[p].quantity,l.combos[c].sales_btax=l.combos[c].sales_btax-n[p].combos[c].price*n[p].combos[c].quantity*n[p].quantity,l.combos[c].sales_atax=l.combos[c].sales_atax-n[p].combos[c].price*n[p].combos[c].quantity*n[p].quantity*(1+n[p].tax/100))}else if(12===o)if(1===n[p].ptype||2===n[p].ptype)_[i]._id===n[p].id_product&&(a=!0,l.quantity=l.quantity-n[p].quantity,l.sales_btax=l.sales_btax-n[p].price*n[p].quantity,l.sales_atax=l.sales_atax-n[p].price*n[p].quantity*(1+n[p].tax/100));else if(5===n[p].ptype)for(b=0;b<n[p].combos.length;b++)_[i]._id===n[p].combos[b].id_product&&(a=!0,l.quantity=l.quantity-n[p].combos[b].quantity*n[p].quantity,l.sales_btax=l.sales_btax-n[p].combos[b].price*n[p].combos[b].quantity*n[p].quantity,l.sales_atax=l.sales_atax-n[p].combos[b].price*n[p].combos[b].quantity*n[p].quantity*(1+n[p].tax/100))}else if(1===o||2===o){if(1===n[p].ptype||2===n[p].ptype)_[i]._id===n[p].id_product&&(a=!0,l.quantity=l.quantity+n[p].quantity,l.sales_btax=l.sales_btax+n[p].price*n[p].quantity,l.sales_atax=l.sales_atax+n[p].price*n[p].quantity*(1+n[p].tax/100));else if(5===n[p].ptype)for(b=0;b<n[p].combos.length;b++)_[i]._id===n[p].combos[b].id_product&&(a=!0,l.quantity=l.quantity+n[p].combos[b].quantity*n[p].quantity,l.sales_btax=l.sales_btax+n[p].combos[b].price*n[p].combos[b].quantity*n[p].quantity,l.sales_atax=l.sales_atax+n[p].combos[b].price*n[p].combos[b].quantity*n[p].quantity*(1+n[p].tax/100))}else if(5===o){if(5===n[p].ptype&&_[i]._id===n[p].id_product&&(a=!0,l.quantity=l.quantity+n[p].quantity,l.sales_btax=l.sales_btax+n[p].price*n[p].quantity,l.sales_atax=l.sales_atax+n[p].price*n[p].quantity*(1+n[p].tax/100),null!=l.combos))for(c=0;c<l.combos.length;c++)_[i].combos[c].id_product===n[p].combos[c].id_product&&(l.combos[c].quantity=l.combos[c].quantity+n[p].combos[c].quantity*n[p].quantity,l.combos[c].sales_btax=l.combos[c].sales_btax+n[p].combos[c].price*n[p].combos[c].quantity*n[p].quantity,l.combos[c].sales_atax=l.combos[c].sales_atax+n[p].combos[c].price*n[p].combos[c].quantity*n[p].quantity*(1+n[p].tax/100))}else if(12===o)if(1===n[p].ptype||2===n[p].ptype)_[i]._id===n[p].id_product&&(a=!0,l.quantity=l.quantity+n[p].quantity,l.sales_btax=l.sales_btax+n[p].price*n[p].quantity,l.sales_atax=l.sales_atax+n[p].price*n[p].quantity*(1+n[p].tax/100));else if(5===n[p].ptype)for(b=0;b<n[p].combos.length;b++)_[i]._id===n[p].combos[b].id_product&&(a=!0,l.quantity=l.quantity+n[p].combos[b].quantity*n[p].quantity,l.sales_btax=l.sales_btax+n[p].combos[b].price*n[p].combos[b].quantity*n[p].quantity,l.sales_atax=l.sales_atax+n[p].combos[b].price*n[p].combos[b].quantity*n[p].quantity*(1+n[p].tax/100));a&&(l.sales_atax=Math.round(1e6*l.sales_atax)/1e6,null!=l.subs&&l.subs.forEach((function(t){t.sales_atax=Math.round(1e6*t.sales_atax)/1e6})),null!=l.combos&&l.combos.forEach((function(t){t.sales_atax=Math.round(1e6*t.sales_atax)/1e6})),u.quantity=u.quantity+l.quantity,u.sales_btax=u.sales_btax+l.sales_btax,u.sales_atax=u.sales_atax+l.sales_atax,l.index=u.size+1,u.docs.push(l),u.size++,u.empty=!1)}console.log("jsons",u),s(u)})):s(u)}))},t.prototype.getReportSales_Products_byProduct=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0},l=i.getlocalProduct(n),c=new Array;i.getlocalProductAndCombos(n).forEach((function(t){c.push(t._id)}));for(var u,d=l.type,_=new Array,p=[1,3,15],b=0;b<p.length;b++)u="all"===o||void 0===o?{date:{$gte:t,$lte:e},id_product:{$in:c},bill_type:{$eq:p[b]}}:{date:{$gte:t,$lte:e},id_product:{$in:c},bill_type:{$eq:p[b]},id_branch:{$eq:o}},_[b]=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0);Promise.all(_).then((function(t){var e,n=t.flat();if(n.length>0)for(var o=0;o<n.length;o++){var s=new Array;if(s[0]={id_product:l._id,name:l.name,unit:l.unit,barcode:l.barcode,img:l.img,bill_code:n[o].bill_code,bill_type:n[o].bill_type,id_bill:n[o].id_bill,date:n[o].date,tax:n[o].tax,salesman:null===(e=i.vhAuth.getlocalEmployee(n[o].id_employee))||void 0===e?void 0:e.name,customer:i.getlocalCustomer(n[o].id_customer).name},3==n[o].bill_type)if(1===d||2===d)if(null!=n[o].combos)for(var c=0;c<n[o].combos.length;c++)n[o].combos[c].id_product===l._id&&(s[0].quantity=-n[o].combos[c].quantity*n[o].quantity,s[0].price=n[o].combos[c].price);else s[0].quantity=-n[o].quantity,s[0].price=n[o].price;else 5===d&&(s[0].quantity=-n[o].quantity,s[0].price=n[o].price);else if(1===d||2===d)if(null!=n[o].combos)for(c=0;c<n[o].combos.length;c++)n[o].combos[c].id_product===l._id&&(s[0].quantity=n[o].combos[c].quantity*n[o].quantity,s[0].price=n[o].combos[c].price);else s[0].quantity=n[o].quantity,s[0].price=n[o].price;else 5===d&&(s[0].quantity=n[o].quantity,s[0].price=n[o].price);s.forEach((function(t){t.sales_btax=t.price*t.quantity,t.sales_atax=t.price*t.quantity*(1+t.tax/100),t.index=r.size+1,r.docs.push(t),r.size++,r.empty=!1,r.quantity=r.quantity+t.quantity,r.sales_btax=r.sales_btax+t.price*t.quantity,r.sales_atax=r.sales_atax+t.price*t.quantity*(1+Number(t.tax)/100)}))}console.log("json",r),a(r)}))}))},t.prototype.getDiscount_bill_byCustomer=function(t,e){for(var n=this.getlocalCustomer(e),o=this.getlocalDiscount_bills(),i=this.getlocalCustomerClasss(),a=null,s=0;s<i.length;s++)if(i[s]._id===n.id_customer_class&&null!=i[s].id_discount_bill&&null!=i[s].id_discount_bill)for(var r=0;r<o.length;r++)if(o[r]._id===i[s].id_discount_bill){a={discount:0},1===o[r].method?(0!=o[r].level5.sales||0!=o[r].level5.discount)&&t>=o[r].level5.sales?1===o[r].type?(a.discount=a.discount+(o[r].level2.sales-o[r].level1.sales)*o[r].level1.discount/100,a.discount=a.discount+(o[r].level3.sales-o[r].level2.sales)*o[r].level2.discount/100,a.discount=a.discount+(o[r].level4.sales-o[r].level3.sales)*o[r].level3.discount/100,a.discount=a.discount+(o[r].level5.sales-o[r].level4.sales)*o[r].level4.discount/100,a.discount=a.discount+(t-o[r].level5.sales)*o[r].level5.discount/100):2===o[r].type&&(a.discount=o[r].level1.discount,a.discount=a.discount+o[r].level2.discount,a.discount=a.discount+o[r].level3.discount,a.discount=a.discount+o[r].level4.discount,a.discount=a.discount+o[r].level5.discount):(0!=o[r].level4.sales||0!=o[r].level4.discount)&&t>=o[r].level4.sales?1===o[r].type?(a.discount=a.discount+(o[r].level2.sales-o[r].level1.sales)*o[r].level1.discount/100,a.discount=a.discount+(o[r].level3.sales-o[r].level2.sales)*o[r].level2.discount/100,a.discount=a.discount+(o[r].level4.sales-o[r].level3.sales)*o[r].level3.discount/100,a.discount=a.discount+(t-o[r].level4.sales)*o[r].level4.discount/100):2===o[r].type&&(a.discount=o[r].level1.discount,a.discount=a.discount+o[r].level2.discount,a.discount=a.discount+o[r].level3.discount,a.discount=a.discount+o[r].level4.discount):(0!=o[r].level3.sales||0!=o[r].level3.discount)&&t>=o[r].level3.sales?1===o[r].type?(a.discount=a.discount+(o[r].level2.sales-o[r].level1.sales)*o[r].level1.discount/100,a.discount=a.discount+(o[r].level3.sales-o[r].level2.sales)*o[r].level2.discount/100,a.discount=a.discount+(t-o[r].level3.sales)*o[r].level3.discount/100):2===o[r].type&&(a.discount=o[r].level1.discount,a.discount=a.discount+o[r].level2.discount,a.discount=a.discount+o[r].level3.discount):(0!=o[r].level2.sales||0!=o[r].level2.discount)&&t>=o[r].level2.sales?1===o[r].type?(a.discount=a.discount+(o[r].level2.sales-o[r].level1.sales)*o[r].level1.discount/100,a.discount=a.discount+(t-o[r].level2.sales)*o[r].level2.discount/100):2===o[r].type&&(a.discount=o[r].level1.discount,a.discount=a.discount+o[r].level2.discount):(0!=o[r].level1.sales||0!=o[r].level1.discount)&&t>=o[r].level1.sales&&(1===o[r].type?a.discount=a.discount+(t-o[r].level1.sales)*o[r].level1.discount/100:2===o[r].type&&(a.discount=o[r].level1.discount)):2===o[r].method&&((0!=o[r].level5.sales||0!=o[r].level5.discount)&&t>=o[r].level5.sales?1===o[r].type?a.discount=t*o[r].level5.discount/100:2===o[r].type&&(a.discount=o[r].level5.discount):(0!=o[r].level4.sales||0!=o[r].level4.discount)&&t>=o[r].level4.sales?1===o[r].type?a.discount=t*o[r].level4.discount/100:2===o[r].type&&(a.discount=o[r].level4.discount):(0!=o[r].level3.sales||0!=o[r].level3.discount)&&t>=o[r].level3.sales?1===o[r].type?a.discount=t*o[r].level3.discount/100:2===o[r].type&&(a.discount=o[r].level3.discount):(0!=o[r].level2.sales||0!=o[r].level2.discount)&&t>=o[r].level2.sales?1===o[r].type?a.discount=t*o[r].level2.discount/100:2===o[r].type&&(a.discount=o[r].level2.discount):(0!=o[r].level1.sales||0!=o[r].level1.discount)&&t>=o[r].level1.sales&&(1===o[r].type?a.discount=t*o[r].level1.discount/100:2===o[r].type&&(a.discount=o[r].level1.discount)));break}return a},t.prototype.getReportDiscount_sales_Customers=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Array;if("all"===n)r=i.getlocalCustomers();else{var l=i.getlocalCustomer(n);r.push(l)}var c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,discount_btax:0,discount_atax:0};if(r.length>0){var u=void 0;u="all"===n?"all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1,3,15]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1,3,15]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$gte:t,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1,3,15]}}:{date:{$gte:t,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1,3,15]},id_branch:{$eq:o}};var d=i.vhmongo_firebase.database().getDocsByFields("discount_saless",{},{},{},0),_=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0),p=i.vhmongo_firebase.database().getDocsByFields("customer_classs",{},{},{},0);Promise.all([d,_,p]).then((function(t){var e,n=t[0],o=t[1],i=t[2];if(o.length>0)for(var s=0;s<r.length;s++){for(var l=!1,u={id_customer:r[s]._id,name:r[s].name,img:null===(e=r[s])||void 0===e?void 0:e.img,sales_btax:0,sales_atax:0,quantity:0,discount_btax:0,discount_atax:0,discount_name:""},d=0;d<o.length;d++)if(r[s]._id===o[d].id_customer)if(l=!0,3==o[d].bill_type)if(5===o[d].ptype){if(null!=o[d].combos)for(var _=0;_<o[d].combos.length;_++)u.quantity=u.quantity-o[d].combos[_].quantity*o[d].quantity,u.sales_btax=u.sales_btax-o[d].combos[_].price*o[d].combos[_].quantity*o[d].quantity,u.sales_atax=u.sales_atax-o[d].combos[_].price*o[d].combos[_].quantity*o[d].quantity*(1+o[d].tax/100)}else u.quantity=u.quantity-o[d].quantity,u.sales_btax=u.sales_btax-o[d].price*o[d].quantity,u.sales_atax=u.sales_atax-o[d].price*o[d].quantity*(1+o[d].tax/100);else if(5===o[d].ptype){if(null!=o[d].combos)for(_=0;_<o[d].combos.length;_++)u.quantity=u.quantity+o[d].combos[_].quantity*o[d].quantity,u.sales_btax=u.sales_btax+o[d].combos[_].price*o[d].combos[_].quantity*o[d].quantity,u.sales_atax=u.sales_atax+o[d].combos[_].price*o[d].combos[_].quantity*o[d].quantity*(1+o[d].tax/100)}else u.quantity=u.quantity+o[d].quantity,u.sales_btax=u.sales_btax+o[d].price*o[d].quantity,u.sales_atax=u.sales_atax+o[d].price*o[d].quantity*(1+o[d].tax/100);if(l&&null!=r[s].id_customer_class&&null!=r[s].id_customer_class)for(d=0;d<i.length;d++)if(i[d]._id===r[s].id_customer_class&&null!=i[d].id_discount_sales&&null!=i[d].id_discount_sales)for(var p=0;p<n.length;p++)if(n[p]._id===i[d].id_discount_sales){u.discount_name=n[p].name,1===n[p].method?(0!=n[p].level5.sales||0!=n[p].level5.discount)&&u.sales_btax>=n[p].level5.sales?1===n[p].type?(u.discount_btax=u.discount_btax+(n[p].level2.sales-n[p].level1.sales)*n[p].level1.discount/100,u.discount_btax=u.discount_btax+(n[p].level3.sales-n[p].level2.sales)*n[p].level2.discount/100,u.discount_btax=u.discount_btax+(n[p].level4.sales-n[p].level3.sales)*n[p].level3.discount/100,u.discount_btax=u.discount_btax+(n[p].level5.sales-n[p].level4.sales)*n[p].level4.discount/100,u.discount_btax=u.discount_btax+(u.sales_btax-n[p].level5.sales)*n[p].level5.discount/100):2===n[p].type&&(u.discount_btax=n[p].level1.discount,u.discount_btax=u.discount_btax+n[p].level2.discount,u.discount_btax=u.discount_btax+n[p].level3.discount,u.discount_btax=u.discount_btax+n[p].level4.discount,u.discount_btax=u.discount_btax+n[p].level5.discount):(0!=n[p].level4.sales||0!=n[p].level4.discount)&&u.sales_btax>=n[p].level4.sales?1===n[p].type?(u.discount_btax=u.discount_btax+(n[p].level2.sales-n[p].level1.sales)*n[p].level1.discount/100,u.discount_btax=u.discount_btax+(n[p].level3.sales-n[p].level2.sales)*n[p].level2.discount/100,u.discount_btax=u.discount_btax+(n[p].level4.sales-n[p].level3.sales)*n[p].level3.discount/100,u.discount_btax=u.discount_btax+(u.sales_btax-n[p].level4.sales)*n[p].level4.discount/100):2===n[p].type&&(u.discount_btax=n[p].level1.discount,u.discount_btax=u.discount_btax+n[p].level2.discount,u.discount_btax=u.discount_btax+n[p].level3.discount,u.discount_btax=u.discount_btax+n[p].level4.discount):(0!=n[p].level3.sales||0!=n[p].level3.discount)&&u.sales_btax>=n[p].level3.sales?1===n[p].type?(u.discount_btax=u.discount_btax+(n[p].level2.sales-n[p].level1.sales)*n[p].level1.discount/100,u.discount_btax=u.discount_btax+(n[p].level3.sales-n[p].level2.sales)*n[p].level2.discount/100,u.discount_btax=u.discount_btax+(u.sales_btax-n[p].level3.sales)*n[p].level3.discount/100):2===n[p].type&&(u.discount_btax=n[p].level1.discount,u.discount_btax=u.discount_btax+n[p].level2.discount,u.discount_btax=u.discount_btax+n[p].level3.discount):(0!=n[p].level2.sales||0!=n[p].level2.discount)&&u.sales_btax>=n[p].level2.sales?1===n[p].type?(u.discount_btax=u.discount_btax+(n[p].level2.sales-n[p].level1.sales)*n[p].level1.discount/100,u.discount_btax=u.discount_btax+(u.sales_btax-n[p].level2.sales)*n[p].level2.discount/100):2===n[p].type&&(u.discount_btax=n[p].level1.discount,u.discount_btax=u.discount_btax+n[p].level2.discount):(0!=n[p].level1.sales||0!=n[p].level1.discount)&&u.sales_btax>=n[p].level1.sales&&(1===n[p].type?u.discount_btax=u.discount_btax+(u.sales_btax-n[p].level1.sales)*n[p].level1.discount/100:2===n[p].type&&(u.discount_btax=n[p].level1.discount)):2===n[p].method&&((0!=n[p].level5.sales||0!=n[p].level5.discount)&&u.sales_btax>=n[p].level5.sales?1===n[p].type?u.discount_btax=u.sales_btax*n[p].level5.discount/100:2===n[p].type&&(u.discount_btax=n[p].level5.discount):(0!=n[p].level4.sales||0!=n[p].level4.discount)&&u.sales_btax>=n[p].level4.sales?1===n[p].type?u.discount_btax=u.sales_btax*n[p].level4.discount/100:2===n[p].type&&(u.discount_btax=n[p].level4.discount):(0!=n[p].level3.sales||0!=n[p].level3.discount)&&u.sales_btax>=n[p].level3.sales?1===n[p].type?u.discount_btax=u.sales_btax*n[p].level3.discount/100:2===n[p].type&&(u.discount_btax=n[p].level3.discount):(0!=n[p].level2.sales||0!=n[p].level2.discount)&&u.sales_btax>=n[p].level2.sales?1===n[p].type?u.discount_btax=u.sales_btax*n[p].level2.discount/100:2===n[p].type&&(u.discount_btax=n[p].level2.discount):(0!=n[p].level1.sales||0!=n[p].level1.discount)&&u.sales_btax>=n[p].level1.sales&&(1===n[p].type?u.discount_btax=u.sales_btax*n[p].level1.discount/100:2===n[p].type&&(u.discount_btax=n[p].level1.discount))),1===n[p].method?(0!=n[p].level5.sales||0!=n[p].level5.discount)&&u.sales_atax>=n[p].level5.sales?1===n[p].type?(u.discount_atax=u.discount_atax+(n[p].level2.sales-n[p].level1.sales)*n[p].level1.discount/100,u.discount_atax=u.discount_atax+(n[p].level3.sales-n[p].level2.sales)*n[p].level2.discount/100,u.discount_atax=u.discount_atax+(n[p].level4.sales-n[p].level3.sales)*n[p].level3.discount/100,u.discount_atax=u.discount_atax+(n[p].level5.sales-n[p].level4.sales)*n[p].level4.discount/100,u.discount_atax=u.discount_atax+(u.sales_atax-n[p].level5.sales)*n[p].level5.discount/100):2===n[p].type&&(u.discount_atax=n[p].level1.discount,u.discount_atax=u.discount_atax+n[p].level2.discount,u.discount_atax=u.discount_atax+n[p].level3.discount,u.discount_atax=u.discount_atax+n[p].level4.discount,u.discount_atax=u.discount_atax+n[p].level5.discount):(0!=n[p].level4.sales||0!=n[p].level4.discount)&&u.sales_atax>=n[p].level4.sales?1===n[p].type?(u.discount_atax=u.discount_atax+(n[p].level2.sales-n[p].level1.sales)*n[p].level1.discount/100,u.discount_atax=u.discount_atax+(n[p].level3.sales-n[p].level2.sales)*n[p].level2.discount/100,u.discount_atax=u.discount_atax+(n[p].level4.sales-n[p].level3.sales)*n[p].level3.discount/100,u.discount_atax=u.discount_atax+(u.sales_atax-n[p].level4.sales)*n[p].level4.discount/100):2===n[p].type&&(u.discount_atax=n[p].level1.discount,u.discount_atax=u.discount_atax+n[p].level2.discount,u.discount_atax=u.discount_atax+n[p].level3.discount,u.discount_atax=u.discount_atax+n[p].level4.discount):(0!=n[p].level3.sales||0!=n[p].level3.discount)&&u.sales_atax>=n[p].level3.sales?1===n[p].type?(u.discount_atax=u.discount_atax+(n[p].level2.sales-n[p].level1.sales)*n[p].level1.discount/100,u.discount_atax=u.discount_atax+(n[p].level3.sales-n[p].level2.sales)*n[p].level2.discount/100,u.discount_atax=u.discount_atax+(u.sales_atax-n[p].level3.sales)*n[p].level3.discount/100):2===n[p].type&&(u.discount_atax=n[p].level1.discount,u.discount_atax=u.discount_atax+n[p].level2.discount,u.discount_atax=u.discount_atax+n[p].level3.discount):(0!=n[p].level2.sales||0!=n[p].level2.discount)&&u.sales_atax>=n[p].level2.sales?1===n[p].type?(u.discount_atax=u.discount_atax+(n[p].level2.sales-n[p].level1.sales)*n[p].level1.discount/100,u.discount_atax=u.discount_atax+(u.sales_atax-n[p].level2.sales)*n[p].level2.discount/100):2===n[p].type&&(u.discount_atax=n[p].level1.discount,u.discount_atax=u.discount_atax+n[p].level2.discount):(0!=n[p].level1.sales||0!=n[p].level1.discount)&&u.sales_atax>=n[p].level1.sales&&(1===n[p].type?u.discount_atax=u.discount_atax+(u.sales_atax-n[p].level1.sales)*n[p].level1.discount/100:2===n[p].type&&(u.discount_atax=n[p].level1.discount)):2===n[p].method&&((0!=n[p].level5.sales||0!=n[p].level5.discount)&&u.sales_atax>=n[p].level5.sales?1===n[p].type?u.discount_atax=u.sales_atax*n[p].level5.discount/100:2===n[p].type&&(u.discount_atax=n[p].level5.discount):(0!=n[p].level4.sales||0!=n[p].level4.discount)&&u.sales_atax>=n[p].level4.sales?1===n[p].type?u.discount_atax=u.sales_atax*n[p].level4.discount/100:2===n[p].type&&(u.discount_atax=n[p].level4.discount):(0!=n[p].level3.sales||0!=n[p].level3.discount)&&u.sales_atax>=n[p].level3.sales?1===n[p].type?u.discount_atax=u.sales_atax*n[p].level3.discount/100:2===n[p].type&&(u.discount_atax=n[p].level3.discount):(0!=n[p].level2.sales||0!=n[p].level2.discount)&&u.sales_atax>=n[p].level2.sales?1===n[p].type?u.discount_atax=u.sales_atax*n[p].level2.discount/100:2===n[p].type&&(u.discount_atax=n[p].level2.discount):(0!=n[p].level1.sales||0!=n[p].level1.discount)&&u.sales_atax>=n[p].level1.sales&&(1===n[p].type?u.discount_atax=u.sales_atax*n[p].level1.discount/100:2===n[p].type&&(u.discount_atax=n[p].level1.discount))),c.sales_btax=c.sales_btax+u.sales_btax,c.sales_atax=c.sales_atax+u.sales_atax,c.discount_btax=c.discount_btax+u.discount_btax,c.discount_atax=c.discount_atax+u.discount_atax,u.index=c.size+1,c.docs.push(u),c.size++,c.empty=!1;break}}console.log("getReportDiscount_Customers",c),a(c)}))}else a(c)}))},t.prototype.getReportCommission_Employees=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Array;if("all"===n)r=i.vhAuth.getlocalEmployees();else{var l=i.vhAuth.getlocalEmployee(n);r.push(l)}var c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,commission_btax:0,commission_atax:0};if(r.length>0){var u=void 0;u="all"===n?"all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1,3,15]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1,3,15]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$gte:t,$lte:e},id_employee:{$eq:n},bill_type:{$in:[1,3,15]}}:{date:{$gte:t,$lte:e},id_employee:{$eq:n},bill_type:{$in:[1,3,15]},id_branch:{$eq:o}};var d=i.vhmongo_firebase.database().getDocsByFields("commissions",{},{},{},0),_=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0),p=i.vhmongo_firebase.database().getDocsByFields("employee_classs",{},{},{},0);Promise.all([d,_,p]).then((function(t){var e=t[0],n=t[1],o=t[2];if(n.length>0)for(var i=0;i<r.length;i++){for(var s=!1,l={id_employee:r[i]._id,name:r[i].name,sales_btax:0,sales_atax:0,quantity:0,commission_btax:0,commission_atax:0,commission_name:""},u=0;u<n.length;u++)if(r[i]._id===n[u].id_employee)if(s=!0,3==n[u].bill_type)if(5===n[u].ptype){if(null!=n[u].combos)for(var d=0;d<n[u].combos.length;d++)l.quantity=l.quantity-n[u].combos[d].quantity*n[u].quantity,l.sales_btax=l.sales_btax-n[u].combos[d].price*n[u].combos[d].quantity*n[u].quantity,l.sales_atax=l.sales_atax-n[u].combos[d].price*n[u].combos[d].quantity*n[u].quantity*(1+n[u].tax/100)}else l.quantity=l.quantity-n[u].quantity,l.sales_btax=l.sales_btax-n[u].price*n[u].quantity,l.sales_atax=l.sales_atax-n[u].price*n[u].quantity*(1+n[u].tax/100);else if(5===n[u].ptype){if(null!=n[u].combos)for(d=0;d<n[u].combos.length;d++)l.quantity=l.quantity+n[u].combos[d].quantity*n[u].quantity,l.sales_btax=l.sales_btax+n[u].combos[d].price*n[u].combos[d].quantity*n[u].quantity,l.sales_atax=l.sales_atax+n[u].combos[d].price*n[u].combos[d].quantity*n[u].quantity*(1+n[u].tax/100)}else l.quantity=l.quantity+n[u].quantity,l.sales_btax=l.sales_btax+n[u].price*n[u].quantity,l.sales_atax=l.sales_atax+n[u].price*n[u].quantity*(1+n[u].tax/100);if(s&&null!=r[i].id_employee_class&&null!=r[i].id_employee_class)for(u=0;u<o.length;u++)if(o[u]._id===r[i].id_employee_class&&null!=o[u].id_commission&&null!=o[u].id_commission)for(var _=0;_<e.length;_++)if(e[_]._id===o[u].id_commission){l.commission_name=e[_].name,1===e[_].method?(0!=e[_].level5.sales||0!=e[_].level5.commission)&&l.sales_btax>=e[_].level5.sales?1===e[_].type?(l.commission_btax=l.commission_btax+(e[_].level2.sales-e[_].level1.sales)*e[_].level1.commission/100,l.commission_btax=l.commission_btax+(e[_].level3.sales-e[_].level2.sales)*e[_].level2.commission/100,l.commission_btax=l.commission_btax+(e[_].level4.sales-e[_].level3.sales)*e[_].level3.commission/100,l.commission_btax=l.commission_btax+(e[_].level5.sales-e[_].level4.sales)*e[_].level4.commission/100,l.commission_btax=l.commission_btax+(l.sales_btax-e[_].level5.sales)*e[_].level5.commission/100):2===e[_].type&&(l.commission_btax=e[_].level1.commission,l.commission_btax=l.commission_btax+e[_].level2.commission,l.commission_btax=l.commission_btax+e[_].level3.commission,l.commission_btax=l.commission_btax+e[_].level4.commission,l.commission_btax=l.commission_btax+e[_].level5.commission):(0!=e[_].level4.sales||0!=e[_].level4.commission)&&l.sales_btax>=e[_].level4.sales?1===e[_].type?(l.commission_btax=l.commission_btax+(e[_].level2.sales-e[_].level1.sales)*e[_].level1.commission/100,l.commission_btax=l.commission_btax+(e[_].level3.sales-e[_].level2.sales)*e[_].level2.commission/100,l.commission_btax=l.commission_btax+(e[_].level4.sales-e[_].level3.sales)*e[_].level3.commission/100,l.commission_btax=l.commission_btax+(l.sales_btax-e[_].level4.sales)*e[_].level4.commission/100):2===e[_].type&&(l.commission_btax=e[_].level1.commission,l.commission_btax=l.commission_btax+e[_].level2.commission,l.commission_btax=l.commission_btax+e[_].level3.commission,l.commission_btax=l.commission_btax+e[_].level4.commission):(0!=e[_].level3.sales||0!=e[_].level3.commission)&&l.sales_btax>=e[_].level3.sales?1===e[_].type?(l.commission_btax=l.commission_btax+(e[_].level2.sales-e[_].level1.sales)*e[_].level1.commission/100,l.commission_btax=l.commission_btax+(e[_].level3.sales-e[_].level2.sales)*e[_].level2.commission/100,l.commission_btax=l.commission_btax+(l.sales_btax-e[_].level3.sales)*e[_].level3.commission/100):2===e[_].type&&(l.commission_btax=e[_].level1.commission,l.commission_btax=l.commission_btax+e[_].level2.commission,l.commission_btax=l.commission_btax+e[_].level3.commission):(0!=e[_].level2.sales||0!=e[_].level2.commission)&&l.sales_btax>=e[_].level2.sales?1===e[_].type?(l.commission_btax=l.commission_btax+(e[_].level2.sales-e[_].level1.sales)*e[_].level1.commission/100,l.commission_btax=l.commission_btax+(l.sales_btax-e[_].level2.sales)*e[_].level2.commission/100):2===e[_].type&&(l.commission_btax=e[_].level1.commission,l.commission_btax=l.commission_btax+e[_].level2.commission):(0!=e[_].level1.sales||0!=e[_].level1.commission)&&l.sales_btax>=e[_].level1.sales&&(1===e[_].type?l.commission_btax=l.commission_btax+(l.sales_btax-e[_].level1.sales)*e[_].level1.commission/100:2===e[_].type&&(l.commission_btax=e[_].level1.commission)):2===e[_].method&&((0!=e[_].level5.sales||0!=e[_].level5.commission)&&l.sales_btax>=e[_].level5.sales?1===e[_].type?l.commission_btax=l.sales_btax*e[_].level5.commission/100:2===e[_].type&&(l.commission_btax=e[_].level5.commission):(0!=e[_].level4.sales||0!=e[_].level4.commission)&&l.sales_btax>=e[_].level4.sales?1===e[_].type?l.commission_btax=l.sales_btax*e[_].level4.commission/100:2===e[_].type&&(l.commission_btax=e[_].level4.commission):(0!=e[_].level3.sales||0!=e[_].level3.commission)&&l.sales_btax>=e[_].level3.sales?1===e[_].type?l.commission_btax=l.sales_btax*e[_].level3.commission/100:2===e[_].type&&(l.commission_btax=e[_].level3.commission):(0!=e[_].level2.sales||0!=e[_].level2.commission)&&l.sales_btax>=e[_].level2.sales?1===e[_].type?l.commission_btax=l.sales_btax*e[_].level2.commission/100:2===e[_].type&&(l.commission_btax=e[_].level2.commission):(0!=e[_].level1.sales||0!=e[_].level1.commission)&&l.sales_btax>=e[_].level1.sales&&(1===e[_].type?l.commission_btax=l.sales_btax*e[_].level1.commission/100:2===e[_].type&&(l.commission_btax=e[_].level1.commission))),1===e[_].method?(0!=e[_].level5.sales||0!=e[_].level5.commission)&&l.sales_atax>=e[_].level5.sales?1===e[_].type?(l.commission_atax=l.commission_atax+(e[_].level2.sales-e[_].level1.sales)*e[_].level1.commission/100,l.commission_atax=l.commission_atax+(e[_].level3.sales-e[_].level2.sales)*e[_].level2.commission/100,l.commission_atax=l.commission_atax+(e[_].level4.sales-e[_].level3.sales)*e[_].level3.commission/100,l.commission_atax=l.commission_atax+(e[_].level5.sales-e[_].level4.sales)*e[_].level4.commission/100,l.commission_atax=l.commission_atax+(l.sales_atax-e[_].level5.sales)*e[_].level5.commission/100):2===e[_].type&&(l.commission_atax=e[_].level1.commission,l.commission_atax=l.commission_atax+e[_].level2.commission,l.commission_atax=l.commission_atax+e[_].level3.commission,l.commission_atax=l.commission_atax+e[_].level4.commission,l.commission_atax=l.commission_atax+e[_].level5.commission):(0!=e[_].level4.sales||0!=e[_].level4.commission)&&l.sales_atax>=e[_].level4.sales?1===e[_].type?(l.commission_atax=l.commission_atax+(e[_].level2.sales-e[_].level1.sales)*e[_].level1.commission/100,l.commission_atax=l.commission_atax+(e[_].level3.sales-e[_].level2.sales)*e[_].level2.commission/100,l.commission_atax=l.commission_atax+(e[_].level4.sales-e[_].level3.sales)*e[_].level3.commission/100,l.commission_atax=l.commission_atax+(l.sales_atax-e[_].level4.sales)*e[_].level4.commission/100):2===e[_].type&&(l.commission_atax=e[_].level1.commission,l.commission_atax=l.commission_atax+e[_].level2.commission,l.commission_atax=l.commission_atax+e[_].level3.commission,l.commission_atax=l.commission_atax+e[_].level4.commission):(0!=e[_].level3.sales||0!=e[_].level3.commission)&&l.sales_atax>=e[_].level3.sales?1===e[_].type?(l.commission_atax=l.commission_atax+(e[_].level2.sales-e[_].level1.sales)*e[_].level1.commission/100,l.commission_atax=l.commission_atax+(e[_].level3.sales-e[_].level2.sales)*e[_].level2.commission/100,l.commission_atax=l.commission_atax+(l.sales_atax-e[_].level3.sales)*e[_].level3.commission/100):2===e[_].type&&(l.commission_atax=e[_].level1.commission,l.commission_atax=l.commission_atax+e[_].level2.commission,l.commission_atax=l.commission_atax+e[_].level3.commission):(0!=e[_].level2.sales||0!=e[_].level2.commission)&&l.sales_atax>=e[_].level2.sales?1===e[_].type?(l.commission_atax=l.commission_atax+(e[_].level2.sales-e[_].level1.sales)*e[_].level1.commission/100,l.commission_atax=l.commission_atax+(l.sales_atax-e[_].level2.sales)*e[_].level2.commission/100):2===e[_].type&&(l.commission_atax=e[_].level1.commission,l.commission_atax=l.commission_atax+e[_].level2.commission):(0!=e[_].level1.sales||0!=e[_].level1.commission)&&l.sales_atax>=e[_].level1.sales&&(1===e[_].type?l.commission_atax=l.commission_atax+(l.sales_atax-e[_].level1.sales)*e[_].level1.commission/100:2===e[_].type&&(l.commission_atax=e[_].level1.commission)):2===e[_].method&&((0!=e[_].level5.sales||0!=e[_].level5.commission)&&l.sales_atax>=e[_].level5.sales?1===e[_].type?l.commission_atax=l.sales_atax*e[_].level5.commission/100:2===e[_].type&&(l.commission_atax=e[_].level5.commission):(0!=e[_].level4.sales||0!=e[_].level4.commission)&&l.sales_atax>=e[_].level4.sales?1===e[_].type?l.commission_atax=l.sales_atax*e[_].level4.commission/100:2===e[_].type&&(l.commission_atax=e[_].level4.commission):(0!=e[_].level3.sales||0!=e[_].level3.commission)&&l.sales_atax>=e[_].level3.sales?1===e[_].type?l.commission_atax=l.sales_atax*e[_].level3.commission/100:2===e[_].type&&(l.commission_atax=e[_].level3.commission):(0!=e[_].level2.sales||0!=e[_].level2.commission)&&l.sales_atax>=e[_].level2.sales?1===e[_].type?l.commission_atax=l.sales_atax*e[_].level2.commission/100:2===e[_].type&&(l.commission_atax=e[_].level2.commission):(0!=e[_].level1.sales||0!=e[_].level1.commission)&&l.sales_atax>=e[_].level1.sales&&(1===e[_].type?l.commission_atax=l.sales_atax*e[_].level1.commission/100:2===e[_].type&&(l.commission_atax=e[_].level1.commission))),c.sales_btax=c.sales_btax+l.sales_btax,c.sales_atax=c.sales_atax+l.sales_atax,c.commission_btax=c.commission_btax+l.commission_btax,c.commission_atax=c.commission_atax+l.commission_atax,l.index=c.size+1,c.docs.push(l),c.size++,c.empty=!1;break}}console.log("getReportCommission_Employees",c),a(c)}))}else a(c)}))},t.prototype.getReportSales_Customers_byCustomers=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Array;if("all"===n)r=i.getlocalCustomers();else{var l=i.getlocalCustomer(n);r.push(l)}var c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};if(r.length>0){var u=void 0;u="all"===n?"all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1,3,15]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1,3,15]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$gte:t,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1,3,15]}}:{date:{$gte:t,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1,3,15]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0).then((function(t){var e;if(t.length>0)for(var n=0;n<r.length;n++){for(var o=!1,i={id_customer:r[n]._id,name:r[n].name,img:null===(e=r[n])||void 0===e?void 0:e.img,sales_btax:0,sales_atax:0,quantity:0},s=0;s<t.length;s++)if(r[n]._id===t[s].id_customer)if(o=!0,3==t[s].bill_type)if(5===t[s].ptype){if(null!=t[s].combos)for(var l=0;l<t[s].combos.length;l++)i.quantity=i.quantity-t[s].combos[l].quantity*t[s].quantity,i.sales_btax=i.sales_btax-t[s].combos[l].price*t[s].combos[l].quantity*t[s].quantity,i.sales_atax=i.sales_atax-t[s].combos[l].price*t[s].combos[l].quantity*t[s].quantity*(1+t[s].tax/100)}else i.quantity=i.quantity-t[s].quantity,i.sales_btax=i.sales_btax-t[s].price*t[s].quantity,i.sales_atax=i.sales_atax-t[s].price*t[s].quantity*(1+t[s].tax/100);else if(5===t[s].ptype){if(null!=t[s].combos)for(l=0;l<t[s].combos.length;l++)i.quantity=i.quantity+t[s].combos[l].quantity*t[s].quantity,i.sales_btax=i.sales_btax+t[s].combos[l].price*t[s].combos[l].quantity*t[s].quantity,i.sales_atax=i.sales_atax+t[s].combos[l].price*t[s].combos[l].quantity*t[s].quantity*(1+t[s].tax/100)}else i.quantity=i.quantity+t[s].quantity,i.sales_btax=i.sales_btax+t[s].price*t[s].quantity,i.sales_atax=i.sales_atax+t[s].price*t[s].quantity*(1+t[s].tax/100);o&&(c.quantity=c.quantity+i.quantity,c.sales_btax=c.sales_btax+i.sales_btax,c.sales_atax=c.sales_atax+i.sales_atax,i.index=c.size+1,c.docs.push(i),c.size++,c.empty=!1)}console.log("getReportSales_Customers_byCustomers"),a(c)}))}else a(c)}))},t.prototype.getReportSales_Customers_byProducts=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l=i.getlocalProducts(12);r=r="all"===o||void 0===o?{date:{$gte:t,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1,3,15]}}:{date:{$gte:t,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1,3,15]},id_branch:{$eq:o}};var c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};l.length>0?i.vhmongo_firebase.database().getDocsByFields("vhbill_details",r,{},{date:1},0).then((function(t){if(t.length>0)for(var e=0;e<l.length;e++){for(var o=!1,i=Object.assign({},l[e]),s={id_product:i._id,name:i.name,unit:i.unit,barcode:i.barcode,img:i.img,id_customer:n,sales_btax:0,sales_atax:0,quantity:0},r=0;r<t.length;r++)if(3==t[r].bill_type)if(5===t[r].ptype)for(var u=0;u<t[r].combos.length;u++)l[e]._id===t[r].combos[u].id_product&&(o=!0,s.quantity=s.quantity-t[r].combos[u].quantity*t[r].quantity,s.sales_btax=s.sales_btax-t[r].combos[u].price*t[r].combos[u].quantity*t[r].quantity,s.sales_atax=s.sales_atax-t[r].combos[u].price*t[r].combos[u].quantity*t[r].quantity*(1+t[r].tax/100));else l[e]._id===t[r].id_product&&(o=!0,s.quantity=s.quantity-t[r].quantity,s.sales_btax=s.sales_btax-t[r].price*t[r].quantity,s.sales_atax=s.sales_atax-t[r].price*t[r].quantity*(1+t[r].tax/100));else if(5===t[r].ptype)for(u=0;u<t[r].combos.length;u++)l[e]._id===t[r].combos[u].id_product&&(o=!0,s.quantity=s.quantity+t[r].combos[u].quantity*t[r].quantity,s.sales_btax=s.sales_btax+t[r].combos[u].price*t[r].combos[u].quantity*t[r].quantity,s.sales_atax=s.sales_atax+t[r].combos[u].price*t[r].combos[u].quantity*t[r].quantity*(1+t[r].tax/100));else l[e]._id===t[r].id_product&&(o=!0,s.quantity=s.quantity+t[r].quantity,s.sales_btax=s.sales_btax+t[r].price*t[r].quantity,s.sales_atax=s.sales_atax+t[r].price*t[r].quantity*(1+t[r].tax/100));o&&(s.sales_atax=Math.round(1e6*s.sales_atax)/1e6,c.quantity=c.quantity+s.quantity,c.sales_btax=c.sales_btax+s.sales_btax,c.sales_atax=c.sales_atax+s.sales_atax,s.index=c.size+1,c.docs.push(s),c.size++,c.empty=!1)}console.log("getReportSales_Customers_byProducts"),a(c)})):a(c)}))},t.prototype.getReportSales_Customers_byProducts_Analytics=function(t,e,n,o,i,a){var s=this;return new Promise((function(r,l){var c,u=s.getlocalProducts(15);u=(u=u.filter((function(t){return!0===t.allow_sell}))).filter((function(t){if(null!=t[a]&&!0===t.allow_sell){if("shopee"===i&&null!=t[a].shopees&&null!=t[a].shopees.length)for(var e=0;e<t[a].shopees.length;e++)if(t[a].shopees[e].id_shop===o)return!0;if("tiki"===i&&null!=t[a].tikis&&null!=t[a].tikis.length)for(e=0;e<t[a].tikis.length;e++)if(t[a].tikis[e].id_shop===o)return!0;if("lazada"===i&&null!=t[a].lazadas&&null!=t[a].lazadas.length)for(e=0;e<t[a].lazadas.length;e++)if(t[a].lazadas[e].id_shop===o)return!0;if("sendo"===i&&null!=t[a].sendos&&null!=t[a].sendos.length)for(e=0;e<t[a].sendos.length;e++)if(t[a].sendos[e].id_shop===o)return!0}return!1})),console.log("hello products",u),c=c="all"===a||void 0===a?{date:{$gte:t,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1,3,15]}}:{date:{$gte:t,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1,3,15]},id_branch:{$eq:a}};var d={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};u.length>0?s.vhmongo_firebase.database().getDocsByFields("vhbill_details",c,{},{date:1},0).then((function(t){if(t.length>0)for(var e=0;e<u.length;e++){for(var o=Object.assign({},u[e]),i={id_product:o._id,name:o.name,unit:o.unit,barcode:o.barcode,img:o.img,id_customer:n,sales_btax:0,sales_atax:0,quantity:0},a=0;a<t.length;a++)if(3==t[a].bill_type)if(5===t[a].ptype)for(var s=0;s<t[a].combos.length;s++)u[e]._id===t[a].combos[s].id_product&&(!0,i.quantity=i.quantity-t[a].combos[s].quantity*t[a].quantity,i.sales_btax=i.sales_btax-t[a].combos[s].price*t[a].combos[s].quantity*t[a].quantity,i.sales_atax=i.sales_atax-t[a].combos[s].price*t[a].combos[s].quantity*t[a].quantity*(1+t[a].tax/100));else u[e]._id===t[a].id_product&&(!0,i.quantity=i.quantity-t[a].quantity,i.sales_btax=i.sales_btax-t[a].price*t[a].quantity,i.sales_atax=i.sales_atax-t[a].price*t[a].quantity*(1+t[a].tax/100));else if(5===t[a].ptype)for(s=0;s<t[a].combos.length;s++)u[e]._id===t[a].combos[s].id_product&&(!0,i.quantity=i.quantity+t[a].combos[s].quantity*t[a].quantity,i.sales_btax=i.sales_btax+t[a].combos[s].price*t[a].combos[s].quantity*t[a].quantity,i.sales_atax=i.sales_atax+t[a].combos[s].price*t[a].combos[s].quantity*t[a].quantity*(1+t[a].tax/100));else u[e]._id===t[a].id_product&&(!0,i.quantity=i.quantity+t[a].quantity,i.sales_btax=i.sales_btax+t[a].price*t[a].quantity,i.sales_atax=i.sales_atax+t[a].price*t[a].quantity*(1+t[a].tax/100));i.sales_atax=Math.round(1e6*i.sales_atax)/1e6,d.quantity=d.quantity+i.quantity,d.sales_btax=d.sales_btax+i.sales_btax,d.sales_atax=d.sales_atax+i.sales_atax,i.index=d.size+1,d.docs.push(i),d.size++,d.empty=!1}console.log("getReportSales_Customers_byProducts_Analytics"),r(d)})):r(d)}))},t.prototype.getReportSales_Customers_byProduct=function(t,e,n,o,i){var a=this;return new Promise((function(s,r){var l=a.getlocalProduct(o),c=new Array;a.getlocalProductAndCombos(o).forEach((function(t){c.push(t._id)}));for(var u,d=l.type,_={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0},p=new Array,b=[1,3,15],f=0;f<b.length;f++)u="all"===i||void 0===i?{date:{$gte:t,$lte:e},id_customer:{$eq:n},id_product:{$in:c},bill_type:{$eq:b[f]}}:{date:{$gte:t,$lte:e},id_customer:{$eq:n},id_product:{$in:c},bill_type:{$eq:b[f]},id_branch:{$eq:i}},p[f]=a.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0);Promise.all(p).then((function(t){var e,n=t.flat();if(n.length>0)for(var o=0;o<n.length;o++){var i=new Array;if(i[0]={id_product:l._id,name:l.name,unit:l.unit,barcode:l.barcode,img:l.img,bill_code:n[o].bill_code,bill_type:n[o].bill_type,id_bill:n[o].id_bill,date:n[o].date,tax:n[o].tax,salesman:null===(e=a.vhAuth.getlocalEmployee(n[o].id_employee))||void 0===e?void 0:e.name,customer:a.getlocalCustomer(n[o].id_customer).name},3==n[o].bill_type)if(1===d||2===d)if(null!=n[o].combos)for(var r=0;r<n[o].combos.length;r++)n[o].combos[r].id_product===l._id&&(i[0].quantity=-n[o].combos[r].quantity*n[o].quantity,i[0].price=n[o].combos[r].price);else i[0].quantity=-n[o].quantity,i[0].price=n[o].price;else 5===d&&(i[0].quantity=-n[o].quantity,i[0].price=n[o].price);else if(1===d||2===d)if(null!=n[o].combos)for(r=0;r<n[o].combos.length;r++)n[o].combos[r].id_product===l._id&&(i[0].quantity=n[o].combos[r].quantity*n[o].quantity,i[0].price=n[o].combos[r].price);else i[0].quantity=n[o].quantity,i[0].price=n[o].price;else 5===d&&(i[0].quantity=n[o].quantity,i[0].price=n[o].price);i.forEach((function(t){t.sales_btax=t.price*t.quantity,t.sales_atax=t.price*t.quantity*(1+t.tax/100),t.index=_.size+1,_.docs.push(t),_.size++,_.empty=!1,_.quantity=_.quantity+t.quantity,_.sales_btax=_.sales_btax+t.price*t.quantity,_.sales_atax=_.sales_atax+t.price*t.quantity*(1+Number(t.tax)/100)}))}console.log("getReportSales_Customers_byProduct"),s(_)}))}))},t.prototype.getReportSales_Employees_byEmployees=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Array;if("all"===n)r=i.vhAuth.getlocalEmployees();else{var l=i.vhAuth.getlocalEmployee(n);r.push(l)}var c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};if(r.length>0){var u=void 0;u="all"===n?"all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1,3,15]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1,3,15]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$gte:t,$lte:e},id_employee:{$eq:n},bill_type:{$in:[1,3,15]}}:{date:{$gte:t,$lte:e},id_employee:{$eq:n},bill_type:{$in:[1,3,15]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0).then((function(t){if(t.length>0)for(var e=0;e<r.length;e++){for(var n=!1,o={id_employee:r[e]._id,name:r[e].name,sales_btax:0,sales_atax:0,quantity:0},i=0;i<t.length;i++)if(r[e]._id===t[i].id_employee)if(n=!0,3==t[i].bill_type)if(5===t[i].ptype){if(null!=t[i].combos)for(var s=0;s<t[i].combos.length;s++)o.quantity=o.quantity-t[i].combos[s].quantity*t[i].quantity,o.sales_btax=o.sales_btax-t[i].combos[s].price*t[i].combos[s].quantity*t[i].quantity,o.sales_atax=o.sales_atax-t[i].combos[s].price*t[i].combos[s].quantity*t[i].quantity*(1+t[i].tax/100)}else o.quantity=o.quantity-t[i].quantity,o.sales_btax=o.sales_btax-t[i].price*t[i].quantity,o.sales_atax=o.sales_atax-t[i].price*t[i].quantity*(1+t[i].tax/100);else if(5===t[i].ptype){if(null!=t[i].combos)for(s=0;s<t[i].combos.length;s++)o.quantity=o.quantity+t[i].combos[s].quantity*t[i].quantity,o.sales_btax=o.sales_btax+t[i].combos[s].price*t[i].combos[s].quantity*t[i].quantity,o.sales_atax=o.sales_atax+t[i].combos[s].price*t[i].combos[s].quantity*t[i].quantity*(1+t[i].tax/100)}else o.quantity=o.quantity+t[i].quantity,o.sales_btax=o.sales_btax+t[i].price*t[i].quantity,o.sales_atax=o.sales_atax+t[i].price*t[i].quantity*(1+t[i].tax/100);n&&(c.quantity=c.quantity+o.quantity,c.sales_btax=c.sales_btax+o.sales_btax,c.sales_atax=c.sales_atax+o.sales_atax,o.index=c.size+1,c.docs.push(o),c.size++,c.empty=!1)}console.log("getReportSales_Employees_byEmployees"),a(c)}))}else a(c)}))},t.prototype.getReportSales_Employees_byProducts=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l=i.getlocalProducts(12);r=r="all"===o||void 0===o?{date:{$gte:t,$lte:e},id_employee:{$eq:n},bill_type:{$in:[1,3,15]}}:{date:{$gte:t,$lte:e},id_employee:{$eq:n},bill_type:{$in:[1,3,15]},id_branch:{$eq:o}};var c={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0};l.length>0?i.vhmongo_firebase.database().getDocsByFields("vhbill_details",r,{},{date:1},0).then((function(t){if(t.length>0)for(var e=0;e<l.length;e++){for(var n=!1,o=Object.assign({},l[e]),i={id_product:o._id,name:o.name,unit:o.unit,barcode:o.barcode,img:o.img,sales_btax:0,sales_atax:0,quantity:0},s=0;s<t.length;s++)if(3==t[s].bill_type)if(5===t[s].ptype)for(var r=0;r<t[s].combos.length;r++)l[e]._id===t[s].combos[r].id_product&&(n=!0,i.quantity=i.quantity-t[s].combos[r].quantity*t[s].quantity,i.sales_btax=i.sales_btax-t[s].combos[r].price*t[s].combos[r].quantity*t[s].quantity,i.sales_atax=i.sales_atax-t[s].combos[r].price*t[s].combos[r].quantity*t[s].quantity*(1+t[s].tax/100));else l[e]._id===t[s].id_product&&(n=!0,i.quantity=i.quantity-t[s].quantity,i.sales_btax=i.sales_btax-t[s].price*t[s].quantity,i.sales_atax=i.sales_atax-t[s].price*t[s].quantity*(1+t[s].tax/100));else if(5===t[s].ptype)for(r=0;r<t[s].combos.length;r++)l[e]._id===t[s].combos[r].id_product&&(n=!0,i.quantity=i.quantity+t[s].combos[r].quantity*t[s].quantity,i.sales_btax=i.sales_btax+t[s].combos[r].price*t[s].combos[r].quantity*t[s].quantity,i.sales_atax=i.sales_atax+t[s].combos[r].price*t[s].combos[r].quantity*t[s].quantity*(1+t[s].tax/100));else l[e]._id===t[s].id_product&&(n=!0,i.quantity=i.quantity+t[s].quantity,i.sales_btax=i.sales_btax+t[s].price*t[s].quantity,i.sales_atax=i.sales_atax+t[s].price*t[s].quantity*(1+t[s].tax/100));n&&(i.sales_atax=Math.round(1e6*i.sales_atax)/1e6,c.quantity=c.quantity+i.quantity,c.sales_btax=c.sales_btax+i.sales_btax,c.sales_atax=c.sales_atax+i.sales_atax,i.index=c.size+1,c.docs.push(i),c.size++,c.empty=!1)}console.log("getReportSales_Employees_byProducts"),a(c)})):a(c)}))},t.prototype.getReportSales_Employees_byProduct=function(t,e,n,o,i){var a=this;return new Promise((function(s,r){var l=a.getlocalProduct(o),c=new Array;a.getlocalProductAndCombos(o).forEach((function(t){c.push(t._id)}));for(var u,d=l.type,_={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0,quantity:0},p=new Array,b=[1,3,15],f=0;f<b.length;f++)u="all"===i||void 0===i?{date:{$gte:t,$lte:e},id_employee:{$eq:n},id_product:{$in:c},bill_type:{$eq:b[f]}}:{date:{$gte:t,$lte:e},id_employee:{$eq:n},id_product:{$in:c},bill_type:{$eq:b[f]},id_branch:{$eq:i}},p[f]=a.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0);Promise.all(p).then((function(t){var e,n=t.flat();if(n.length>0)for(var o=0;o<n.length;o++){var i=new Array;if(i[0]={id_product:l._id,name:l.name,unit:l.unit,barcode:l.barcode,img:l.img,bill_code:n[o].bill_code,bill_type:n[o].bill_type,id_bill:n[o].id_bill,date:n[o].date,tax:n[o].tax,salesman:null===(e=a.vhAuth.getlocalEmployee(n[o].id_employee))||void 0===e?void 0:e.name,customer:a.getlocalCustomer(n[o].id_customer).name},3==n[o].bill_type)if(1===d||2===d)if(null!=n[o].combos)for(var r=0;r<n[o].combos.length;r++)n[o].combos[r].id_product===l._id&&(i[0].quantity=-n[o].combos[r].quantity*n[o].quantity,i[0].price=n[o].combos[r].price);else i[0].quantity=-n[o].quantity,i[0].price=n[o].price;else 5===d&&(i[0].quantity=-n[o].quantity,i[0].price=n[o].price);else if(1===d||2===d)if(null!=n[o].combos)for(r=0;r<n[o].combos.length;r++)n[o].combos[r].id_product===l._id&&(i[0].quantity=n[o].combos[r].quantity*n[o].quantity,i[0].price=n[o].combos[r].price);else i[0].quantity=n[o].quantity,i[0].price=n[o].price;else 5===d&&(i[0].quantity=n[o].quantity,i[0].price=n[o].price);i.forEach((function(t){t.sales_btax=t.price*t.quantity,t.sales_atax=t.price*t.quantity*(1+t.tax/100),t.index=_.size+1,_.docs.push(t),_.size++,_.empty=!1,_.quantity=_.quantity+t.quantity,_.sales_btax=_.sales_btax+t.price*t.quantity,_.sales_atax=_.sales_atax+t.price*t.quantity*(1+Number(t.tax)/100)}))}console.log("getReportSales_Employees_byProduct"),s(_)}))}))},t.prototype.getReportInputOutputReturns_byTime_byIDProduct_byBillTypeArray=function(t,e,n,o,i,a){var s=this;return new Promise((function(r,l){var c=new Array,u=new Array,d=new Array;if(1===o?d=[1,5]:2===o&&(d=[2,5]),"all"===n)c=s.vhAlgorithm.sortVietnamesebyASC(s.getlocalProducts(o),"name");else{var _=s.getlocalProduct(n);c.push(_),s.getlocalProductAndCombos(n).forEach((function(t){u.push(t._id)}))}var p={docs:new Array,empty:!0,size:0,quantity:0,pay_btax:0,pay_atax:0};if(c.length>0){for(var b=void 0,f=new Array,h=0;h<i.length;h++)b="all"===n?"all"===a||void 0===a?{date:{$gte:t,$lte:e},ptype:{$in:d},bill_type:{$eq:i[h]}}:{date:{$gte:t,$lte:e},ptype:{$in:d},bill_type:{$eq:i[h]},id_branch:{$eq:a}}:"all"===a||void 0===a?{date:{$gte:t,$lte:e},id_product:{$in:u},bill_type:{$eq:i[h]}}:{date:{$gte:t,$lte:e},id_product:{$in:u},bill_type:{$eq:i[h]},id_branch:{$eq:a}},f[h]=s.vhmongo_firebase.database().getDocsByFields("vhbill_details",b,{},{date:1},0);Promise.all(f).then((function(t){for(var e=t.flat(),n=0;n<c.length;n++){for(var o={_id:c[n]._id,name:c[n].name,type:c[n].type,unit:c[n].unit,quantity:0,pay_btax:0,pay_atax:0},i=0;i<e.length;i++)if(1===e[i].ptype)e[i].id_product===c[n]._id&&(o.pay_btax=o.pay_btax+e[i].price*e[i].quantity,o.pay_atax=o.pay_atax+e[i].price*e[i].quantity*(1+e[i].tax/100),o.quantity=o.quantity+e[i].quantity,p.pay_btax=p.pay_btax+e[i].price*e[i].quantity,p.pay_atax=p.pay_atax+e[i].price*e[i].quantity*(1+e[i].tax/100),p.quantity=p.quantity+e[i].quantity);else if(5===e[i].ptype)for(var a=0;a<e[i].combos.length;a++)e[i].combos[a].id_product===o._id&&(o.pay_btax=o.pay_btax+e[i].combos[a].price*e[i].combos[a].quantity*e[i].quantity,o.pay_atax=o.pay_atax+e[i].combos[a].price*e[i].combos[a].quantity*e[i].quantity*(1+e[i].tax/100),o.quantity=o.quantity+e[i].combos[a].quantity*e[i].quantity,p.pay_btax=p.pay_btax+e[i].combos[a].price*e[i].combos[a].quantity*e[i].quantity,p.pay_atax=p.pay_atax+e[i].combos[a].price*e[i].combos[a].quantity*e[i].quantity*(1+e[i].tax/100),p.quantity=p.quantity+e[i].combos[a].quantity*e[i].quantity);o.pay_atax=Math.round(1e6*o.pay_atax)/1e6,p.pay_atax=Math.round(1e6*p.pay_atax)/1e6,p.docs.push(o),p.size++,p.empty=!1}r(p)}))}else console.log("server -> products khong ton tai trong CSDL: "),r(p)}))},t.prototype.getReportInputOutputReturns_Detail_byTime_byIDProduct_byBillTypeArray=function(t,e,n,o,i){var a=this;return new Promise((function(s,r){var l,c=a.getlocalProduct(n),u={docs:new Array,empty:!0,size:0,quantity:0,pay_btax:0,pay_atax:0},d=new Array,_=new Array;a.getlocalProductAndCombos(n).forEach((function(t){_.push(t._id)}));for(var p=0;p<_.length;p++)l="all"===i||void 0===i?{date:{$gte:t,$lte:e},id_product:{$eq:_[p]},bill_type:{$in:o}}:{date:{$gte:t,$lte:e},id_product:{$eq:_[p]},bill_type:{$in:o},id_branch:{$eq:i}},d[p]=a.vhmongo_firebase.database().getDocsByFields("vhbill_details",l,{},{date:1},0);a.vhmongo_firebase.database().getDocsByFields("vhbill_details",l,{},{date:1},0).then((function(t){for(var e,n,o,i,a,r,l,d,_,p,b,f,h=0;h<t.length;h++){var y={id_bill:null===(e=t[h])||void 0===e?void 0:e.id_bill,bill_code:null===(n=t[h])||void 0===n?void 0:n.bill_code,bill_type:null===(o=t[h])||void 0===o?void 0:o.bill_type,date:null===(i=t[h])||void 0===i?void 0:i.date,name:c.name,unit:c.unit};if((null===(a=t[h])||void 0===a?void 0:a.id_cashier)&&(y.id_cashier=null===(r=t[h])||void 0===r?void 0:r.id_cashier),(null===(l=t[h])||void 0===l?void 0:l.id_employee)&&(y.id_employee=null===(d=t[h])||void 0===d?void 0:d.id_employee),(null===(_=t[h])||void 0===_?void 0:_.id_customer)&&(y.id_customer=null===(p=t[h])||void 0===p?void 0:p.id_customer),(null===(b=t[h])||void 0===b?void 0:b.id_supplier)&&(y.id_supplier=null===(f=t[h])||void 0===f?void 0:f.id_supplier),1===t[h].ptype)y.price_btax=t[h].price,y.price_atax=t[h].price*(1+t[h].tax/100),y.pay_btax=t[h].price*t[h].quantity,y.pay_atax=t[h].price*t[h].quantity*(1+t[h].tax/100),y.quantity=t[h].quantity,u.quantity=u.quantity+t[h].quantity,u.pay_btax=u.pay_btax+t[h].price*t[h].quantity,u.pay_atax=u.pay_atax+t[h].price*t[h].quantity*(1+t[h].tax/100);else if(5===t[h].ptype)for(var m=0;m<t[h].combos.length;m++)t[h].combos[m].id_product===c._id&&(y.price_btax=t[h].combos[m].price,y.price_atax=t[h].combos[m].price*(1+t[h].tax/100),y.pay_btax=t[h].combos[m].price*t[h].combos[m].quantity*t[h].quantity,y.pay_atax=t[h].combos[m].price*t[h].combos[m].quantity*t[h].quantity*(1+t[h].tax/100),y.quantity=t[h].combos[m].quantity*t[h].quantity,u.quantity=u.quantity+t[h].combos[m].quantity*t[h].quantity,u.pay_btax=u.pay_btax+t[h].combos[m].price*t[h].combos[m].quantity*t[h].quantity,u.pay_atax=u.pay_atax+t[h].combos[m].price*t[h].combos[m].quantity*t[h].quantity*(1+t[h].tax/100));0==c.inquantity&&0==c.outquantity||(y.price_atax=Math.round(1e6*y.price_atax)/1e6,y.pay_atax=Math.round(1e6*y.pay_atax)/1e6,u.pay_atax=Math.round(1e6*u.pay_atax)/1e6,y.index=u.size+1,u.docs.push(y),u.size++,u.empty=!1)}console.log("getReportInputOutputInventory_byTime_byIDProduct"),s(u)}))}))},t.prototype.getReportInputOutputInventory_byTime_byIDProduct=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r={docs:new Array,empty:!0,size:0,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0,stock_first:0,stock_last:0,cost_stock_first_btax:0,cost_stock_first_atax:0,cost_stock_last_btax:0,cost_stock_last_atax:0},l=i.vhAuth.getStore(),c=new Array;if("all"===n)c=i.vhAlgorithm.sortVietnamesebyASC(i.getlocalProducts(1),"name");else{var u=i.getlocalProduct(n);c.push(u)}var d=null,_=null;if("all"===n)if("all"===o||void 0===o)console.log("trường hợp này chưa có hàm, liên hệ anh Huy viết");else{if(null!=c[0][o]&&null!=c[0][o].inventory){for(var p=0;p<c[0][o].inventory.length&&!(new Date(c[0][o].inventory[p].date).getTime()>t.getTime());p++)_=new Date(c[0][o].inventory[p].date),d=p,p;for(p=0;p<c[0][o].inventory.length&&!(new Date(c[0][o].inventory[p].date).getTime()>e.getTime());p++)p}if(_){for(var b=!1,f=0;f<c.length;f++)null!=c[f][o]&&null!=c[f][o].inventory||(b=!0);if(b)return console.log("Vui lòng đồng bộ kho để lấy về dữ liệu mới nhất"),a(r)}}else if("all"===o||void 0===o)console.log("trường hợp này chưa có hàm, liên hệ anh Huy viết");else if(null!=c[0][o]&&null!=c[0][o].inventory)for(p=0;p<c[0][o].inventory.length&&!(new Date(c[0][o].inventory[p].date).getTime()>t.getTime());p++)_=new Date(c[0][o].inventory[p].date),d=p;if(_||(_=new Date(l.registrationdate)),c.length>0){var h,y=new Array;if("all"===n)h="all"===o||void 0===o?{date:{$gte:_,$lte:e},bill_type:{$in:[1,10,15,30,2,3,9,31]}}:{date:{$gte:_,$lte:e},bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:o}},y[0]=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",h,{},{date:1},0);else{var m=i.getlocalProductAndCombos(n);for(f=0;f<m.length;f++)h="all"===o||void 0===o?{date:{$gte:_,$lte:e},id_product:{$eq:m[f]._id},bill_type:{$in:[1,10,15,30,2,3,9,31]}}:{date:{$gte:_,$lte:e},id_product:{$eq:m[f]._id},bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:o}},y[f]=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",h,{},{date:1},0)}Promise.all(y).then((function(e){for(var n=e.flat(),i=0;i<c.length;i++){for(var s={stock_first:0,cost_stock_first_btax:0,cost_stock_first_atax:0,unit_cost_stock_first_btax:0,unit_cost_stock_first_atax:0,inquantity_tofirst:0,outquantity_tofirst:0,pay_tofirst_btax:0,pay_tofirst_atax:0,profit_first_btax:0,profit_first_atax:0,sales_tofirst_btax:0,sales_tofirst_atax:0},l={_id:c[i]._id,name:c[i].name,type:c[i].type,unit:c[i].unit,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0,stock_first:0,stock_last:0,cost_stock_first_btax:0,cost_stock_first_atax:0,cost_stock_last_btax:0,cost_stock_last_atax:0},u=0,_=0,p=0,b=0,f=0,h=0,y=0,m=0;m<n.length;m++)if(1===n[m].ptype){if(n[m].id_product===c[i]._id){var v=new Date(n[m].date);1===n[m].bill_type||10===n[m].bill_type||15===n[m].bill_type||30===n[m].bill_type?v>=new Date(t)?(l.revenue_btax=l.revenue_btax+n[m].price*n[m].quantity,l.revenue_atax=l.revenue_atax+n[m].price*n[m].quantity*(1+n[m].tax/100),l.outquantity=l.outquantity+n[m].quantity,r.revenue_btax=r.revenue_btax+n[m].price*n[m].quantity,r.revenue_atax=r.revenue_atax+n[m].price*n[m].quantity*(1+n[m].tax/100),r.outquantity=r.outquantity+n[m].quantity):u+=n[m].quantity:2===n[m].bill_type||3===n[m].bill_type||31===n[m].bill_type?(v>=new Date(t)?(l.cost_btax=l.cost_btax+n[m].price*n[m].quantity,l.cost_atax=l.cost_atax+n[m].price*n[m].quantity*(1+n[m].tax/100),l.inquantity=l.inquantity+n[m].quantity,r.cost_btax=r.cost_btax+n[m].price*n[m].quantity,r.cost_atax=r.cost_atax+n[m].price*n[m].quantity*(1+n[m].tax/100),r.inquantity=r.inquantity+n[m].quantity):(_+=n[m].quantity,p+=n[m].price*n[m].quantity,b+=n[m].price*n[m].quantity*(1+n[m].tax/100)),f+=n[m].quantity,h+=n[m].price*n[m].quantity,y+=n[m].price*n[m].quantity*(1+n[m].tax/100)):9===n[m].bill_type&&(s.stock_first=s.stock_first+n[m].quantity,s.cost_stock_first_btax=s.cost_stock_first_btax+n[m].price*n[m].quantity,s.cost_stock_first_atax=s.cost_stock_first_atax+n[m].price*n[m].quantity*(1+n[m].tax/100))}}else if(5===n[m].ptype)for(var g=0;g<n[m].combos.length;g++)if(n[m].combos[g].id_product===c[i]._id){v=new Date(n[m].date);1===n[m].bill_type||10===n[m].bill_type||15===n[m].bill_type||30===n[m].bill_type?v>=new Date(t)?(l.revenue_btax=l.revenue_btax+n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity,l.revenue_atax=l.revenue_atax+n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity*(1+n[m].tax/100),l.outquantity=l.outquantity+n[m].combos[g].quantity*n[m].quantity,r.revenue_btax=r.revenue_btax+n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity,r.revenue_atax=r.revenue_atax+n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity*(1+n[m].tax/100),r.outquantity=r.outquantity+n[m].combos[g].quantity*n[m].quantity):u+=n[m].combos[g].quantity*n[m].quantity:2===n[m].bill_type||3===n[m].bill_type||31===n[m].bill_type?(v>=new Date(t)?(l.cost_btax=l.cost_btax+n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity,l.cost_atax=l.cost_atax+n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity*(1+n[m].tax/100),l.inquantity=l.inquantity+n[m].combos[g].quantity*n[m].quantity,r.cost_btax=r.cost_btax+n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity,r.cost_atax=r.cost_atax+n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity*(1+n[m].tax/100),r.inquantity=r.inquantity+n[m].combos[g].quantity*n[m].quantity):(p+=n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity,b+=n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity*(1+n[m].tax/100),_+=n[m].combos[g].quantity*n[m].quantity),f+=n[m].combos[g].quantity*n[m].quantity,h+=n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity,y+=n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity*(1+n[m].tax/100)):9===n[m].bill_type&&(s.stock_first=s.stock_first+n[m].combos[g].quantity*n[m].quantity,s.cost_stock_first_btax=s.cost_stock_first_btax+n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity,s.cost_stock_first_atax=s.cost_stock_first_atax+n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity*(1+n[m].tax/100));break}null!=d&&(s=Object.assign({},c[i][o].inventory[d])),l.stock_first=s.stock_first+_-u,l.stock_last=l.stock_first+l.inquantity-l.outquantity,s.stock_first+_!=0&&(l.cost_stock_first_btax=(s.cost_stock_first_btax+p)/(s.stock_first+_)*l.stock_first,l.cost_stock_first_atax=(s.cost_stock_first_atax+b)/(s.stock_first+_)*l.stock_first),s.stock_first+f!=0&&(l.cost_stock_last_btax=(s.cost_stock_first_btax+h)/(s.stock_first+f)*l.stock_last,l.cost_stock_last_atax=(s.cost_stock_first_atax+y)/(s.stock_first+f)*l.stock_last),r.stock_first=r.stock_first+l.stock_first,r.stock_last=r.stock_last+l.stock_last,r.cost_stock_first_btax=r.cost_stock_first_btax+l.cost_stock_first_btax,r.cost_stock_first_atax=r.cost_stock_first_atax+l.cost_stock_first_atax,r.cost_stock_last_btax=r.cost_stock_last_btax+l.cost_stock_last_btax,r.cost_stock_last_atax=r.cost_stock_last_atax+l.cost_stock_last_atax,0==l.stock_first&&0==l.stock_last&&0==l.inquantity&&0==l.outquantity||(l.revenue_atax=Math.round(1e6*l.revenue_atax)/1e6,l.cost_atax=Math.round(1e6*l.cost_atax)/1e6,l.cost_stock_first_atax=Math.round(1e6*l.cost_stock_first_atax)/1e6,l.cost_stock_last_atax=Math.round(1e6*l.cost_stock_last_atax)/1e6,l.index=r.size+1,r.docs.push(l),r.size++,r.empty=!1)}a(r),console.log("getReportInputOutputInventory_byTime_byIDProduct3",r)}))}else console.log("server -> products khong ton tai trong CSDL: "),a(r)}))},t.prototype.makeCorrectStock1stDayOfMonth=function(t,e,n,o,i){var a=this;return new Promise((function(s,r){for(var l=new Array,c=0;c<n.length;c++)if(null!=n[c][i]&&null!=n[c][i].inventory){for(var u=n[c][i].inventory[t],d=t+1;d<=e;d++)n[c][i].inventory[d].inquantity_tofirst=u.inquantity_tofirst,n[c][i].inventory[d].pay_tofirst_btax=u.pay_tofirst_btax,n[c][i].inventory[d].pay_tofirst_atax=u.pay_tofirst_atax,n[c][i].inventory[d].outquantity_tofirst=u.outquantity_tofirst,n[c][i].inventory[d].sales_tofirst_btax=u.sales_tofirst_btax,n[c][i].inventory[d].sales_tofirst_atax=u.sales_tofirst_atax,n[c][i].inventory[d].stock_first=0,n[c][i].inventory[d].unit_cost_stock_first_btax=0,n[c][i].inventory[d].unit_cost_stock_first_atax=0,n[c][i].inventory[d].cost_stock_first_btax=0,n[c][i].inventory[d].cost_stock_first_atax=0,n[c][i].inventory[d].profit_first_btax=0,n[c][i].inventory[d].profit_first_atax=0;if(o.length>0)for(var _=0;_<o.length;_++)if(1===o[_].ptype){if(o[_].id_product===n[c]._id)for(d=t+1;d<=e;d++)new Date(o[_].date).getTime()<new Date(n[c][i].inventory[d].date).getTime()&&(1===o[_].bill_type||10===o[_].bill_type||15===o[_].bill_type||30===o[_].bill_type?(n[c][i].inventory[d].outquantity_tofirst=n[c][i].inventory[d].outquantity_tofirst+o[_].quantity,n[c][i].inventory[d].sales_tofirst_btax=n[c][i].inventory[d].sales_tofirst_btax+o[_].price*o[_].quantity,n[c][i].inventory[d].sales_tofirst_atax=n[c][i].inventory[d].sales_tofirst_atax+o[_].price*o[_].quantity*(1+o[_].tax/100)):2!==o[_].bill_type&&3!==o[_].bill_type&&9!==o[_].bill_type&&31!==o[_].bill_type||(n[c][i].inventory[d].inquantity_tofirst=n[c][i].inventory[d].inquantity_tofirst+o[_].quantity,n[c][i].inventory[d].pay_tofirst_btax=n[c][i].inventory[d].pay_tofirst_btax+o[_].price*o[_].quantity,n[c][i].inventory[d].pay_tofirst_atax=n[c][i].inventory[d].pay_tofirst_atax+o[_].price*o[_].quantity*(1+o[_].tax/100)))}else if(5===o[_].ptype)for(var p=0;p<o[_].combos.length;p++)if(o[_].combos[p].id_product===n[c]._id)for(d=t+1;d<=e;d++)new Date(o[_].date).getTime()<new Date(n[c][i].inventory[d].date).getTime()&&(1===o[_].bill_type||10===o[_].bill_type||15===o[_].bill_type||30===o[_].bill_type?(n[c][i].inventory[d].outquantity_tofirst=n[c][i].inventory[d].outquantity_tofirst+o[_].combos[p].quantity*o[_].quantity,n[c][i].inventory[d].sales_tofirst_btax=n[c][i].inventory[d].sales_tofirst_btax+o[_].combos[p].price*o[_].combos[p].quantity*o[_].quantity,n[c][i].inventory[d].sales_tofirst_atax=n[c][i].inventory[d].sales_tofirst_atax+o[_].combos[p].price*o[_].combos[p].quantity*o[_].quantity*(1+o[_].tax/100)):2!==o[_].bill_type&&3!==o[_].bill_type&&9!==o[_].bill_type&&31!==o[_].bill_type||(n[c][i].inventory[d].inquantity_tofirst=n[c][i].inventory[d].inquantity_tofirst+o[_].combos[p].quantity*o[_].quantity,n[c][i].inventory[d].pay_tofirst_btax=n[c][i].inventory[d].pay_tofirst_btax+o[_].combos[p].price*o[_].combos[p].quantity*o[_].quantity,n[c][i].inventory[d].pay_tofirst_atax=n[c][i].inventory[d].pay_tofirst_atax+o[_].combos[p].price*o[_].combos[p].quantity*o[_].quantity*(1+o[_].tax/100)));for(d=t+1;d<=e;d++){var b=n[c][i].inventory[d].inquantity_tofirst-n[c][i].inventory[d-1].inquantity_tofirst,f=n[c][i].inventory[d].pay_tofirst_btax-n[c][i].inventory[d-1].pay_tofirst_btax,h=n[c][i].inventory[d].pay_tofirst_atax-n[c][i].inventory[d-1].pay_tofirst_atax;n[c][i].inventory[d].stock_first=n[c][i].inventory[d].inquantity_tofirst-n[c][i].inventory[d].outquantity_tofirst,n[c][i].inventory[d-1].stock_first+b!=0&&(n[c][i].inventory[d].unit_cost_stock_first_btax=(n[c][i].inventory[d-1].cost_stock_first_btax+f)/(n[c][i].inventory[d-1].stock_first+b),n[c][i].inventory[d].unit_cost_stock_first_atax=(n[c][i].inventory[d-1].cost_stock_first_atax+h)/(n[c][i].inventory[d-1].stock_first+b),n[c][i].inventory[d].cost_stock_first_btax=n[c][i].inventory[d].unit_cost_stock_first_btax*n[c][i].inventory[d].stock_first,n[c][i].inventory[d].cost_stock_first_atax=n[c][i].inventory[d].unit_cost_stock_first_atax*n[c][i].inventory[d].stock_first);var y=n[c][i].inventory[d].outquantity_tofirst-n[c][i].inventory[d-1].outquantity_tofirst,m=n[c][i].inventory[d].unit_cost_stock_first_btax*y,v=n[c][i].inventory[d].unit_cost_stock_first_atax*y,g=n[c][i].inventory[d].sales_tofirst_btax-n[c][i].inventory[d-1].sales_tofirst_btax,x=n[c][i].inventory[d].sales_tofirst_atax-n[c][i].inventory[d-1].sales_tofirst_atax;n[c][i].inventory[d].profit_first_btax=g-m,n[c][i].inventory[d].profit_first_atax=x-v}var q=a.getlocalProduct(n[c]._id);for(d=t+1;d<=e;d++)q[i].inventory[d].inquantity_tofirst!=n[c][i].inventory[d].inquantity_tofirst||q[i].inventory[d].pay_tofirst_btax!=n[c][i].inventory[d].pay_tofirst_btax||q[i].inventory[d].pay_tofirst_atax!=n[c][i].inventory[d].pay_tofirst_atax||q[i].inventory[d].outquantity_tofirst!=n[c][i].inventory[d].outquantity_tofirst||q[i].inventory[d].sales_tofirst_btax!=n[c][i].inventory[d].sales_tofirst_btax||q[i].inventory[d].sales_tofirst_atax!=n[c][i].inventory[d].sales_tofirst_atax||q[i].inventory[d].stock_first!=n[c][i].inventory[d].stock_first||q[i].inventory[d].unit_cost_stock_first_btax!=n[c][i].inventory[d].unit_cost_stock_first_btax||q[i].inventory[d].unit_cost_stock_first_atax!=n[c][i].inventory[d].unit_cost_stock_first_atax||q[i].inventory[d].cost_stock_first_btax!=n[c][i].inventory[d].cost_stock_first_btax||q[i].inventory[d].cost_stock_first_atax!=n[c][i].inventory[d].cost_stock_first_atax||q[i].inventory[d].profit_first_btax!=n[c][i].inventory[d].profit_first_btax||q[i].inventory[d].profit_first_atax!=n[c][i].inventory[d].profit_first_atax?(console.log("k",d),console.log("_product",q),console.log("products[i]",n[c]),l[l.length]=new Promise((function(t,e){t(null)}))):l[l.length]=new Promise((function(t,e){t(null)}))}Promise.all(l).then((function(){console.log("makeCorrectStock1stDayOfMonth"),s(!0)}))}))},t.prototype.getReportInputOutputInventory_byEndTime_byIDProduct_allRecords=function(t,e,n){var o=this;return new Promise((function(i,a){var s=new Array;if("all"===e)s=o.vhAlgorithm.sortVietnamesebyASC(o.getlocalProducts(1),"name");else{var r=o.getlocalProduct(e);s.push(r)}var l={docs:new Array,empty:!0,size:0,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0,stock_last:0,cost_stock_last_btax:0,cost_stock_last_atax:0};if(s.length>0){var c=void 0;c="all"===e?"all"===n||void 0===n?{date:{$lte:t},bill_type:{$in:[1,10,15,30,2,3,9,31]}}:{date:{$lte:t},bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:n}}:"all"===n||void 0===n?{date:{$lte:t},id_product:{$eq:e},bill_type:{$in:[1,10,15,30,2,3,9,31]}}:{date:{$lte:t},id_product:{$eq:e},bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:n}},o.vhmongo_firebase.database().getDocsByFields("vhbill_details",c,{},{date:1},0).then((function(t){for(var e=0;e<s.length;e++){for(var o={_id:s[e]._id,name:s[e].name,type:s[e].type,unit:s[e].unit,img:s[e].img,allow_sell:s[e].allow_sell,barcode:s[e].barcode,price:s[e].price,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0,stock_last:0,cost_stock_last_btax:0,cost_stock_last_atax:0,unit_cost_stock_last_btax:0,unit_cost_stock_last_atax:0},a=0;a<t.length;a++)if(1===t[a].ptype)t[a].id_product===s[e]._id&&(1===t[a].bill_type||10===t[a].bill_type||15===t[a].bill_type||30===t[a].bill_type?(o.revenue_btax=o.revenue_btax+t[a].price*t[a].quantity,o.revenue_atax=o.revenue_atax+t[a].price*t[a].quantity*(1+t[a].tax/100),o.outquantity=o.outquantity+t[a].quantity,l.revenue_btax=l.revenue_btax+t[a].price*t[a].quantity,l.revenue_atax=l.revenue_atax+t[a].price*t[a].quantity*(1+t[a].tax/100),l.outquantity=l.outquantity+t[a].quantity):2!==t[a].bill_type&&3!==t[a].bill_type&&9!==t[a].bill_type&&31!==t[a].bill_type||(o.cost_btax=o.cost_btax+t[a].price*t[a].quantity,o.cost_atax=o.cost_atax+t[a].price*t[a].quantity*(1+t[a].tax/100),o.inquantity=o.inquantity+t[a].quantity,l.cost_btax=l.cost_btax+t[a].price*t[a].quantity,l.cost_atax=l.cost_atax+t[a].price*t[a].quantity*(1+t[a].tax/100),l.inquantity=l.inquantity+t[a].quantity));else if(5===t[a].ptype)if("all"===n||void 0===n);else for(var r=0;r<t[a].combos.length;r++)t[a].combos[r].id_product===s[e]._id&&(1===t[a].bill_type||10===t[a].bill_type||15===t[a].bill_type||30===t[a].bill_type?(o.revenue_btax=o.revenue_btax+t[a].combos[r].price*t[a].combos[r].quantity*t[a].quantity,o.revenue_atax=o.revenue_atax+t[a].combos[r].price*t[a].combos[r].quantity*t[a].quantity*(1+t[a].tax/100),o.outquantity=o.outquantity+t[a].combos[r].quantity*t[a].quantity,l.revenue_btax=l.revenue_btax+t[a].combos[r].price*t[a].combos[r].quantity*t[a].quantity,l.revenue_atax=l.revenue_atax+t[a].combos[r].price*t[a].combos[r].quantity*t[a].quantity*(1+t[a].tax/100),l.outquantity=l.outquantity+t[a].combos[r].quantity*t[a].quantity):2!==t[a].bill_type&&3!==t[a].bill_type&&9!==t[a].bill_type&&31!==t[a].bill_type||(o.cost_btax=o.cost_btax+t[a].combos[r].price*t[a].combos[r].quantity*t[a].quantity,o.cost_atax=o.cost_atax+t[a].combos[r].price*t[a].combos[r].quantity*t[a].quantity*(1+t[a].tax/100),o.inquantity=o.inquantity+t[a].combos[r].quantity*t[a].quantity,l.cost_btax=l.cost_btax+t[a].combos[r].price*t[a].combos[r].quantity*t[a].quantity,l.cost_atax=l.cost_atax+t[a].combos[r].price*t[a].combos[r].quantity*t[a].quantity*(1+t[a].tax/100),l.inquantity=l.inquantity+t[a].combos[r].quantity*t[a].quantity));o.stock_last=o.inquantity-o.outquantity,0!=o.inquantity&&(o.unit_cost_stock_last_btax=o.cost_btax/o.inquantity),0!=o.inquantity&&(o.unit_cost_stock_last_atax=o.cost_atax/o.inquantity),o.cost_stock_last_btax=o.unit_cost_stock_last_btax*o.stock_last,o.cost_stock_last_atax=o.unit_cost_stock_last_atax*o.stock_last,l.stock_last=l.stock_last+o.stock_last,l.cost_stock_last_btax=l.cost_stock_last_btax+o.cost_stock_last_btax,l.cost_stock_last_atax=l.cost_stock_last_atax+o.cost_stock_last_atax,o.revenue_atax=Math.round(1e6*o.revenue_atax)/1e6,o.cost_atax=Math.round(1e6*o.cost_atax)/1e6,o.cost_stock_last_atax=Math.round(1e6*o.cost_stock_last_atax)/1e6,o.unit_cost_stock_last_atax=Math.round(1e6*o.unit_cost_stock_last_atax)/1e6,l.revenue_atax=Math.round(1e6*l.revenue_atax)/1e6,l.cost_atax=Math.round(1e6*l.cost_atax)/1e6,l.cost_stock_last_atax=Math.round(1e6*l.cost_stock_last_atax)/1e6,l.index=l.size+1,l.docs.push(o),l.size++,l.empty=!1}console.log("getReportInputOutputInventory_byEndTime_byIDProduct"),i(l)}))}else console.log("server -> products khong ton tai trong CSDL: "),i(l)}))},t.prototype.getReportInputOutputInventory_byEndTime_byIDProduct=function(t,e,n){var o=this;return new Promise((function(i,a){var s=o.getDefaultBranch()._id,r={docs:new Array,empty:!0,size:0},l=o.vhAuth.getStore(),c=new Array;if("all"===e)c=o.vhAlgorithm.sortVietnamesebyASC(o.getlocalProducts(1),"name");else{var u=o.getlocalProduct(e);c.push(u)}var d=null,_=null;if("all"===e)if("all"===n||void 0===n)console.log("trường hợp này chưa có hàm, liên hệ anh Huy viết");else{if(null!=c[0][n]&&null!=c[0][n].inventory)for(var p=0;p<c[0][n].inventory.length&&!(new Date(c[0][n].inventory[p].date).getTime()>t.getTime());p++)_=new Date(c[0][n].inventory[p].date),d=p;if(_){for(var b=!1,f=0;f<c.length;f++)null!=c[f][n]&&null!=c[f][n].inventory||(b=!0);if(b)return console.log("Vui lòng đồng bộ kho để lấy về dữ liệu mới nhất"),i(r)}}else if("all"===n||void 0===n)console.log("trường hợp này chưa có hàm, liên hệ anh Huy viết");else if(null!=c[0][n]&&null!=c[0][n].inventory)for(p=0;p<c[0][n].inventory.length&&!(new Date(c[0][n].inventory[p].date).getTime()>t.getTime());p++)_=new Date(c[0][n].inventory[p].date),d=p;if(_||(_=new Date(l.registrationdate)),c.length>0){var h,y=new Array;if("all"===e)h="all"===n||void 0===n?{date:{$gte:_,$lte:t},bill_type:{$in:[1,10,15,30,2,3,9,31]}}:{date:{$gte:_,$lte:t},bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:n}},y[0]=o.vhmongo_firebase.database().getDocsByFields("vhbill_details",h,{},{date:1},0);else{var m=o.getlocalProductAndCombos(e);for(f=0;f<m.length;f++)h="all"===n||void 0===n?{date:{$gte:_,$lte:t},id_product:{$eq:m[f]._id},bill_type:{$in:[1,10,15,30,2,3,9,31]}}:{date:{$gte:_,$lte:t},id_product:{$eq:m[f]._id},bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:n}},y[f]=o.vhmongo_firebase.database().getDocsByFields("vhbill_details",h,{},{date:1},0)}Promise.all(y).then((function(t){for(var e=t.flat(),n=0;n<c.length;n++){for(var o={stock_first:0,cost_stock_first_btax:0,cost_stock_first_atax:0,unit_cost_stock_first_btax:0,unit_cost_stock_first_atax:0,inquantity_tofirst:0,outquantity_tofirst:0,pay_tofirst_btax:0,pay_tofirst_atax:0,profit_first_btax:0,profit_first_atax:0,sales_tofirst_btax:0,sales_tofirst_atax:0},a={_id:c[n]._id,name:c[n].name,type:c[n].type,unit:c[n].unit,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0,unit_cost_stock_last_btax:0,unit_cost_stock_last_atax:0,stock_first:0,cost_stock_first_btax:0,cost_stock_first_atax:0,stock_last:0,cost_stock_last_btax:0,cost_stock_last_atax:0},l=0;l<e.length;l++)if(1===e[l].ptype){if(e[l].id_product===c[n]._id){new Date(e[l].date);1===e[l].bill_type||10===e[l].bill_type||15===e[l].bill_type||30===e[l].bill_type?a.outquantity=a.outquantity+e[l].quantity:2===e[l].bill_type||3===e[l].bill_type||31===e[l].bill_type?(a.cost_btax=a.cost_btax+e[l].price*e[l].quantity,a.cost_atax=a.cost_atax+e[l].price*e[l].quantity*(1+e[l].tax/100),a.inquantity=a.inquantity+e[l].quantity):9===e[l].bill_type&&(o.stock_first=o.stock_first+e[l].quantity,o.cost_stock_first_btax=o.cost_stock_first_btax+e[l].price*e[l].quantity,o.cost_stock_first_atax=o.cost_stock_first_atax+e[l].price*e[l].quantity*(1+e[l].tax/100))}}else if(5===e[l].ptype)for(var u=0;u<e[l].combos.length;u++)if(e[l].combos[u].id_product===c[n]._id){new Date(e[l].date);1===e[l].bill_type||10===e[l].bill_type||15===e[l].bill_type||30===e[l].bill_type?a.outquantity=a.outquantity+e[l].combos[u].quantity*e[l].quantity:2===e[l].bill_type||3===e[l].bill_type||31===e[l].bill_type?(a.cost_btax=a.cost_btax+e[l].combos[u].price*e[l].combos[u].quantity*e[l].quantity,a.cost_atax=a.cost_atax+e[l].combos[u].price*e[l].combos[u].quantity*e[l].quantity*(1+e[l].tax/100),a.inquantity=a.inquantity+e[l].combos[u].quantity*e[l].quantity):9===e[l].bill_type&&(o.stock_first=o.stock_first+e[l].combos[u].quantity*e[l].quantity,o.cost_stock_first_btax=o.cost_stock_first_btax+e[l].combos[u].price*e[l].combos[u].quantity*e[l].quantity,o.cost_stock_first_atax=o.cost_stock_first_atax+e[l].combos[u].price*e[l].combos[u].quantity*e[l].quantity*(1+e[l].tax/100));break}null!=d&&(o=Object.assign({},c[n][s].inventory[d])),a.stock_first=o.stock_first,a.cost_stock_first_btax=o.cost_stock_first_btax,a.cost_stock_first_atax=o.cost_stock_first_atax,a.stock_first+a.inquantity!=0&&(a.unit_cost_stock_last_btax=(a.cost_stock_first_btax+a.cost_btax)/(a.stock_first+a.inquantity),a.unit_cost_stock_last_atax=(a.cost_stock_first_atax+a.cost_atax)/(a.stock_first+a.inquantity)),a.stock_last=a.stock_first+a.inquantity-a.outquantity,a.cost_stock_last_btax=a.unit_cost_stock_last_btax*a.stock_last,a.cost_stock_last_atax=a.unit_cost_stock_last_atax*a.stock_last,0==a.stock_first&&0==a.stock_last&&0==a.inquantity&&0==a.outquantity||(a.cost_atax=Math.round(1e6*a.cost_atax)/1e6,a.cost_stock_first_atax=Math.round(1e6*a.cost_stock_first_atax)/1e6,a.cost_stock_last_atax=Math.round(1e6*a.cost_stock_last_atax)/1e6,a.index=r.size+1,r.docs.push(a),r.size++,r.empty=!1)}i(r),console.log("getReportInputOutputInventory_byEndTime_byIDProduct",r)}))}else console.log("server -> products khong ton tai trong CSDL: "),i(r)}))},t.prototype.getReportInputOutputInventory_Detail_byEndTime_byIDProduct=function(t,e,n){var o=this;return new Promise((function(i,a){var s,r=o.getlocalProduct(e),l={docs:new Array,empty:!0,size:0,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0},c=new Array,u=new Array;o.getlocalProductAndCombos(e).forEach((function(t){u.push(t._id)}));for(var d=0;d<u.length;d++)s="all"===n||void 0===n?{date:{$lte:t},id_product:{$eq:u[d]},bill_type:{$in:[1,10,15,30,2,3,9,31]}}:{date:{$lte:t},id_product:{$eq:u[d]},bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:n}},c[d]=o.vhmongo_firebase.database().getDocsByFields("vhbill_details",s,{},{date:1},0);Promise.all(c).then((function(t){for(var e,n,o,a,s,c,u,d,_,p,b,f,h,y,m=t.flat(),v=0;v<m.length;v++){var g={id_bill:null===(e=m[v])||void 0===e?void 0:e.id_bill,bill_code:null===(n=m[v])||void 0===n?void 0:n.bill_code,bill_type:null===(o=m[v])||void 0===o?void 0:o.bill_type,date:null===(a=m[v])||void 0===a?void 0:a.date,tax:null===(s=m[v])||void 0===s?void 0:s.tax,name:r.name,unit:r.unit};if((null===(c=m[v])||void 0===c?void 0:c.id_cashier)&&(g.id_cashier=null===(u=m[v])||void 0===u?void 0:u.id_cashier),(null===(d=m[v])||void 0===d?void 0:d.id_employee)&&(g.id_employee=null===(_=m[v])||void 0===_?void 0:_.id_employee),(null===(p=m[v])||void 0===p?void 0:p.id_customer)&&(g.id_customer=null===(b=m[v])||void 0===b?void 0:b.id_customer),(null===(f=m[v])||void 0===f?void 0:f.id_supplier)&&(g.id_supplier=null===(h=m[v])||void 0===h?void 0:h.id_supplier),1===m[v].ptype)g.price_btax=m[v].price,g.price_atax=m[v].price*(1+m[v].tax/100),g.payment_btax=m[v].price*m[v].quantity,g.payment_atax=m[v].price*m[v].quantity*(1+m[v].tax/100),g.quantity=null===(y=m[v])||void 0===y?void 0:y.quantity,1===m[v].bill_type||10===m[v].bill_type||15===m[v].bill_type||30===m[v].bill_type?(g.type="output",l.revenue_btax=l.revenue_btax+m[v].price*m[v].quantity,l.revenue_atax=l.revenue_atax+m[v].price*m[v].quantity*(1+m[v].tax/100),l.outquantity=l.outquantity+m[v].quantity):2===m[v].bill_type||3===m[v].bill_type||31===m[v].bill_type?(g.type="input",l.cost_btax=l.cost_btax+m[v].price*m[v].quantity,l.cost_atax=l.cost_atax+m[v].price*m[v].quantity*(1+m[v].tax/100),l.inquantity=l.inquantity+m[v].quantity):9===m[v].bill_type&&(g.type="beginning",l.cost_btax=l.cost_btax+m[v].price*m[v].quantity,l.cost_atax=l.cost_atax+m[v].price*m[v].quantity*(1+m[v].tax/100),l.inquantity=l.inquantity+m[v].quantity);else if(5===m[v].ptype)for(var x=0;x<m[v].combos.length;x++)m[v].combos[x].id_product===r._id&&(g.price_btax=m[v].combos[x].price,g.price_atax=m[v].combos[x].price*(1+m[v].tax/100),g.payment_btax=m[v].combos[x].price*m[v].combos[x].quantity*m[v].quantity,g.payment_atax=m[v].combos[x].price*m[v].combos[x].quantity*m[v].quantity*(1+m[v].tax/100),g.quantity=m[v].combos[x].quantity*m[v].quantity,1===m[v].bill_type||10===m[v].bill_type||15===m[v].bill_type||30===m[v].bill_type?(g.type="output",l.revenue_btax=l.revenue_btax+m[v].combos[x].price*m[v].combos[x].quantity*m[v].quantity,l.revenue_atax=l.revenue_atax+m[v].combos[x].price*m[v].combos[x].quantity*m[v].quantity*(1+m[v].tax/100),l.outquantity=l.outquantity+m[v].combos[x].quantity*m[v].quantity):2===m[v].bill_type||3===m[v].bill_type||31===m[v].bill_type?(g.type="input",l.cost_btax=l.cost_btax+m[v].combos[x].price*m[v].combos[x].quantity*m[v].quantity,l.cost_atax=l.cost_atax+m[v].combos[x].price*m[v].combos[x].quantity*m[v].quantity*(1+m[v].tax/100),l.inquantity=l.inquantity+m[v].combos[x].quantity*m[v].quantity):9===m[v].bill_type&&(g.type="beginning",l.cost_btax=l.cost_btax+m[v].combos[x].price*m[v].combos[x].quantity*m[v].quantity,l.cost_atax=l.cost_atax+m[v].combos[x].price*m[v].combos[x].quantity*m[v].quantity*(1+m[v].tax/100),l.inquantity=l.inquantity+m[v].combos[x].quantity*m[v].quantity));g.price_atax=Math.round(1e6*g.price_atax)/1e6,g.payment_atax=Math.round(1e6*g.payment_atax)/1e6,l.docs.push(g),l.size++,l.empty=!1}console.log("getReportInputOutputInventory_Detail_byEndTime_byIDProduct"),i(l)}))}))},t.prototype.getReportInputOutputInventory_Detail_byTime_byIDProduct=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l=i.getlocalProduct(n),c={docs:new Array,empty:!0,size:0,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0},u=new Array,d=new Array;i.getlocalProductAndCombos(n).forEach((function(t){d.push(t._id)}));for(var _=0;_<d.length;_++)r="all"===o||void 0===o?{date:{$gte:t,$lte:e},id_product:{$eq:d[_]},bill_type:{$in:[1,10,15,30,2,3,9,31]}}:{date:{$gte:t,$lte:e},id_product:{$eq:d[_]},bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:o}},u[_]=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",r,{},{date:1},0);Promise.all(u).then((function(t){for(var e,n,o,i,s,r,u,d,_,p,b,f,h,y,m,v,g,x,q,w=t.flat(),P=0;P<w.length;P++){var D={id_bill:null===(e=w[P])||void 0===e?void 0:e.id_bill,bill_code:null===(n=w[P])||void 0===n?void 0:n.bill_code,bill_type:null===(o=w[P])||void 0===o?void 0:o.bill_type,date:null===(i=w[P])||void 0===i?void 0:i.date,name:l.name,unit:l.unit};if((null===(s=w[P])||void 0===s?void 0:s.id_cashier)&&(D.id_cashier=null===(r=w[P])||void 0===r?void 0:r.id_cashier),(null===(u=w[P])||void 0===u?void 0:u.id_employee)&&(D.id_employee=null===(d=w[P])||void 0===d?void 0:d.id_employee),(null===(_=w[P])||void 0===_?void 0:_.id_customer)&&(D.id_customer=null===(p=w[P])||void 0===p?void 0:p.id_customer),(null===(b=w[P])||void 0===b?void 0:b.id_supplier)&&(D.id_supplier=null===(f=w[P])||void 0===f?void 0:f.id_supplier),1===w[P].ptype)D.price_btax=null===(h=w[P])||void 0===h?void 0:h.price,D.price_atax=(null===(y=w[P])||void 0===y?void 0:y.price)*(1+w[P].tax/100),D.payment_btax=(null===(m=w[P])||void 0===m?void 0:m.price)*(null===(v=w[P])||void 0===v?void 0:v.quantity),D.payment_atax=(null===(g=w[P])||void 0===g?void 0:g.price)*(null===(x=w[P])||void 0===x?void 0:x.quantity)*(1+w[P].tax/100),D.quantity=null===(q=w[P])||void 0===q?void 0:q.quantity,1===w[P].bill_type||10===w[P].bill_type||15===w[P].bill_type||30===w[P].bill_type?(D.type="output",c.revenue_btax=c.revenue_btax+w[P].price*w[P].quantity,c.revenue_atax=c.revenue_atax+w[P].price*w[P].quantity*(1+w[P].tax/100),c.outquantity=c.outquantity+w[P].quantity):2===w[P].bill_type||3===w[P].bill_type||31===w[P].bill_type?(D.type="input",c.cost_btax=c.cost_btax+w[P].price*w[P].quantity,c.cost_atax=c.cost_atax+w[P].price*w[P].quantity*(1+w[P].tax/100),c.inquantity=c.inquantity+w[P].quantity):9===w[P].bill_type&&(D.type="beginning",c.cost_btax=c.cost_btax+w[P].price*w[P].quantity,c.cost_atax=c.cost_atax+w[P].price*w[P].quantity*(1+w[P].tax/100),c.inquantity=c.inquantity+w[P].quantity);else if(5===w[P].ptype)for(var k=0;k<w[P].combos.length;k++)if(w[P].combos[k].id_product===l._id){D.price_btax=w[P].combos[k].price,D.price_atax=w[P].combos[k].price*(1+w[P].tax/100),D.payment_btax=w[P].combos[k].price*w[P].combos[k].quantity*w[P].quantity,D.payment_atax=w[P].combos[k].price*w[P].combos[k].quantity*w[P].quantity*(1+w[P].tax/100),D.quantity=w[P].combos[k].quantity*w[P].quantity,1===w[P].bill_type||10===w[P].bill_type||15===w[P].bill_type||30===w[P].bill_type?(D.type="output",c.revenue_btax=c.revenue_btax+w[P].combos[k].price*w[P].combos[k].quantity*w[P].quantity,c.revenue_atax=c.revenue_atax+w[P].combos[k].price*w[P].combos[k].quantity*w[P].quantity*(1+w[P].tax/100),c.outquantity=c.outquantity+w[P].combos[k].quantity*w[P].quantity):2===w[P].bill_type||3===w[P].bill_type||31===w[P].bill_type?(D.type="input",c.cost_btax=c.cost_btax+w[P].combos[k].price*w[P].combos[k].quantity*w[P].quantity,c.cost_atax=c.cost_atax+w[P].combos[k].price*w[P].combos[k].quantity*w[P].quantity*(1+w[P].tax/100),c.inquantity=c.inquantity+w[P].combos[k].quantity*w[P].quantity):9===w[P].bill_type&&(D.type="beginning",c.cost_btax=c.cost_btax+w[P].combos[k].price*w[P].combos[k].quantity*w[P].quantity,c.cost_atax=c.cost_atax+w[P].combos[k].price*w[P].combos[k].quantity*w[P].quantity*(1+w[P].tax/100),c.inquantity=c.inquantity+w[P].combos[k].quantity*w[P].quantity);break}D.price_atax=Math.round(1e6*D.price_atax)/1e6,D.payment_atax=Math.round(1e6*D.payment_atax)/1e6,c.docs.push(D),c.size++,c.empty=!1}console.log("getReportInputOutputInventory_Detail_byTime_byIDProduct"),a(c)}))}))},t.prototype.getReportInputOutput_byTime_byIDProduct=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Array;if("all"===n)r=i.vhAlgorithm.sortVietnamesebyASC(i.getlocalProducts(1),"name");else{var l=i.getlocalProduct(n);r.push(l)}var c={docs:new Array,empty:!0,size:0,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0};if(r.length>0){for(var u=void 0,d=new Array,_=[1,5],p=0;p<_.length;p++)u="all"===n?"all"===o||void 0===o?{date:{$gte:t,$lte:e},ptype:{$eq:_[p]},bill_type:{$in:[1,10,15,30,2,3,31]}}:{date:{$gte:t,$lte:e},ptype:{$eq:_[p]},bill_type:{$in:[1,10,15,30,2,3,31]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$gte:t,$lte:e},ptype:{$eq:_[p]},id_product:{$eq:n},bill_type:{$in:[1,10,15,30,2,3,31]}}:{date:{$gte:t,$lte:e},ptype:{$eq:_[p]},bill_type:{$in:[1,10,15,30,2,3,31]},id_branch:{$eq:o}},d[p]=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0);Promise.all(d).then((function(t){for(var e=t.flat(),n=0;n<r.length;n++){for(var o={_id:r[n]._id,name:r[n].name,type:r[n].type,unit:r[n].unit,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0},i=0;i<e.length;i++)if(1===e[i].ptype)e[i].id_product===r[n]._id&&(1===e[i].bill_type||10===e[i].bill_type||15===e[i].bill_type||30===e[i].bill_type?(o.revenue_btax=o.revenue_btax+e[i].price*e[i].quantity,o.revenue_atax=o.revenue_atax+e[i].price*e[i].quantity*(1+e[i].tax/100),o.outquantity=o.outquantity+e[i].quantity,c.revenue_btax=c.revenue_btax+e[i].price*e[i].quantity,c.revenue_atax=c.revenue_atax+e[i].price*e[i].quantity*(1+e[i].tax/100),c.outquantity=c.outquantity+e[i].quantity):2!==e[i].bill_type&&3!==e[i].bill_type&&31!==e[i].bill_type||(o.cost_btax=o.cost_btax+e[i].price*e[i].quantity,o.cost_atax=o.cost_atax+e[i].price*e[i].quantity*(1+e[i].tax/100),o.inquantity=o.inquantity+e[i].quantity,c.cost_btax=c.cost_btax+e[i].price*e[i].quantity,c.cost_atax=c.cost_atax+e[i].price*e[i].quantity*(1+e[i].tax/100),c.inquantity=c.inquantity+e[i].quantity));else if(5===e[i].ptype)for(var s=0;s<e[i].combos.length;s++)if(e[i].combos[s].id_product===r[n]._id){1===e[i].bill_type||10===e[i].bill_type||15===e[i].bill_type||30===e[i].bill_type?(o.revenue_btax=o.revenue_btax+e[i].combos[s].price*e[i].combos[s].quantity*e[i].quantity,o.revenue_atax=o.revenue_atax+e[i].combos[s].price*e[i].combos[s].quantity*e[i].quantity*(1+e[i].tax/100),o.outquantity=o.outquantity+e[i].combos[s].quantity*e[i].quantity,c.revenue_btax=c.revenue_btax+e[i].combos[s].price*e[i].combos[s].quantity*e[i].quantity,c.revenue_atax=c.revenue_atax+e[i].combos[s].price*e[i].combos[s].quantity*e[i].quantity*(1+e[i].tax/100),c.outquantity=c.outquantity+e[i].combos[s].quantity*e[i].quantity):2!==e[i].bill_type&&3!==e[i].bill_type&&31!==e[i].bill_type||(o.cost_btax=o.cost_btax+e[i].price*e[i].quantity,o.cost_atax=o.cost_atax+e[i].price*e[i].quantity*(1+e[i].tax/100),o.inquantity=o.inquantity+e[i].quantity,c.cost_btax=c.cost_btax+e[i].combos[s].price*e[i].combos[s].quantity*e[i].quantity,c.cost_atax=c.cost_atax+e[i].combos[s].price*e[i].combos[s].quantity*e[i].quantity*(1+e[i].tax/100),c.inquantity=c.inquantity+e[i].combos[s].quantity*e[i].quantity);break}0==o.inquantity&&0==o.outquantity||(o.revenue_atax=Math.round(1e6*o.revenue_atax)/1e6,o.cost_atax=Math.round(1e6*o.cost_atax)/1e6,o.index=c.size+1,c.docs.push(o),c.size++,c.empty=!1)}console.log("getReportInputOutput_byTime_byIDProduct"),a(c)}))}else console.log("server -> products khong ton tai trong CSDL: "),a(c)}))},t.prototype.getReportInputOutput_Detail_byTime_byIDProduct=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l=i.getlocalProduct(n),c={docs:new Array,empty:!0,size:0,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0},u=new Array,d=new Array;i.getlocalProductAndCombos(n).forEach((function(t){d.push(t._id)}));for(var _=0;_<d.length;_++)r="all"===o||void 0===o?{date:{$gte:t,$lte:e},id_product:{$eq:d[_]},bill_type:{$in:[1,10,15,30,2,3,31]}}:{date:{$gte:t,$lte:e},id_product:{$eq:d[_]},bill_type:{$in:[1,10,15,30,2,3,31]},id_branch:{$eq:o}},u[_]=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",r,{},{date:1},0);Promise.all(u).then((function(t){for(var e,n,o,i,s,r,u,d,_,p,b,f,h,y,m,v,g,x,q,w=t.flat(),P=0;P<w.length;P++){var D={id_bill:null===(e=w[P])||void 0===e?void 0:e.id_bill,bill_code:null===(n=w[P])||void 0===n?void 0:n.bill_code,bill_type:null===(o=w[P])||void 0===o?void 0:o.bill_type,date:null===(i=w[P])||void 0===i?void 0:i.date,name:l.name,unit:l.unit};if((null===(s=w[P])||void 0===s?void 0:s.id_cashier)&&(D.id_cashier=null===(r=w[P])||void 0===r?void 0:r.id_cashier),(null===(u=w[P])||void 0===u?void 0:u.id_employee)&&(D.id_employee=null===(d=w[P])||void 0===d?void 0:d.id_employee),(null===(_=w[P])||void 0===_?void 0:_.id_customer)&&(D.id_customer=null===(p=w[P])||void 0===p?void 0:p.id_customer),(null===(b=w[P])||void 0===b?void 0:b.id_supplier)&&(D.id_supplier=null===(f=w[P])||void 0===f?void 0:f.id_supplier),1===w[P].ptype)D.price_btax=null===(h=w[P])||void 0===h?void 0:h.price,D.price_atax=(null===(y=w[P])||void 0===y?void 0:y.price)*(1+w[P].tax/100),D.payment_btax=(null===(m=w[P])||void 0===m?void 0:m.price)*(null===(v=w[P])||void 0===v?void 0:v.quantity),D.payment_atax=(null===(g=w[P])||void 0===g?void 0:g.price)*(null===(x=w[P])||void 0===x?void 0:x.quantity)*(1+w[P].tax/100),D.quantity=null===(q=w[P])||void 0===q?void 0:q.quantity,1===w[P].bill_type||10===w[P].bill_type||15===w[P].bill_type||30===w[P].bill_type?(D.type="output",c.revenue_btax=c.revenue_btax+w[P].price*w[P].quantity,c.revenue_atax=c.revenue_atax+w[P].price*w[P].quantity*(1+w[P].tax/100),c.outquantity=c.outquantity+w[P].quantity):2!==w[P].bill_type&&3!==w[P].bill_type&&31!==w[P].bill_type||(D.type="input",c.cost_btax=c.cost_btax+w[P].price*w[P].quantity,c.cost_atax=c.cost_atax+w[P].price*w[P].quantity*(1+w[P].tax/100),c.inquantity=c.inquantity+w[P].quantity);else if(5===w[P].ptype)for(var k=0;k<w[P].combos.length;k++)w[P].combos[k].id_product===l._id&&(D.price_btax=w[P].combos[k].price,D.price_atax=w[P].combos[k].price*(1+w[P].tax/100),D.payment_btax=w[P].combos[k].price*w[P].combos[k].quantity*w[P].quantity,D.payment_atax=w[P].combos[k].price*w[P].combos[k].quantity*w[P].quantity*(1+w[P].tax/100),D.quantity=w[P].combos[k].quantity*w[P].quantity,1===w[P].bill_type||10===w[P].bill_type||15===w[P].bill_type||30===w[P].bill_type?(D.type="output",c.revenue_btax=c.revenue_btax+w[P].combos[k].price*w[P].combos[k].quantity*w[P].quantity,c.revenue_atax=c.revenue_atax+w[P].combos[k].price*w[P].combos[k].quantity*w[P].quantity*(1+w[P].tax/100),c.outquantity=c.outquantity+w[P].combos[k].quantity*w[P].quantity):2!==w[P].bill_type&&3!==w[P].bill_type&&31!==w[P].bill_type||(D.type="input",c.cost_btax=c.cost_btax+w[P].combos[k].price*w[P].combos[k].quantity*w[P].quantity,c.cost_atax=c.cost_atax+w[P].combos[k].price*w[P].combos[k].quantity*w[P].quantity*(1+w[P].tax/100),c.inquantity=c.inquantity+w[P].combos[k].quantity*w[P].quantity));D.price_atax=Math.round(1e6*D.price_atax)/1e6,D.payment_atax=Math.round(1e6*D.payment_atax)/1e6,c.docs.push(D),c.size++,c.empty=!1}a(c)}))}))},t.prototype.getReportProfit_byTime_byIDProduct=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r={docs:new Array,empty:!0,size:0,outquantity_sales:0,sales_btax:0,sales_atax:0,profit_sales_btax:0,profit_sales_atax:0,cost_outstock_sales_btax:0,cost_outstock_sales_atax:0,return_on_sales_btax:0,return_on_sales_atax:0},l=i.vhAuth.getStore(),c=new Array;if("all"===n)c=i.vhAlgorithm.sortVietnamesebyASC(i.getlocalProducts(1),"name");else{var u=i.getlocalProduct(n);c.push(u)}var d=null,_=null;if("all"===n)if("all"===o||void 0===o)console.log("trường hợp này chưa có hàm, liên hệ anh Huy viết");else{if(null!=c[0][o]&&null!=c[0][o].inventory)for(var p=0;p<c[0][o].inventory.length&&!(new Date(c[0][o].inventory[p].date).getTime()>t.getTime());p++)_=new Date(c[0][o].inventory[p].date),d=p;if(_){for(var b=!1,f=0;f<c.length;f++)null!=c[f][o]&&null!=c[f][o].inventory||(b=!0);if(b)return console.log("Vui lòng đồng bộ kho để lấy về dữ liệu mới nhất"),a(r)}}else if("all"===o||void 0===o)console.log("trường hợp này chưa có hàm, liên hệ anh Huy viết");else if(null!=c[0][o]&&null!=c[0][o].inventory)for(p=0;p<c[0][o].inventory.length&&!(new Date(c[0][o].inventory[p].date).getTime()>t.getTime());p++)_=new Date(c[0][o].inventory[p].date),d=p;if(_||(_=new Date(l.registrationdate)),c.length>0){var h,y=new Array;if("all"===n)h="all"===o||void 0===o?{date:{$gte:_,$lte:e},bill_type:{$in:[1,10,15,30,2,3,9,31]}}:{date:{$gte:_,$lte:e},bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:o}},y[0]=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",h,{},{date:1},0);else{var m=i.getlocalProductAndCombos(n);for(f=0;f<m.length;f++)h="all"===o||void 0===o?{date:{$gte:_,$lte:e},id_product:{$eq:m[f]._id},bill_type:{$in:[1,10,15,30,2,3,9,31]}}:{date:{$gte:_,$lte:e},id_product:{$eq:m[f]._id},bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:o}},y[f]=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",h,{},{date:1},0)}Promise.all(y).then((function(e){for(var n=e.flat(),i=0;i<c.length;i++){for(var s={stock_first:0,cost_stock_first_btax:0,cost_stock_first_atax:0},l={_id:c[i]._id,name:c[i].name,type:c[i].type,unit:c[i].unit,outquantity_sales:0,sales_btax:0,sales_atax:0,profit_sales_btax:0,profit_sales_atax:0,cost_outstock_sales_btax:0,cost_outstock_sales_atax:0,return_on_sales_btax:0,return_on_sales_atax:0,outquantity:0,inquantity:0,stock_first:0,stock_last:0,cost_stock_first_btax:0,cost_stock_first_atax:0,cost_stock_last_btax:0,cost_stock_last_atax:0,cost_stock_average_btax:0,cost_stock_average_atax:0},u=0,_=0,p=0,b=0,f=0,h=0,y=0,m=0;m<n.length;m++)if(1===n[m].ptype){if(n[m].id_product===c[i]._id){var v=new Date(n[m].date);1===n[m].bill_type||10===n[m].bill_type||15===n[m].bill_type||30===n[m].bill_type?v>=new Date(t)?(l.sales_btax=l.sales_btax+n[m].price*n[m].quantity,l.sales_atax=l.sales_atax+n[m].price*n[m].quantity*(1+n[m].tax/100),l.outquantity_sales=l.outquantity_sales+n[m].quantity,l.outquantity=l.outquantity+n[m].quantity,r.sales_btax=r.sales_btax+n[m].price*n[m].quantity,r.sales_atax=r.sales_atax+n[m].price*n[m].quantity*(1+n[m].tax/100),r.outquantity_sales=r.outquantity_sales+n[m].quantity):u+=n[m].quantity:3===n[m].bill_type?(v>=new Date(t)?(l.sales_btax=l.sales_btax-n[m].price*n[m].quantity,l.sales_atax=l.sales_atax-n[m].price*n[m].quantity*(1+n[m].tax/100),l.outquantity_sales=l.outquantity_sales-n[m].quantity,r.sales_btax=r.sales_btax-n[m].price*n[m].quantity,r.sales_atax=r.sales_atax-n[m].price*n[m].quantity*(1+n[m].tax/100),r.outquantity_sales=r.outquantity_sales-n[m].quantity,l.inquantity=l.inquantity+n[m].quantity):(_+=n[m].quantity,p+=n[m].price*n[m].quantity,b+=n[m].price*n[m].quantity*(1+n[m].tax/100)),f+=n[m].quantity,h+=n[m].price*n[m].quantity,y+=n[m].price*n[m].quantity*(1+n[m].tax/100)):2!==n[m].bill_type&&9!==n[m].bill_type&&31!==n[m].bill_type||(v>=new Date(t)?l.inquantity=l.inquantity+n[m].quantity:(_+=n[m].quantity,p+=n[m].price*n[m].quantity,b+=n[m].price*n[m].quantity*(1+n[m].tax/100)),f+=n[m].quantity,h+=n[m].price*n[m].quantity,y+=n[m].price*n[m].quantity*(1+n[m].tax/100))}}else if(5===n[m].ptype)for(var g=0;g<n[m].combos.length;g++)if(n[m].combos[g].id_product===c[i]._id){v=new Date(n[m].date);1===n[m].bill_type||10===n[m].bill_type||15===n[m].bill_type||30===n[m].bill_type?v>=new Date(t)?(l.sales_btax=l.sales_btax+n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity,l.sales_atax=l.sales_atax+n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity*(1+n[m].tax/100),l.outquantity=l.outquantity+n[m].combos[g].quantity*n[m].quantity,r.sales_btax=r.sales_btax+n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity,r.sales_atax=r.sales_atax+n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity*(1+n[m].tax/100),r.outquantity=r.outquantity+n[m].combos[g].quantity*n[m].quantity):u+=n[m].combos[g].quantity*n[m].quantity:3===n[m].bill_type?(v>=new Date(t)?(l.sales_btax=l.sales_btax-n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity,l.sales_atax=l.sales_atax-n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity*(1+n[m].tax/100),l.outquantity_sales=l.outquantity_sales-n[m].combos[g].quantity*n[m].quantity,r.sales_btax=r.sales_btax-n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity,r.sales_atax=r.sales_atax-n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity*(1+n[m].tax/100),r.outquantity_sales=r.outquantity_sales-n[m].combos[g].quantity*n[m].quantity,l.inquantity=l.inquantity+n[m].combos[g].quantity*n[m].quantity):(p+=n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity,b+=n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity*(1+n[m].tax/100),_+=n[m].combos[g].quantity*n[m].quantity),f+=n[m].combos[g].quantity*n[m].quantity,h+=n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity,y+=n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity*(1+n[m].tax/100)):2!==n[m].bill_type&&9!==n[m].bill_type&&31!==n[m].bill_type||(v>=new Date(t)?l.inquantity=l.inquantity+n[m].combos[g].quantity*n[m].quantity:(p+=n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity,b+=n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity*(1+n[m].tax/100),_+=n[m].combos[g].quantity*n[m].quantity),f+=n[m].combos[g].quantity*n[m].quantity,h+=n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity,y+=n[m].combos[g].price*n[m].combos[g].quantity*n[m].quantity*(1+n[m].tax/100));break}if(null!=d&&(s=Object.assign({},c[i][o].inventory[d])),l.stock_first=s.stock_first+_-u,l.stock_last=l.stock_first+l.inquantity-l.outquantity,s.stock_first+_!=0&&(l.cost_stock_first_btax=(s.cost_stock_first_btax+p)/(s.stock_first+_)*l.stock_first,l.cost_stock_first_atax=(s.cost_stock_first_atax+b)/(s.stock_first+_)*l.stock_first),s.stock_first+f!=0&&(l.cost_stock_last_btax=(s.cost_stock_first_btax+h)/(s.stock_first+f)*l.stock_last,l.cost_stock_last_atax=(s.cost_stock_first_atax+y)/(s.stock_first+f)*l.stock_last),s.stock_first>0?(l.cost_stock_average_btax=(s.cost_stock_first_btax+h)/(s.stock_first+f),l.cost_stock_average_atax=(s.cost_stock_first_atax+y)/(s.stock_first+f)):0!=f&&(l.cost_stock_average_btax=h/f,l.cost_stock_average_atax=y/f),l.cost_outstock_sales_btax=l.cost_stock_average_btax*l.outquantity_sales,l.cost_outstock_sales_atax=l.cost_stock_average_atax*l.outquantity_sales,l.profit_sales_btax=l.sales_btax-l.cost_stock_average_btax*l.outquantity_sales,l.profit_sales_atax=l.sales_atax-l.cost_stock_average_atax*l.outquantity_sales,0!=l.sales_btax?l.return_on_sales_btax=l.profit_sales_btax/l.sales_btax:l.profit_sales_btax>0?l.return_on_sales_btax=1/0:l.profit_sales_btax<0?l.return_on_sales_btax=-1/0:0===l.profit_sales_btax&&(l.return_on_sales_btax=0),0!=l.sales_atax?l.return_on_sales_atax=l.profit_sales_atax/l.sales_atax:l.profit_sales_atax>0?l.return_on_sales_atax=1/0:l.profit_sales_atax<0?l.return_on_sales_atax=-1/0:0==l.profit_sales_atax&&(l.return_on_sales_atax=0),r.profit_sales_btax=r.profit_sales_btax+l.profit_sales_btax,r.profit_sales_atax=r.profit_sales_atax+l.profit_sales_atax,r.cost_outstock_sales_btax=r.cost_outstock_sales_btax+l.cost_outstock_sales_btax,r.cost_outstock_sales_atax=r.cost_outstock_sales_atax+l.cost_outstock_sales_atax,0!=r.sales_btax&&(r.return_on_sales_btax=r.profit_sales_btax/r.sales_btax),0!=r.sales_atax&&(r.return_on_sales_atax=r.profit_sales_atax/r.sales_atax),l.sales_atax=Math.round(1e6*l.sales_atax)/1e6,l.profit_sales_atax=Math.round(1e6*l.profit_sales_atax)/1e6,l.return_on_sales_atax=Math.round(1e6*l.return_on_sales_atax)/1e6,l.index=r.size+1,l.outquantity>0){var x={_id:l._id,name:l.name,type:l.type,unit:l.unit,outquantity_sales:l.outquantity_sales,sales_btax:l.sales_btax,sales_atax:l.sales_atax,profit_sales_btax:l.profit_sales_btax,profit_sales_atax:l.profit_sales_atax,cost_outstock_sales_btax:l.cost_outstock_sales_btax,cost_outstock_sales_atax:l.cost_outstock_sales_atax,return_on_sales_btax:l.return_on_sales_btax,return_on_sales_atax:l.return_on_sales_atax};r.docs.push(x),r.size++,r.empty=!1}}a(r),console.log("getReportProfit_byTime_byIDProduct",r)}))}else console.log("server -> products khong ton tai trong CSDL: "),a(r)}))},t.prototype.getReportInputOutputInventory_byTime_byIDProduct1=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=new Array;if("all"===n)r=i.vhAlgorithm.sortVietnamesebyASC(i.getlocalProducts(1),"name");else{var l=i.getlocalProduct(n);r.push(l)}var c={docs:new Array,empty:!0,size:0,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0,stock_first:0,stock_last:0,cost_stock_first_btax:0,cost_stock_first_atax:0,cost_stock_last_btax:0,cost_stock_last_atax:0};if(r.length>0){for(var u=void 0,d=new Array,_=[1,5],p=0;p<_.length;p++)u="all"===o||void 0===o?{date:{$lte:e},ptype:{$eq:_[p]},bill_type:{$in:[1,10,15,30,2,3,9,31]}}:{date:{$lte:e},ptype:{$eq:_[p]},bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:o}},d[p]=i.vhmongo_firebase.database().getDocsByFields("vhbill_details",u,{},{date:1},0);Promise.all(d).then((function(e){for(var n=e.flat(),o=0;o<r.length;o++){for(var i={_id:r[o]._id,name:r[o].name,type:r[o].type,unit:r[o].unit,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0,stock_first:0,stock_last:0,cost_stock_first_btax:0,cost_stock_first_atax:0,cost_stock_last_btax:0,cost_stock_last_atax:0},s=0,l=0,u=0,d=0,_=0,p=0,b=0,f=0;f<n.length;f++)if(1===n[f].ptype){if(n[f].id_product===r[o]._id){var h=new Date(n[f].date);1===n[f].bill_type||10===n[f].bill_type||15===n[f].bill_type||30===n[f].bill_type?h>=new Date(t)?(i.revenue_btax=i.revenue_btax+n[f].price*n[f].quantity,i.revenue_atax=i.revenue_atax+n[f].price*n[f].quantity*(1+n[f].tax/100),i.outquantity=i.outquantity+n[f].quantity,c.revenue_btax=c.revenue_btax+n[f].price*n[f].quantity,c.revenue_atax=c.revenue_atax+n[f].price*n[f].quantity*(1+n[f].tax/100),c.outquantity=c.outquantity+n[f].quantity):s+=n[f].quantity:2!==n[f].bill_type&&3!==n[f].bill_type&&9!==n[f].bill_type&&31!==n[f].bill_type||(h>=new Date(t)?(i.cost_btax=i.cost_btax+n[f].price*n[f].quantity,i.cost_atax=i.cost_atax+n[f].price*n[f].quantity*(1+n[f].tax/100),i.inquantity=i.inquantity+n[f].quantity,c.cost_btax=c.cost_btax+n[f].price*n[f].quantity,c.cost_atax=c.cost_atax+n[f].price*n[f].quantity*(1+n[f].tax/100),c.inquantity=c.inquantity+n[f].quantity):(l+=n[f].quantity,u+=n[f].price*n[f].quantity,d+=n[f].price*n[f].quantity*(1+n[f].tax/100)),_+=n[f].quantity,p+=n[f].price*n[f].quantity,b+=n[f].price*n[f].quantity*(1+n[f].tax/100))}}else if(5===n[f].ptype)for(var y=0;y<n[f].combos.length;y++)if(n[f].combos[y].id_product===r[o]._id){h=new Date(n[f].date);1===n[f].bill_type||10===n[f].bill_type||15===n[f].bill_type||30===n[f].bill_type?h>=new Date(t)?(i.revenue_btax=i.revenue_btax+n[f].combos[y].price*n[f].combos[y].quantity*n[f].quantity,i.revenue_atax=i.revenue_atax+n[f].combos[y].price*n[f].combos[y].quantity*n[f].quantity*(1+n[f].tax/100),i.outquantity=i.outquantity+n[f].combos[y].quantity*n[f].quantity,c.revenue_btax=c.revenue_btax+n[f].combos[y].price*n[f].combos[y].quantity*n[f].quantity,c.revenue_atax=c.revenue_atax+n[f].combos[y].price*n[f].combos[y].quantity*n[f].quantity*(1+n[f].tax/100),c.outquantity=c.outquantity+n[f].combos[y].quantity*n[f].quantity):s+=n[f].combos[y].quantity*n[f].quantity:2!==n[f].bill_type&&3!==n[f].bill_type&&9!==n[f].bill_type&&31!==n[f].bill_type||(h>=new Date(t)?(i.cost_btax=i.cost_btax+n[f].combos[y].price*n[f].combos[y].quantity*n[f].quantity,i.cost_atax=i.cost_atax+n[f].combos[y].price*n[f].combos[y].quantity*n[f].quantity*(1+n[f].tax/100),i.inquantity=i.inquantity+n[f].combos[y].quantity*n[f].quantity,c.cost_btax=c.cost_btax+n[f].combos[y].price*n[f].combos[y].quantity*n[f].quantity,c.cost_atax=c.cost_atax+n[f].combos[y].price*n[f].combos[y].quantity*n[f].quantity*(1+n[f].tax/100),c.inquantity=c.inquantity+n[f].combos[y].quantity*n[f].quantity):(u+=n[f].combos[y].price*n[f].combos[y].quantity*n[f].quantity,d+=n[f].combos[y].price*n[f].combos[y].quantity*n[f].quantity*(1+n[f].tax/100),l+=n[f].combos[y].quantity*n[f].quantity),_+=n[f].combos[y].quantity*n[f].quantity,p+=n[f].combos[y].price*n[f].combos[y].quantity*n[f].quantity,b+=n[f].combos[y].price*n[f].combos[y].quantity*n[f].quantity*(1+n[f].tax/100));break}i.stock_first=l-s,i.stock_last=i.stock_first+i.inquantity-i.outquantity,0!=l&&(i.cost_stock_first_btax=u/l*i.stock_first),0!=l&&(i.cost_stock_first_atax=d/l*i.stock_first),0!=_&&(i.cost_stock_last_btax=p/_*i.stock_last),0!=_&&(i.cost_stock_last_atax=b/_*i.stock_last),c.stock_first=c.stock_first+i.stock_first,c.stock_last=c.stock_last+i.stock_last,c.cost_stock_first_btax=c.cost_stock_first_btax+i.cost_stock_first_btax,c.cost_stock_first_atax=c.cost_stock_first_atax+i.cost_stock_first_atax,c.cost_stock_last_btax=c.cost_stock_last_btax+i.cost_stock_last_btax,c.cost_stock_last_atax=c.cost_stock_last_atax+i.cost_stock_last_atax,i.revenue_atax=Math.round(1e6*i.revenue_atax)/1e6,i.cost_atax=Math.round(1e6*i.cost_atax)/1e6,i.cost_stock_first_atax=Math.round(1e6*i.cost_stock_first_atax)/1e6,i.cost_stock_last_atax=Math.round(1e6*i.cost_stock_last_atax)/1e6,i.index=c.size+1,c.docs.push(i),c.size++,c.empty=!1}a(c),console.log("getReportInputOutputInventory_byTime_byIDProduct")}))}else console.log("server -> products khong ton tai trong CSDL: "),a(c)}))},t.prototype.syncInventoryEveryDay_StockBeginning=function(){var t=this;return new Promise((function(e,n){for(var o=t.getlocalProducts(1),i=t.getlocalBranchs(),a=new Array,s=function(e){a[e]=new Promise((function(n){var a=i[e]._id,s={bill_type:{$eq:9},id_branch:{$eq:a}};t.vhmongo_firebase.database().getDocsByFields("vhbill_details",s,{},{date:1},0).then((function(e){var i=new Array;if(e.length>0)for(var s=0;s<o.length;s++){for(var r=0,l=0,c=0,u=0,d=0,_=0;_<e.length;_++)1===e[_].ptype&&e[_].id_product===o[s]._id&&(r+=e[_].quantity,l+=e[_].price*e[_].quantity,c+=e[_].price*e[_].quantity*(1+e[_].tax/100));if(0!=r){u=l/r,d=c/r;var p={};null!=o[s][a]?p[a]=o[s][a]:p[a]={},p[a].stock_beginning=r,p[a].unit_cost_stock_beginning_btax=u,p[a].unit_cost_stock_beginning_atax=d,p[a].cost_stock_beginning_btax=l,p[a].cost_stock_beginning_atax=c,i.push(t.vhmongo_firebase.database().updateDoc("products",o[s]._id,Object.assign({},p)))}}Promise.all(i).then((function(){n(null)}))}))}))},r=0;r<i.length;r++)s(r);Promise.all(a).then((function(){e(null)}))}))},t.prototype.syncInventoryEveryDay_Stock1stDayOfMonth=function(){var t=this;return new Promise((function(e,n){var o=t.vhAuth.getStore(),i=[Object.assign({},t.getDefaultBranch())];t.vhmongo_firebase.auth().getServerDate().then((function(n){var a=t.get1stDayOfMonthArray(o.registrationdate,n);if(a.length>0){for(var s=new Array,r=function(e){s[e]=new Promise((function(n){for(var o=i[e]._id,s=t.getlocalProducts(1),r=s.length,l=new Array,c=0;c<s.length;c++)l.push(c);var u=!0,d=l.splice(0,10),_=setInterval((function(){if(u){u=!1;for(var i=new Array,c=function(e){i[i.length]=new Promise((function(n){if(null!=s[e][o]&&null!=s[e][o].inventory){var i=s[e][o].inventory[s[e][o].inventory.length-1],l=s[e][o].inventory.length;if(new Date(i.date).getTime()<new Date(a[a.length-1]).getTime()){for(var c=l;c<a.length;c++)s[e][o].inventory[c]={},s[e][o].inventory[c].date=a[c],s[e][o].inventory[c].inquantity_tofirst=i.inquantity_tofirst,s[e][o].inventory[c].pay_tofirst_btax=i.pay_tofirst_btax,s[e][o].inventory[c].pay_tofirst_atax=i.pay_tofirst_atax,s[e][o].inventory[c].outquantity_tofirst=i.outquantity_tofirst,s[e][o].inventory[c].sales_tofirst_btax=i.sales_tofirst_btax,s[e][o].inventory[c].sales_tofirst_atax=i.sales_tofirst_atax,s[e][o].inventory[c].stock_first=0,s[e][o].inventory[c].unit_cost_stock_first_btax=0,s[e][o].inventory[c].unit_cost_stock_first_atax=0,s[e][o].inventory[c].cost_stock_first_btax=0,s[e][o].inventory[c].cost_stock_first_atax=0,s[e][o].inventory[c].profit_first_btax=0,s[e][o].inventory[c].profit_first_atax=0;var u=new Array,d=new Array;t.getlocalProductAndCombos(s[e]._id).forEach((function(t){d.push(t._id)}));for(var _=0;_<d.length;_++){var p={date:{$gte:new Date(i.date),$lte:new Date(a[a.length-1])},bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:o},id_product:{$eq:d[_]}};u[_]=t.vhmongo_firebase.database().getDocsByFields("vhbill_details",p,{},{date:1},0)}Promise.all(u).then((function(i){var c=i.flat();if(c.length>0)for(var u=0;u<c.length;u++)if(1===c[u].ptype){if(c[u].id_product===s[e]._id)for(var d=l;d<a.length;d++)new Date(c[u].date).getTime()<new Date(s[e][o].inventory[d].date).getTime()&&(1===c[u].bill_type||10===c[u].bill_type||15===c[u].bill_type||30===c[u].bill_type?(s[e][o].inventory[d].outquantity_tofirst=s[e][o].inventory[d].outquantity_tofirst+c[u].quantity,s[e][o].inventory[d].sales_tofirst_btax=s[e][o].inventory[d].sales_tofirst_btax+c[u].price*c[u].quantity,s[e][o].inventory[d].sales_tofirst_atax=s[e][o].inventory[d].sales_tofirst_atax+c[u].price*c[u].quantity*(1+c[u].tax/100)):2!==c[u].bill_type&&3!==c[u].bill_type&&9!==c[u].bill_type&&31!==c[u].bill_type||(s[e][o].inventory[d].inquantity_tofirst=s[e][o].inventory[d].inquantity_tofirst+c[u].quantity,s[e][o].inventory[d].pay_tofirst_btax=s[e][o].inventory[d].pay_tofirst_btax+c[u].price*c[u].quantity,s[e][o].inventory[d].pay_tofirst_atax=s[e][o].inventory[d].pay_tofirst_atax+c[u].price*c[u].quantity*(1+c[u].tax/100)))}else if(5===c[u].ptype)for(var _=0;_<c[u].combos.length;_++)if(c[u].combos[_].id_product===s[e]._id)for(d=l;d<a.length;d++)new Date(c[u].date).getTime()<new Date(s[e][o].inventory[d].date).getTime()&&(1===c[u].bill_type||10===c[u].bill_type||15===c[u].bill_type||30===c[u].bill_type?(s[e][o].inventory[d].outquantity_tofirst=s[e][o].inventory[d].outquantity_tofirst+c[u].combos[_].quantity*c[u].quantity,s[e][o].inventory[d].sales_tofirst_btax=s[e][o].inventory[d].sales_tofirst_btax+c[u].combos[_].price*c[u].combos[_].quantity*c[u].quantity,s[e][o].inventory[d].sales_tofirst_atax=s[e][o].inventory[d].sales_tofirst_atax+c[u].combos[_].price*c[u].combos[_].quantity*c[u].quantity*(1+c[u].tax/100)):2!==c[u].bill_type&&3!==c[u].bill_type&&9!==c[u].bill_type&&31!==c[u].bill_type||(s[e][o].inventory[d].inquantity_tofirst=s[e][o].inventory[d].inquantity_tofirst+c[u].combos[_].quantity*c[u].quantity,s[e][o].inventory[d].pay_tofirst_btax=s[e][o].inventory[d].pay_tofirst_btax+c[u].combos[_].price*c[u].combos[_].quantity*c[u].quantity,s[e][o].inventory[d].pay_tofirst_atax=s[e][o].inventory[d].pay_tofirst_atax+c[u].combos[_].price*c[u].combos[_].quantity*c[u].quantity*(1+c[u].tax/100)));for(d=l;d<a.length;d++){var p=s[e][o].inventory[d].inquantity_tofirst-s[e][o].inventory[d-1].inquantity_tofirst,b=s[e][o].inventory[d].pay_tofirst_btax-s[e][o].inventory[d-1].pay_tofirst_btax,f=s[e][o].inventory[d].pay_tofirst_atax-s[e][o].inventory[d-1].pay_tofirst_atax;s[e][o].inventory[d].stock_first=s[e][o].inventory[d].inquantity_tofirst-s[e][o].inventory[d].outquantity_tofirst,s[e][o].inventory[d-1].stock_first+p!=0&&(s[e][o].inventory[d].unit_cost_stock_first_btax=(s[e][o].inventory[d-1].cost_stock_first_btax+b)/(s[e][o].inventory[d-1].stock_first+p),s[e][o].inventory[d].unit_cost_stock_first_atax=(s[e][o].inventory[d-1].cost_stock_first_atax+f)/(s[e][o].inventory[d-1].stock_first+p),s[e][o].inventory[d].cost_stock_first_btax=s[e][o].inventory[d].unit_cost_stock_first_btax*s[e][o].inventory[d].stock_first,s[e][o].inventory[d].cost_stock_first_atax=s[e][o].inventory[d].unit_cost_stock_first_atax*s[e][o].inventory[d].stock_first);var h=s[e][o].inventory[d].outquantity_tofirst-s[e][o].inventory[d-1].outquantity_tofirst,y=s[e][o].inventory[d].unit_cost_stock_first_btax*h,m=s[e][o].inventory[d].unit_cost_stock_first_atax*h,v=s[e][o].inventory[d].sales_tofirst_btax-s[e][o].inventory[d-1].sales_tofirst_btax,g=s[e][o].inventory[d].sales_tofirst_atax-s[e][o].inventory[d-1].sales_tofirst_atax;s[e][o].inventory[d].profit_first_btax=v-y,s[e][o].inventory[d].profit_first_atax=g-m}r--;var x=t.getlocalProduct(s[e]._id),q={};null!=x[o]?(q[o]=x[o],q[o].inventory=s[e][o].inventory):q[o]=s[e][o],t.vhmongo_firebase.database().updateDoc("products",s[e]._id,Object.assign({},q)).then((function(){console.log(e,s[e]),n(!0)}))}))}else n(null)}else{u=new Array;var b=new Array;t.getlocalProductAndCombos(s[e]._id).forEach((function(t){b.push(t._id)}));for(_=0;_<b.length;_++){p={bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:o},id_product:{$eq:b[_]}};u[_]=t.vhmongo_firebase.database().getDocsByFields("vhbill_details",p,{},{date:1},0)}Promise.all(u).then((function(i){var l=i.flat();s[e][o]={},s[e][o].inventory=new Array;for(var c=0;c<a.length;c++)s[e][o].inventory[c]={},s[e][o].inventory[c].date=a[c],s[e][o].inventory[c].inquantity_tofirst=0,s[e][o].inventory[c].pay_tofirst_btax=0,s[e][o].inventory[c].pay_tofirst_atax=0,s[e][o].inventory[c].outquantity_tofirst=0,s[e][o].inventory[c].sales_tofirst_btax=0,s[e][o].inventory[c].sales_tofirst_atax=0,s[e][o].inventory[c].stock_first=0,s[e][o].inventory[c].unit_cost_stock_first_btax=0,s[e][o].inventory[c].unit_cost_stock_first_atax=0,s[e][o].inventory[c].cost_stock_first_btax=0,s[e][o].inventory[c].cost_stock_first_atax=0,s[e][o].inventory[c].profit_first_btax=0,s[e][o].inventory[c].profit_first_atax=0;if(l.length>0){for(var u=0;u<l.length;u++)if(1===l[u].ptype){if(l[u].id_product===s[e]._id)for(c=0;c<s[e][o].inventory.length;c++)new Date(l[u].date).getTime()<new Date(s[e][o].inventory[c].date).getTime()&&(1===l[u].bill_type||10===l[u].bill_type||15===l[u].bill_type||30===l[u].bill_type?(s[e][o].inventory[c].outquantity_tofirst=s[e][o].inventory[c].outquantity_tofirst+l[u].quantity,s[e][o].inventory[c].sales_tofirst_btax=s[e][o].inventory[c].sales_tofirst_btax+l[u].price*l[u].quantity,s[e][o].inventory[c].sales_tofirst_atax=s[e][o].inventory[c].sales_tofirst_atax+l[u].price*l[u].quantity*(1+l[u].tax/100)):2!==l[u].bill_type&&3!==l[u].bill_type&&9!==l[u].bill_type&&31!==l[u].bill_type||(s[e][o].inventory[c].inquantity_tofirst=s[e][o].inventory[c].inquantity_tofirst+l[u].quantity,s[e][o].inventory[c].pay_tofirst_btax=s[e][o].inventory[c].pay_tofirst_btax+l[u].price*l[u].quantity,s[e][o].inventory[c].pay_tofirst_atax=s[e][o].inventory[c].pay_tofirst_atax+l[u].price*l[u].quantity*(1+l[u].tax/100)))}else if(5===l[u].ptype)for(var d=0;d<l[u].combos.length;d++)if(l[u].combos[d].id_product===s[e]._id)for(c=0;c<s[e][o].inventory.length;c++)new Date(l[u].date).getTime()<new Date(s[e][o].inventory[c].date).getTime()&&(1===l[u].bill_type||10===l[u].bill_type||15===l[u].bill_type||30===l[u].bill_type?(s[e][o].inventory[c].outquantity_tofirst=s[e][o].inventory[c].outquantity_tofirst+l[u].combos[d].quantity*l[u].quantity,s[e][o].inventory[c].sales_tofirst_btax=s[e][o].inventory[c].sales_tofirst_btax+l[u].combos[d].price*l[u].combos[d].quantity*l[u].quantity,s[e][o].inventory[c].sales_tofirst_atax=s[e][o].inventory[c].sales_tofirst_atax+l[u].combos[d].price*l[u].combos[d].quantity*l[u].quantity*(1+l[u].tax/100)):2!==l[u].bill_type&&3!==l[u].bill_type&&9!==l[u].bill_type&&31!==l[u].bill_type||(s[e][o].inventory[c].inquantity_tofirst=s[e][o].inventory[c].inquantity_tofirst+l[u].combos[d].quantity*l[u].quantity,s[e][o].inventory[c].pay_tofirst_btax=s[e][o].inventory[c].pay_tofirst_btax+l[u].combos[d].price*l[u].combos[d].quantity*l[u].quantity,s[e][o].inventory[c].pay_tofirst_atax=s[e][o].inventory[c].pay_tofirst_atax+l[u].combos[d].price*l[u].combos[d].quantity*l[u].quantity*(1+l[u].tax/100)));for(c=0;c<s[e][o].inventory.length;c++)if(0===c){var _=s[e][o].inventory[0].inquantity_tofirst,p=s[e][o].inventory[0].pay_tofirst_btax,b=s[e][o].inventory[0].pay_tofirst_atax;s[e][o].inventory[0].stock_first=s[e][o].inventory[0].inquantity_tofirst-s[e][o].inventory[0].outquantity_tofirst,0!=_&&(s[e][o].inventory[0].unit_cost_stock_first_btax=p/_,s[e][o].inventory[0].unit_cost_stock_first_atax=b/_,s[e][o].inventory[0].cost_stock_first_btax=s[e][o].inventory[0].unit_cost_stock_first_btax*s[e][o].inventory[0].stock_first,s[e][o].inventory[0].cost_stock_first_atax=s[e][o].inventory[0].unit_cost_stock_first_atax*s[e][o].inventory[0].stock_first);var f=s[e][o].inventory[0].outquantity_tofirst,h=s[e][o].inventory[0].unit_cost_stock_first_btax*f,y=s[e][o].inventory[0].unit_cost_stock_first_atax*f,m=s[e][o].inventory[0].sales_tofirst_btax,v=s[e][o].inventory[0].sales_tofirst_atax;s[e][o].inventory[0].profit_first_btax=m-h,s[e][o].inventory[0].profit_first_atax=v-y}else{_=s[e][o].inventory[c].inquantity_tofirst-s[e][o].inventory[c-1].inquantity_tofirst,p=s[e][o].inventory[c].pay_tofirst_btax-s[e][o].inventory[c-1].pay_tofirst_btax,b=s[e][o].inventory[c].pay_tofirst_atax-s[e][o].inventory[c-1].pay_tofirst_atax;s[e][o].inventory[c].stock_first=s[e][o].inventory[c].inquantity_tofirst-s[e][o].inventory[c].outquantity_tofirst,s[e][o].inventory[c-1].stock_first+_!=0&&(s[e][o].inventory[c].unit_cost_stock_first_btax=(s[e][o].inventory[c-1].cost_stock_first_btax+p)/(s[e][o].inventory[c-1].stock_first+_),s[e][o].inventory[c].unit_cost_stock_first_atax=(s[e][o].inventory[c-1].cost_stock_first_atax+b)/(s[e][o].inventory[c-1].stock_first+_),s[e][o].inventory[c].cost_stock_first_btax=s[e][o].inventory[c].unit_cost_stock_first_btax*s[e][o].inventory[c].stock_first,s[e][o].inventory[c].cost_stock_first_atax=s[e][o].inventory[c].unit_cost_stock_first_atax*s[e][o].inventory[c].stock_first);f=s[e][o].inventory[c].outquantity_tofirst-s[e][o].inventory[c-1].outquantity_tofirst,h=s[e][o].inventory[c].unit_cost_stock_first_btax*f,y=s[e][o].inventory[c].unit_cost_stock_first_atax*f,m=s[e][o].inventory[c].sales_tofirst_btax-s[e][o].inventory[c-1].sales_tofirst_btax,v=s[e][o].inventory[c].sales_tofirst_atax-s[e][o].inventory[c-1].sales_tofirst_atax;s[e][o].inventory[c].profit_first_btax=m-h,s[e][o].inventory[c].profit_first_atax=v-y}}r--;var g=t.getlocalProduct(s[e]._id),x={};null!=g[o]?(x[o]=g[o],x[o].inventory=s[e][o].inventory):x[o]=s[e][o],t.vhmongo_firebase.database().updateDoc("products",s[e]._id,Object.assign({},x)).then((function(){console.log(e,s[e]),n(!0)}))}))}}))},p=d[0];p<=d[d.length-1];p++)c(p);Promise.all(i).then((function(t){r<=0&&(n(e),clearInterval(_)),l.length>0?(u=!0,d=l.splice(0,10)):(n(e),clearInterval(_))}))}}),10)}))},l=0;l<i.length;l++)r(l);Promise.all(s).then((function(t){console.log("syncInventoryEveryDay_Stock1stDayOfMonth",t),e(null)}))}else console.log("syncInventoryEveryDay_Stock1stDayOfMonth"),e(null)}))}))},t.prototype.syncInventoryEveryDay1=function(){var t=this;return new Promise((function(e,n){var o=t.getlocalProducts(1);console.log(o,o);for(var i=new Array,a=0;a<o.length;a++)i.push(a);var s=t.vhAuth.getStore(),r=t.getlocalBranchs();t.vhmongo_firebase.auth().getServerDate().then((function(n){var a=t.get1stDayOfMonthArray(s.registrationdate,n);if(a.length>0){for(var l=new Array,c=function(e){l[e]=new Promise((function(n){var s=r[e]._id,l=!0,c=i.splice(0,1),u=setInterval((function(){if(l){l=!1;for(var r=new Array,d=function(e){r[e]=new Promise((function(n){if(null!=o[e][s]&&null!=o[e][s].inventory){var i=o[e][s].inventory[o[e][s].inventory.length-1];if(new Date(i.date).getTime()!=new Date(a[a.length-1]).getTime()){for(var r=o[e][s].inventory.length;r<a.length;r++)o[e][s].inventory[r]={},o[e][s].inventory[r].date=a[r],o[e][s].inventory[r].inquantity_tofirst=i.inquantity_tofirst,o[e][s].inventory[r].pay_tofirst_btax=i.pay_tofirst_btax,o[e][s].inventory[r].pay_tofirst_atax=i.pay_tofirst_atax,o[e][s].inventory[r].outquantity_tofirst=i.outquantity_tofirst,o[e][s].inventory[r].sales_tofirst_btax=i.sales_tofirst_btax,o[e][s].inventory[r].sales_tofirst_atax=i.sales_tofirst_atax,o[e][s].inventory[r].stock_first=0,o[e][s].inventory[r].unit_cost_stock_first_btax=0,o[e][s].inventory[r].unit_cost_stock_first_atax=0,o[e][s].inventory[r].cost_stock_first_btax=0,o[e][s].inventory[r].cost_stock_first_atax=0,o[e][s].inventory[r].profit_first_btax=0,o[e][s].inventory[r].profit_first_atax=0;var l=new Array,c=new Array;t.getlocalProductAndCombos(o[e]._id).forEach((function(t){c.push(t._id)}));for(var u=0;u<c.length;u++){var d={date:{$gte:new Date(i.date)},bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:s},id_product:{$eq:c[u]}};l[u]=t.vhmongo_firebase.database().getDocsByFields("vhbill_details",d,{},{date:1},0)}Promise.all(l).then((function(t){var i=t.flat();if(i.length>0){for(var a=0;a<i.length;a++)if(1===i[a].ptype){if(i[a].id_product===o[e]._id)for(var r=0;r<o[e][s].inventory.length;r++)new Date(i[a].date).getTime()<new Date(o[e][s].inventory[r].date).getTime()&&(1===i[a].bill_type||10===i[a].bill_type||15===i[a].bill_type||30===i[a].bill_type?(o[e][s].inventory[r].outquantity_tofirst=o[e][s].inventory[r].outquantity_tofirst+i[a].quantity,o[e][s].inventory[r].sales_tofirst_btax=o[e][s].inventory[r].sales_tofirst_btax+i[a].price*i[a].quantity,o[e][s].inventory[r].sales_tofirst_atax=o[e][s].inventory[r].sales_tofirst_atax+i[a].price*i[a].quantity*(1+i[a].tax/100)):2!==i[a].bill_type&&3!==i[a].bill_type&&9!==i[a].bill_type&&31!==i[a].bill_type||(o[e][s].inventory[r].inquantity_tofirst=o[e][s].inventory[r].inquantity_tofirst+i[a].quantity,o[e][s].inventory[r].pay_tofirst_btax=o[e][s].inventory[r].pay_tofirst_btax+i[a].price*i[a].quantity,o[e][s].inventory[r].pay_tofirst_atax=o[e][s].inventory[r].pay_tofirst_atax+i[a].price*i[a].quantity*(1+i[a].tax/100)))}else if(5===i[a].ptype)for(var l=0;l<i[a].combos.length;l++)if(i[a].combos[l].id_product===o[e]._id)for(r=0;r<o[e][s].inventory.length;r++)new Date(i[a].date).getTime()<new Date(o[e][s].inventory[r].date).getTime()&&(1===i[a].bill_type||10===i[a].bill_type||15===i[a].bill_type||30===i[a].bill_type?(o[e][s].inventory[r].outquantity_tofirst=o[e][s].inventory[r].outquantity_tofirst+i[a].combos[l].quantity*i[a].quantity,o[e][s].inventory[r].sales_tofirst_btax=o[e][s].inventory[r].sales_tofirst_btax+i[a].combos[l].price*i[a].combos[l].quantity*i[a].quantity,o[e][s].inventory[r].sales_tofirst_atax=o[e][s].inventory[r].sales_tofirst_atax+i[a].combos[l].price*i[a].combos[l].quantity*i[a].quantity*(1+i[a].tax/100)):2!==i[a].bill_type&&3!==i[a].bill_type&&9!==i[a].bill_type&&31!==i[a].bill_type||(o[e][s].inventory[r].inquantity_tofirst=o[e][s].inventory[r].inquantity_tofirst+i[a].combos[l].quantity*i[a].quantity,o[e][s].inventory[r].pay_tofirst_btax=o[e][s].inventory[r].pay_tofirst_btax+i[a].combos[l].price*i[a].combos[l].quantity*i[a].quantity,o[e][s].inventory[r].pay_tofirst_atax=o[e][s].inventory[r].pay_tofirst_atax+i[a].combos[l].price*i[a].combos[l].quantity*i[a].quantity*(1+i[a].tax/100)));for(r=0;r<o[e][s].inventory.length;r++)if(0===r){var c=o[e][s].inventory[0].inquantity_tofirst,u=o[e][s].inventory[0].pay_tofirst_btax,d=o[e][s].inventory[0].pay_tofirst_atax;o[e][s].inventory[0].stock_first=o[e][s].inventory[0].inquantity_tofirst-o[e][s].inventory[0].outquantity_tofirst,0!=c&&(o[e][s].inventory[0].unit_cost_stock_first_btax=u/c,o[e][s].inventory[0].unit_cost_stock_first_atax=d/c,o[e][s].inventory[0].cost_stock_first_btax=o[e][s].inventory[0].unit_cost_stock_first_btax*o[e][s].inventory[0].stock_first,o[e][s].inventory[0].cost_stock_first_atax=o[e][s].inventory[0].unit_cost_stock_first_atax*o[e][s].inventory[0].stock_first);var _=o[e][s].inventory[0].outquantity_tofirst,p=o[e][s].inventory[0].unit_cost_stock_first_btax*_,b=o[e][s].inventory[0].unit_cost_stock_first_atax*_,f=o[e][s].inventory[0].sales_tofirst_btax,h=o[e][s].inventory[0].sales_tofirst_atax;o[e][s].inventory[0].profit_first_btax=f-p,o[e][s].inventory[0].profit_first_atax=h-b}else{c=o[e][s].inventory[r].inquantity_tofirst-o[e][s].inventory[r-1].inquantity_tofirst,u=o[e][s].inventory[r].pay_tofirst_btax-o[e][s].inventory[r-1].pay_tofirst_btax,d=o[e][s].inventory[r].pay_tofirst_atax-o[e][s].inventory[r-1].pay_tofirst_atax;o[e][s].inventory[r].stock_first=o[e][s].inventory[r].inquantity_tofirst-o[e][s].inventory[r].outquantity_tofirst,o[e][s].inventory[r-1].stock_first+c!=0&&(o[e][s].inventory[r].unit_cost_stock_first_btax=(o[e][s].inventory[r-1].cost_stock_first_btax+u)/(o[e][s].inventory[r-1].stock_first+c),o[e][s].inventory[r].unit_cost_stock_first_atax=(o[e][s].inventory[r-1].cost_stock_first_atax+d)/(o[e][s].inventory[r-1].stock_first+c),o[e][s].inventory[r].cost_stock_first_btax=o[e][s].inventory[r].unit_cost_stock_first_btax*o[e][s].inventory[r].stock_first,o[e][s].inventory[r].cost_stock_first_atax=o[e][s].inventory[r].unit_cost_stock_first_atax*o[e][s].inventory[r].stock_first);_=o[e][s].inventory[r].outquantity_tofirst-o[e][s].inventory[r-1].outquantity_tofirst,p=o[e][s].inventory[r].unit_cost_stock_first_btax*_,b=o[e][s].inventory[r].unit_cost_stock_first_atax*_,f=o[e][s].inventory[r].sales_tofirst_btax-o[e][s].inventory[r-1].sales_tofirst_btax,h=o[e][s].inventory[r].sales_tofirst_atax-o[e][s].inventory[r-1].sales_tofirst_atax;o[e][s].inventory[r].profit_first_btax=f-p,o[e][s].inventory[r].profit_first_atax=h-b}}console.log(e,o[e]),n(o[e])}))}else console.log(e,null),n(null)}else{l=new Array;var _=new Array;t.getlocalProductAndCombos(o[e]._id).forEach((function(t){_.push(t._id)}));for(u=0;u<_.length;u++){d={bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:s},id_product:{$eq:_[u]}};l[u]=t.vhmongo_firebase.database().getDocsByFields("vhbill_details",d,{},{date:1},0)}Promise.all(l).then((function(t){var i=t.flat();o[e][s]={},o[e][s].inventory=new Array;for(var r=0;r<a.length;r++)o[e][s].inventory[r]={},o[e][s].inventory[r].date=a[r],o[e][s].inventory[r].inquantity_tofirst=0,o[e][s].inventory[r].pay_tofirst_btax=0,o[e][s].inventory[r].pay_tofirst_atax=0,o[e][s].inventory[r].outquantity_tofirst=0,o[e][s].inventory[r].sales_tofirst_btax=0,o[e][s].inventory[r].sales_tofirst_atax=0,o[e][s].inventory[r].stock_first=0,o[e][s].inventory[r].unit_cost_stock_first_btax=0,o[e][s].inventory[r].unit_cost_stock_first_atax=0,o[e][s].inventory[r].cost_stock_first_btax=0,o[e][s].inventory[r].cost_stock_first_atax=0,o[e][s].inventory[r].profit_first_btax=0,o[e][s].inventory[r].profit_first_atax=0;if(i.length>0){for(var l=0;l<i.length;l++)if(1===i[l].ptype){if(i[l].id_product===o[e]._id)for(r=0;r<o[e][s].inventory.length;r++)new Date(i[l].date).getTime()<new Date(o[e][s].inventory[r].date).getTime()&&(1===i[l].bill_type||10===i[l].bill_type||15===i[l].bill_type||30===i[l].bill_type?(o[e][s].inventory[r].outquantity_tofirst=o[e][s].inventory[r].outquantity_tofirst+i[l].quantity,o[e][s].inventory[r].sales_tofirst_btax=o[e][s].inventory[r].sales_tofirst_btax+i[l].price*i[l].quantity,o[e][s].inventory[r].sales_tofirst_atax=o[e][s].inventory[r].sales_tofirst_atax+i[l].price*i[l].quantity*(1+i[l].tax/100)):2!==i[l].bill_type&&3!==i[l].bill_type&&9!==i[l].bill_type&&31!==i[l].bill_type||(o[e][s].inventory[r].inquantity_tofirst=o[e][s].inventory[r].inquantity_tofirst+i[l].quantity,o[e][s].inventory[r].pay_tofirst_btax=o[e][s].inventory[r].pay_tofirst_btax+i[l].price*i[l].quantity,o[e][s].inventory[r].pay_tofirst_atax=o[e][s].inventory[r].pay_tofirst_atax+i[l].price*i[l].quantity*(1+i[l].tax/100)))}else if(5===i[l].ptype)for(var c=0;c<i[l].combos.length;c++)if(i[l].combos[c].id_product===o[e]._id)for(r=0;r<o[e][s].inventory.length;r++)new Date(i[l].date).getTime()<new Date(o[e][s].inventory[r].date).getTime()&&(1===i[l].bill_type||10===i[l].bill_type||15===i[l].bill_type||30===i[l].bill_type?(o[e][s].inventory[r].outquantity_tofirst=o[e][s].inventory[r].outquantity_tofirst+i[l].combos[c].quantity*i[l].quantity,o[e][s].inventory[r].sales_tofirst_btax=o[e][s].inventory[r].sales_tofirst_btax+i[l].combos[c].price*i[l].combos[c].quantity*i[l].quantity,o[e][s].inventory[r].sales_tofirst_atax=o[e][s].inventory[r].sales_tofirst_atax+i[l].combos[c].price*i[l].combos[c].quantity*i[l].quantity*(1+i[l].tax/100)):2!==i[l].bill_type&&3!==i[l].bill_type&&9!==i[l].bill_type&&31!==i[l].bill_type||(o[e][s].inventory[r].inquantity_tofirst=o[e][s].inventory[r].inquantity_tofirst+i[l].combos[c].quantity*i[l].quantity,o[e][s].inventory[r].pay_tofirst_btax=o[e][s].inventory[r].pay_tofirst_btax+i[l].combos[c].price*i[l].combos[c].quantity*i[l].quantity,o[e][s].inventory[r].pay_tofirst_atax=o[e][s].inventory[r].pay_tofirst_atax+i[l].combos[c].price*i[l].combos[c].quantity*i[l].quantity*(1+i[l].tax/100)));for(r=0;r<o[e][s].inventory.length;r++)if(0===r){var u=o[e][s].inventory[0].inquantity_tofirst,d=o[e][s].inventory[0].pay_tofirst_btax,_=o[e][s].inventory[0].pay_tofirst_atax;o[e][s].inventory[0].stock_first=o[e][s].inventory[0].inquantity_tofirst-o[e][s].inventory[0].outquantity_tofirst,0!=u&&(o[e][s].inventory[0].unit_cost_stock_first_btax=d/u,o[e][s].inventory[0].unit_cost_stock_first_atax=_/u,o[e][s].inventory[0].cost_stock_first_btax=o[e][s].inventory[0].unit_cost_stock_first_btax*o[e][s].inventory[0].stock_first,o[e][s].inventory[0].cost_stock_first_atax=o[e][s].inventory[0].unit_cost_stock_first_atax*o[e][s].inventory[0].stock_first);var p=o[e][s].inventory[0].outquantity_tofirst,b=o[e][s].inventory[0].unit_cost_stock_first_btax*p,f=o[e][s].inventory[0].unit_cost_stock_first_atax*p,h=o[e][s].inventory[0].sales_tofirst_btax,y=o[e][s].inventory[0].sales_tofirst_atax;o[e][s].inventory[0].profit_first_btax=h-b,o[e][s].inventory[0].profit_first_atax=y-f}else{u=o[e][s].inventory[r].inquantity_tofirst-o[e][s].inventory[r-1].inquantity_tofirst,d=o[e][s].inventory[r].pay_tofirst_btax-o[e][s].inventory[r-1].pay_tofirst_btax,_=o[e][s].inventory[r].pay_tofirst_atax-o[e][s].inventory[r-1].pay_tofirst_atax;o[e][s].inventory[r].stock_first=o[e][s].inventory[r].inquantity_tofirst-o[e][s].inventory[r].outquantity_tofirst,o[e][s].inventory[r-1].stock_first+u!=0&&(o[e][s].inventory[r].unit_cost_stock_first_btax=(o[e][s].inventory[r-1].cost_stock_first_btax+d)/(o[e][s].inventory[r-1].stock_first+u),o[e][s].inventory[r].unit_cost_stock_first_atax=(o[e][s].inventory[r-1].cost_stock_first_atax+_)/(o[e][s].inventory[r-1].stock_first+u),o[e][s].inventory[r].cost_stock_first_btax=o[e][s].inventory[r].unit_cost_stock_first_btax*o[e][s].inventory[r].stock_first,o[e][s].inventory[r].cost_stock_first_atax=o[e][s].inventory[r].unit_cost_stock_first_atax*o[e][s].inventory[r].stock_first);p=o[e][s].inventory[r].outquantity_tofirst-o[e][s].inventory[r-1].outquantity_tofirst,b=o[e][s].inventory[r].unit_cost_stock_first_btax*p,f=o[e][s].inventory[r].unit_cost_stock_first_atax*p,h=o[e][s].inventory[r].sales_tofirst_btax-o[e][s].inventory[r-1].sales_tofirst_btax,y=o[e][s].inventory[r].sales_tofirst_atax-o[e][s].inventory[r-1].sales_tofirst_atax;o[e][s].inventory[r].profit_first_btax=h-b,o[e][s].inventory[r].profit_first_atax=y-f}}console.log(e,o[e]),n(o[e])}))}}))},_=c[0];_<=c[c.length-1];_++)d(_);Promise.all(r).then((function(o){for(var a=0;a<o.length;a++)if(o[a]){var r={};r[s]=o[a][s],t.vhmongo_firebase.database().updateDoc("products",o[a]._id,Object.assign({},r))}i.length>0?(l=!0,c=i.splice(0,1)):(n(e),clearInterval(u))}))}}),100)}))},u=0;u<r.length;u++)c(u);Promise.all(l).then((function(t){console.log("syncInventoryEveryDay",t),e(null)}))}}))}))},t.prototype.makeCorrectQuantityProducts_byShop=function(){var t=this;return new Promise((function(e,n){var o=t.getDefaultBranch()._id,i=(t.vhAuth.getStore(),new Array);i=t.vhAlgorithm.sortVietnamesebyASC(t.getlocalProducts(1),"name");var a=!1,s=new Date;s.setHours(0),s.setMinutes(0),s.setSeconds(0),s.setMilliseconds(0);var r=t.vhAuth.localStorageGET(o+"_date_make_correct_quantity_products_byshop");if(null!=r?r!=s.getTime()&&(a=!0,t.vhAuth.localStorageSET(o+"_date_make_correct_quantity_products_byshop",s.getTime())):(a=!0,t.vhAuth.localStorageSET(o+"_date_make_correct_quantity_products_byshop",s.getTime())),a)if(i.length>0){var l,c=new Array;l={bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:o}},c[0]=t.vhmongo_firebase.database().getDocsByFields("vhbill_details",l,{},{date:1},0),Promise.all(c).then((function(n){for(var a=n.flat(),s=(new Array,0);s<i.length;s++){for(var r={stock_first:0},l={_id:i[s]._id,name:i[s].name,type:i[s].type,unit:i[s].unit,outquantity:0,inquantity:0,stock_first:0,stock_last:0},u=0;u<a.length;u++)if(1===a[u].ptype){if(a[u].id_product===i[s]._id){new Date(a[u].date);1===a[u].bill_type||10===a[u].bill_type||15===a[u].bill_type||30===a[u].bill_type?l.outquantity=l.outquantity+a[u].quantity:2===a[u].bill_type||3===a[u].bill_type||31===a[u].bill_type?(l.cost_btax=l.cost_btax+a[u].price*a[u].quantity,l.cost_atax=l.cost_atax+a[u].price*a[u].quantity*(1+a[u].tax/100),l.inquantity=l.inquantity+a[u].quantity):9===a[u].bill_type&&(r.stock_first=r.stock_first+a[u].quantity)}}else if(5===a[u].ptype)for(var d=0;d<a[u].combos.length;d++)if(a[u].combos[d].id_product===i[s]._id){new Date(a[u].date);1===a[u].bill_type||10===a[u].bill_type||15===a[u].bill_type||30===a[u].bill_type?l.outquantity=l.outquantity+a[u].combos[d].quantity*a[u].quantity:2===a[u].bill_type||3===a[u].bill_type||31===a[u].bill_type?(l.cost_btax=l.cost_btax+a[u].combos[d].price*a[u].combos[d].quantity*a[u].quantity,l.cost_atax=l.cost_atax+a[u].combos[d].price*a[u].combos[d].quantity*a[u].quantity*(1+a[u].tax/100),l.inquantity=l.inquantity+a[u].combos[d].quantity*a[u].quantity):9===a[u].bill_type&&(r.stock_first=r.stock_first+a[u].combos[d].quantity*a[u].quantity);break}if(l.stock_first=r.stock_first,l.stock_last=l.stock_first+l.inquantity-l.outquantity,null!=i[s].quantity_branch[o]){if(i[s].quantity_branch[o]!=l.stock_last){console.log("wrong quality product",i[s]),console.log("products[i].quantity_branch[id_branch]",i[s].quantity_branch[o]),console.log("product.stock_last",l.stock_last),console.log("-----------------------------------------------------------------------");var _={};_[o]=Object.assign({},i[s][o]),_[o].inventory=null;var p={};(p=Object.assign({},i[s].quantity_branch))[o]=l.stock_last;var b=0;for(var f in p)b+=p[f];c.push(t.updateProduct(i[s]._id,Object.assign({quantity:b,quantity_branch:p},_))),c.push(null)}}else if(console.log("undefined quantity product",i[s]),null!=i[s].quantity_branch){p={};(p=Object.assign({},i[s].quantity_branch))[o]=0;b=0;for(var f in p)b+=p[f];c.push(t.updateProduct(i[s]._id,{quantity:b,quantity_branch:p}))}}Promise.all(c).then((function(){console.log("finished"),e(!0)}))}))}else console.log("server -> products khong ton tai trong CSDL: "),e(null);else e(!0)}))},t.prototype.makeCorrectQuantityProducts_60days=function(){var t=this;return new Promise((function(e,n){var o=t.getDefaultBranch()._id,i={docs:new Array,empty:!0,size:0},a=t.vhAuth.getStore(),s=new Array;s=t.vhAlgorithm.sortVietnamesebyASC(t.getlocalProducts(1),"name");var r=null,l=null;if(null!=s[0][o]&&null!=s[0][o].inventory&&(r=s[0][o].inventory.length-1,l=new Date(s[0][o].inventory[r].date)),l||(l=new Date(a.registrationdate)),s.length>0){var c,u=new Array;c={date:{$gte:l},bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:o}},u[0]=t.vhmongo_firebase.database().getDocsByFields("vhbill_details",c,{},{date:1},0),Promise.all(u).then((function(n){for(var a=n.flat(),l=(new Array,0);l<s.length;l++){for(var c={stock_first:0,cost_stock_first_btax:0,cost_stock_first_atax:0,unit_cost_stock_first_btax:0,unit_cost_stock_first_atax:0,inquantity_tofirst:0,outquantity_tofirst:0,pay_tofirst_btax:0,pay_tofirst_atax:0,profit_first_btax:0,profit_first_atax:0,sales_tofirst_btax:0,sales_tofirst_atax:0},d={_id:s[l]._id,name:s[l].name,type:s[l].type,unit:s[l].unit,outquantity:0,inquantity:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0,stock_first:0,stock_last:0,cost_stock_first_btax:0,cost_stock_first_atax:0,cost_stock_last_btax:0,cost_stock_last_atax:0},_=0;_<a.length;_++)if(1===a[_].ptype){if(a[_].id_product===s[l]._id){new Date(a[_].date);1===a[_].bill_type||10===a[_].bill_type||15===a[_].bill_type||30===a[_].bill_type?d.outquantity=d.outquantity+a[_].quantity:2===a[_].bill_type||3===a[_].bill_type||31===a[_].bill_type?(d.cost_btax=d.cost_btax+a[_].price*a[_].quantity,d.cost_atax=d.cost_atax+a[_].price*a[_].quantity*(1+a[_].tax/100),d.inquantity=d.inquantity+a[_].quantity):9===a[_].bill_type&&(c.stock_first=c.stock_first+a[_].quantity,c.cost_stock_first_btax=c.cost_stock_first_btax+a[_].price*a[_].quantity,c.cost_stock_first_atax=c.cost_stock_first_atax+a[_].price*a[_].quantity*(1+a[_].tax/100))}}else if(5===a[_].ptype)for(var p=0;p<a[_].combos.length;p++)if(a[_].combos[p].id_product===s[l]._id){new Date(a[_].date);1===a[_].bill_type||10===a[_].bill_type||15===a[_].bill_type||30===a[_].bill_type?d.outquantity=d.outquantity+a[_].combos[p].quantity*a[_].quantity:2===a[_].bill_type||3===a[_].bill_type||31===a[_].bill_type?(d.cost_btax=d.cost_btax+a[_].combos[p].price*a[_].combos[p].quantity*a[_].quantity,d.cost_atax=d.cost_atax+a[_].combos[p].price*a[_].combos[p].quantity*a[_].quantity*(1+a[_].tax/100),d.inquantity=d.inquantity+a[_].combos[p].quantity*a[_].quantity):9===a[_].bill_type&&(c.stock_first=c.stock_first+a[_].combos[p].quantity*a[_].quantity,c.cost_stock_first_btax=c.cost_stock_first_btax+a[_].combos[p].price*a[_].combos[p].quantity*a[_].quantity,c.cost_stock_first_atax=c.cost_stock_first_atax+a[_].combos[p].price*a[_].combos[p].quantity*a[_].quantity*(1+a[_].tax/100));break}if(null!=r&&(c=Object.assign({},s[l][o].inventory[r])),d.stock_first=c.stock_first,d.stock_last=d.stock_first+d.inquantity-d.outquantity,null!=s[l].quantity_branch[o]&&s[l].quantity_branch[o]!=d.stock_last){console.log("khác products[i]",s[l]),console.log("products[i].quantity_branch[id_branch]",s[l].quantity_branch[o]),console.log("product.stock_last",d.stock_last),console.log("-----------------------------------------------------------------------");var b={};(b=Object.assign({},s[l].quantity_branch))[o]=d.stock_last,u.push(t.updateProduct(s[l]._id,{quantity_branch:b}))}0!=c.stock_first&&(d.cost_stock_first_btax=c.cost_stock_first_btax/c.stock_first*d.stock_first,d.cost_stock_first_atax=c.cost_stock_first_atax/c.stock_first*d.stock_first),0!=c.stock_first&&(d.cost_stock_last_btax=c.cost_stock_first_btax/c.stock_first*d.stock_last,d.cost_stock_last_atax=c.cost_stock_first_atax/c.stock_first*d.stock_last),0==d.stock_first&&0==d.stock_last&&0==d.inquantity&&0==d.outquantity||(d.cost_atax=Math.round(1e6*d.cost_atax)/1e6,d.cost_stock_first_atax=Math.round(1e6*d.cost_stock_first_atax)/1e6,d.cost_stock_last_atax=Math.round(1e6*d.cost_stock_last_atax)/1e6,d.index=i.size+1,i.docs.push(d),i.size++,i.empty=!1)}Promise.all(u).then((function(){console.log("finished"),e(i),console.log("makeCorrectQuantityProducts_60days",i)}))}))}else console.log("server -> products khong ton tai trong CSDL: "),e(i)}))},t.prototype.makeCorrectQuantityProducts=function(){var t=this;return new Promise((function(e,n){var o=t.getlocalProducts(1),i=t.getDefaultBranch()._id,a={ptype:{$eq:1},id_branch:{$eq:i},bill_type:{$in:[1,10,15,30,2,3,9,31]}};t.vhmongo_firebase.database().getDocsByFields("vhbill_details",a,{},{date:1},0).then((function(t){if(o.length>0&&t.length>0){for(var n=new Array,a=0;a<o.length;a++){var s={};s[i]=0;for(var r=0;r<t.length;r++){var l=t[r];o[a]._id===l.id_product&&(1===l.bill_type||10===l.bill_type||15===l.bill_type||30===t[r].bill_type?(l.quantity,s[i]=s[i]-l.quantity):2!==l.bill_type&&3!==l.bill_type&&9!==l.bill_type&&31!==t[r].bill_type||(l.quantity,s[i]=s[i]+l.quantity))}null!=o[a].quantity_branch[i]?o[a].quantity_branch[i]!=s[i]&&(console.log("khác 1 quantity_branch",o[a]),console.log("products[i].quantity_branch[id_branch]",o[a].quantity_branch[i]),console.log("quantity_branch[id_branch]",s[i])):console.log("khác quantity",o[a])}Promise.all(n).then((function(){console.log("finished"),e(null)}))}else e(null)}))}))},t.prototype.makeCorrectQuantityProductsManyBranch=function(){var t=this;return new Promise((function(e,n){var o=t.getlocalProducts(1),i=t.getlocalBranchs();t.vhmongo_firebase.database().getDocsByFields("vhbill_details",{ptype:{$eq:1},bill_type:{$in:[1,10,15,30,2,3,9,31]}},{},{date:1},0).then((function(t){if(o.length>0&&t.length>0){for(var n=new Array,a=0;a<o.length;a++){for(var s=0,r={},l=0;l<i.length;l++)r[i[l]._id]=0;for(var c=0;c<t.length;c++){var u=t[c];o[a]._id===u.id_product&&(1===u.bill_type||10===u.bill_type||15===u.bill_type||30===t[c].bill_type?(s-=u.quantity,null!=r[u.id_branch]?r[u.id_branch]=r[u.id_branch]-u.quantity:r[u.id_branch]=-u.quantity):2!==u.bill_type&&3!==u.bill_type&&9!==u.bill_type&&31!==t[c].bill_type||(s+=u.quantity,null!=r[u.id_branch]?r[u.id_branch]=r[u.id_branch]+u.quantity:r[u.id_branch]=u.quantity))}var d=!1;for(var _ in o[a].quantity!=s&&(d=!0),o[a].quantity_branch)for(var p in r)_===p&&o[a].quantity_branch[_]===r[p]&&(d=!0);d&&(console.log("products[i]",o[a]),n.push(new Promise((function(t){t(null)}))))}Promise.all(n).then((function(){e(null)}))}else e(null)}))}))},t.prototype.getReportProducts_byLowInStock=function(t){var e=this;return new Promise((function(n,o){var i=e.getlocalProducts(1),a=e.getlocalBranchs(),s=new Array;if("all"===t||void 0===t){for(var r=0;r<i.length;r++){i[r].quantity=0,i[r].branchs=new Array;for(var l=0;l<a.length;l++)if(void 0===i[r].quantity_branch[a[l]._id]&&(i[r].quantity_branch[a[l]._id]=0),i[r].quantity_branch[a[l]._id]<=i[r].warning_number){i[r].quantity=i[r].quantity+i[r].quantity_branch[a[l]._id];var c={id_branch:a[l]._id,name:a[l].name,quantity:i[r].quantity_branch[a[l]._id]};i[r].branchs.push(c)}delete i[r].quantity_branch}s=i.filter((function(t){return t.branchs.length>0}))}else{for(r=0;r<i.length;r++){i[r].quantity=0,i[r].branchs=new Array,void 0===i[r].quantity_branch[t]&&(i[r].quantity_branch[t]=0),i[r].quantity=i[r].quantity_branch[t];c={id_branch:t,name:e.getlocalBranch(t).name,quantity:i[r].quantity_branch[t]};i[r].branchs.push(c),delete i[r].quantity_branch}s=i.filter((function(t){if(t.quantity<=t.warning_number)return!0}))}n(s)}))},t.prototype.getReportProducts_byOutOfStock=function(t){var e=this;return new Promise((function(n,o){var i=e.getlocalProducts(1),a=e.getlocalBranchs(),s=new Array;if("all"===t||void 0===t){for(var r=0;r<i.length;r++)for(var l=0;l<a.length;l++);for(r=0;r<i.length;r++){i[r].quantity=0,i[r].branchs=new Array;for(l=0;l<a.length;l++)if(void 0===i[r].quantity_branch[a[l]._id]&&(i[r].quantity_branch[a[l]._id]=0),i[r].quantity_branch[a[l]._id]<=0){i[r].quantity=i[r].quantity+i[r].quantity_branch[a[l]._id];var c={id_branch:a[l]._id,name:a[l].name,quantity:i[r].quantity_branch[a[l]._id]};i[r].branchs.push(c)}delete i[r].quantity_branch}s=i.filter((function(t){return t.branchs.length>0}))}else{for(r=0;r<i.length;r++){i[r].quantity=0,i[r].branchs=new Array,void 0===i[r].quantity_branch[t]&&(i[r].quantity_branch[t]=0),i[r].quantity=i[r].quantity_branch[t];c={id_branch:t,name:e.getlocalBranch(t).name,quantity:i[r].quantity_branch[t]};i[r].branchs.push(c),delete i[r].quantity_branch}s=i.filter((function(t){if(t.quantity<=0)return!0}))}n(s)}))},t.prototype.getReportRevenue_byHoursOut_hourArray=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l={docs:new Array,empty:!0,size:0,revenue:0};r="all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1,7,10,11,15]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1,7,10,11,15]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("bills",r,{},{date:1},0).then((function(t){if(t.length>0){for(var e=new Array,o=0;o<n.length;o++)e[o]={},e[o].revenue=0;for(var i=0;i<t.length;i++){var s=Object.assign({},t[i]);if(s.date){var r=new Date(s.date).getHours();for(o=0;o<n.length;o++)n[o]===r&&(e[o].revenue=e[o].revenue+Number(s.payment),l.revenue=l.revenue+Number(s.payment))}}l.docs=e,l.size=n.length,l.empty=!1}a(l)}))}))},t.prototype.getReportRevenue_byDaysOut_dayArray=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l={docs:new Array,empty:!0,size:0,revenue:0};r="all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1,7,10,11,15]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1,7,10,11,15]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("bills",r,{},{date:1},0).then((function(t){if(t.length>0){for(var e=new Array,o=0;o<n.length;o++)e[o]={},e[o].revenue=0;for(var i=0;i<t.length;i++){var s=t[i];if(s.date){var r=new Date(s.date).getDate();for(o=0;o<n.length;o++)n[o]===r&&(e[o].revenue=e[o].revenue+Number(s.payment),l.revenue=l.revenue+Number(s.payment))}}l.docs=e,l.size=n.length,l.empty=!1}a(l)}))}))},t.prototype.getReportRevenue_byMonthsOut_monthArray=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l={docs:new Array,empty:!0,size:0,revenue:0};r="all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1,7,10,11,15]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1,7,10,11,15]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("bills",r,{},{date:1},0).then((function(t){if(t.length>0){for(var e=new Array,o=0;o<n.length;o++)e[o]={},e[o].revenue=0;for(var i=0;i<t.length;i++){var s=t[i];if(s.date){var r=new Date(s.date).getMonth();for(o=0;o<n.length;o++)n[o]===r&&(e[o].revenue=e[o].revenue+Number(s.payment),l.revenue=l.revenue+Number(s.payment))}}l.docs=e,l.size=n.length,l.empty=!1}a(l)}))}))},t.prototype.getReportRevenue_byIDbranch=function(t,e,n){var o=this;return new Promise((function(i,a){var s,r={docs:new Array,empty:!0,size:0,revenue:0},l=new Array;if("all"===n||void 0===n)l=o.vhAlgorithm.sortVietnamesebyASC(o.getlocalBranchs(),"name"),s={date:{$gte:t,$lte:e},bill_type:{$in:[1,7,10,11,15]}};else{var c=o.getlocalBranch(n);l.push(c),s={date:{$gte:t,$lte:e},bill_type:{$in:[1,7,10,11,15]},id_branch:{$eq:n}}}o.vhmongo_firebase.database().getDocsByFields("bills",s,{},{date:1},0).then((function(t){if(t.length>0){for(var e=new Array,n=0;n<l.length;n++)e[n]={},e[n].id_branch=l[n]._id,e[n].name=l[n].name,e[n].revenue=0;for(var o=0;o<t.length;o++)for(n=0;n<l.length;n++)l[n]._id===t[o].id_branch&&(e[n].revenue=e[n].revenue+Number(t[o].payment),r.revenue=r.revenue+Number(t[o].payment));r.docs=e,r.size=l.length,r.empty=!1}i(r)}))}))},t.prototype.getReportSales_byHoursOut_hourArray=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0};r="all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1,3,15]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1,3,15]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("vhbill_details",r,{},{date:1},0).then((function(t){if(t.length>0){for(var e=new Array,o=0;o<n.length;o++)e[o]={},e[o].sales_btax=0,e[o].sales_atax=0;for(var i=0;i<t.length;i++){var s=Object.assign({},t[i]);if(s.date){var r=new Date(s.date).getHours();for(o=0;o<n.length;o++)n[o]===r&&(3===s.bill_type?(e[o].sales_btax=e[o].sales_btax-Number(s.price)*s.quantity,e[o].sales_atax=e[o].sales_atax-Number(s.price)*s.quantity*(1+s.tax/100),l.sales_btax=l.sales_btax-Number(s.price)*s.quantity,l.sales_atax=l.sales_atax-Number(s.price)*s.quantity*(1+s.tax/100)):(e[o].sales_btax=e[o].sales_btax+Number(s.price)*s.quantity,e[o].sales_atax=e[o].sales_atax+Number(s.price)*s.quantity*(1+s.tax/100),l.sales_btax=l.sales_btax+Number(s.price)*s.quantity,l.sales_atax=l.sales_atax+Number(s.price)*s.quantity*(1+s.tax/100)))}}l.docs=e,l.size=n.length,l.empty=!1}a(l)}))}))},t.prototype.getReportSales_byDaysOut_dayArray=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0};r="all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1,3,15]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1,3,15]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("vhbill_details",r,{},{date:1},0).then((function(t){if(t.length>0){for(var e=new Array,o=0;o<n.length;o++)e[o]={},e[o].sales_btax=0,e[o].sales_atax=0;for(var i=0;i<t.length;i++){var s=Object.assign({},t[i]);if(s.date){var r=new Date(s.date).getDate();for(o=0;o<n.length;o++)n[o]===r&&(3===s.bill_type?(e[o].sales_btax=e[o].sales_btax-Number(s.price)*s.quantity,e[o].sales_atax=e[o].sales_atax-Number(s.price)*s.quantity*(1+s.tax/100),l.sales_btax=l.sales_btax-Number(s.price)*s.quantity,l.sales_atax=l.sales_atax-Number(s.price)*s.quantity*(1+s.tax/100)):(e[o].sales_btax=e[o].sales_btax+Number(s.price)*s.quantity,e[o].sales_atax=e[o].sales_atax+Number(s.price)*s.quantity*(1+s.tax/100),l.sales_btax=l.sales_btax+Number(s.price)*s.quantity,l.sales_atax=l.sales_atax+Number(s.price)*s.quantity*(1+s.tax/100)))}}l.docs=e,l.size=n.length,l.empty=!1}a(l)}))}))},t.prototype.getReportSales_byMonthsOut_monthArray=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r,l={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0};r="all"===o||void 0===o?{date:{$gte:t,$lte:e},bill_type:{$in:[1,15]}}:{date:{$gte:t,$lte:e},bill_type:{$in:[1,15]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("vhbill_details",r,{},{date:1},0).then((function(t){if(t.length>0){for(var e=new Array,o=0;o<n.length;o++)e[o]={},e[o].sales_btax=0,e[o].sales_atax=0;for(var i=0;i<t.length;i++){var s=t[i];if(s.date){var r=new Date(s.date).getMonth();for(o=0;o<n.length;o++)n[o]===r&&(3===s.bill_type?(e[o].sales_btax=e[o].sales_btax-Number(s.price)*s.quantity,e[o].sales_atax=e[o].sales_atax-Number(s.price)*s.quantity*(1+s.tax/100),l.sales_btax=l.sales_btax-Number(s.price)*s.quantity,l.sales_atax=l.sales_atax-Number(s.price)*s.quantity*(1+s.tax/100)):(e[o].sales_btax=e[o].sales_btax+Number(s.price)*s.quantity,e[o].sales_atax=e[o].sales_atax+Number(s.price)*s.quantity*(1+s.tax/100),l.sales_btax=l.sales_btax+Number(s.price)*s.quantity,l.sales_atax=l.sales_atax+Number(s.price)*s.quantity*(1+s.tax/100)))}}l.docs=e,l.size=n.length,l.empty=!1}a(l)}))}))},t.prototype.getReportSales_byIDbranch=function(t,e,n){var o=this;return new Promise((function(i,a){var s,r={docs:new Array,empty:!0,size:0,sales_btax:0,sales_atax:0},l=new Array;if("all"===n||void 0===n)l=o.vhAlgorithm.sortVietnamesebyASC(o.getlocalBranchs(),"name"),s={date:{$gte:t,$lte:e},bill_type:{$in:[1,15,3]}};else{var c=o.getlocalBranch(n);l.push(c),s={date:{$gte:t,$lte:e},bill_type:{$in:[1,15,3]},id_branch:{$eq:n}}}o.vhmongo_firebase.database().getDocsByFields("vhbill_details",s,{},{date:1},0).then((function(t){if(t.length>0){for(var e=new Array,n=0;n<l.length;n++)e[n]={},e[n].id_branch=l[n]._id,e[n].name=l[n].name,e[n].sales_btax=0,e[n].sales_atax=0;for(var o=0;o<t.length;o++){var a=t[o];for(n=0;n<l.length;n++)l[n]._id===a.id_branch&&(3===a.bill_type?(e[n].sales_btax=e[n].sales_btax-Number(a.price)*a.quantity,e[n].sales_atax=e[n].sales_atax-Number(a.price)*a.quantity*(1+a.tax/100),r.sales_btax=r.sales_btax-Number(a.price)*a.quantity,r.sales_atax=r.sales_atax-Number(a.price)*a.quantity*(1+a.tax/100)):(e[n].sales_btax=e[n].sales_btax+Number(a.price)*a.quantity,e[n].sales_atax=e[n].sales_atax+Number(a.price)*a.quantity*(1+a.tax/100),r.sales_btax=r.sales_btax+Number(a.price)*a.quantity,r.sales_atax=r.sales_atax+Number(a.price)*a.quantity*(1+a.tax/100)))}r.docs=e,r.size=l.length,r.empty=!1}i(r)}))}))},t.prototype.getReportCashBook=function(t,e,n,o){var i=this;t=new Date(t),e=new Date(e);var a=[1,7,10,11,15,34,2,3,8,12,33],s=this.vhAuth.getStore();return new Promise((function(r,l){var c,u=0,d=null;if("all"===n)if("all"===o||void 0===o){for(var _=i.getlocalWallets(),p=i.getDefaultBranch()._id,b=null,f=0;f<_.length;f++)if("id_cash"===_[f]._id&&null!=_[f][o]&&null!=_[f][o].cashbook)for(var h=0;h<_[f][p].cashbook.length&&!(new Date(_[f][p].cashbook[h].date).getTime()>t.getTime());h++)d=new Date(_[f][p].cashbook[h].date),b=h;if(d)for(f=0;f<_.length;f++)if("id_cash"===_[f]._id)for(var y=i.getlocalBranchs(),m=0;m<y.length;m++)u+=_[f][y[m]._id].cashbook[b].cashbook_first;else u+=_[f].cashbook[b].cashbook_first}else{for(_=i.getlocalWallets().filter((function(t){return t.id_branch===o||"id_cash"===t._id})),b=null,f=0;f<_.length;f++)if("id_cash"===_[f]._id&&null!=_[f][o]&&null!=_[f][o].cashbook)for(h=0;h<_[f][o].cashbook.length&&!(new Date(_[f][o].cashbook[h].date).getTime()>t.getTime());h++)d=new Date(_[f][o].cashbook[h].date),b=h;if(d)for(f=0;f<_.length;f++)"id_cash"===_[f]._id?u+=_[f][o].cashbook[b].cashbook_first:u+=_[f].cashbook[b].cashbook_first}else if("all"===o||void 0===o)console.log("trường hợp này chưa có hàm, liên hệ anh Huy viết");else{var v=i.getlocalWallet(n);if("id_cash"===v._id){if(null!=v[o]&&null!=v[o].cashbook)for(h=0;h<v[o].cashbook.length&&!(new Date(v[o].cashbook[h].date).getTime()>t.getTime());h++)d=new Date(v[o].cashbook[h].date),u=v[o].cashbook[h].cashbook_first}else if(null!=v.cashbook)for(h=0;h<v.cashbook.length&&!(new Date(v.cashbook[h].date).getTime()>t.getTime());h++)d=new Date(v.cashbook[h].date),u=v.cashbook[h].cashbook_first}d||(d=new Date(s.registrationdate));for(var g=new Array;a.length;){var x=a.splice(0,10);if("all"===n)if("all"===o||void 0===o){var q={date:{$gte:d,$lte:e},bill_type:{$in:x},payment_type:{$eq:1}},w={date:{$gte:d,$lte:e},bill_type:{$in:x},payment_type:{$eq:3}};g.push(i.vhmongo_firebase.database().getDocsByFields("bills",q,{},{date:1},0)),g.push(i.vhmongo_firebase.database().getDocsByFields("bills",w,{},{date:1},0))}else{q={date:{$gte:d,$lte:e},id_branch:{$eq:o},bill_type:{$in:x},payment_type:{$eq:1}},w={date:{$gte:d,$lte:e},id_branch:{$eq:o},bill_type:{$in:x},payment_type:{$eq:3}};g.push(i.vhmongo_firebase.database().getDocsByFields("bills",q,{},{date:1},0)),g.push(i.vhmongo_firebase.database().getDocsByFields("bills",w,{},{date:1},0))}else"all"===o||void 0===o||(c={date:{$gte:d,$lte:e},id_wallet:{$eq:n},id_branch:{$eq:o},bill_type:{$in:x}},g.push(i.vhmongo_firebase.database().getDocsByFields("bills",c,{},{date:1},0)))}Promise.all(g).then((function(e){var n=e.flat();n=i.vhAlgorithm.sortDatebyASC(n,"date");var o={docs:new Array,empty:!0,size:0,cashbook_first:u,income:0,expenditure:0,cashbook_last:0};if(n.length>0)for(var a=0;a<n.length;a++){var s=Object.assign({},n[a]);if(2!=(null==s?void 0:s.payment_type)){delete s.fee,delete s.discount,delete s.note,delete s.total,delete s.tax;var l=new Date(s.date);1===s.bill_type||7===s.bill_type||10===s.bill_type||11===s.bill_type||15===s.bill_type||34===s.bill_type?l>=t?(o.income=o.income+s.payment,s.index=o.size+1,o.docs.push(s),o.size++,o.empty=!1):o.cashbook_first=o.cashbook_first+s.payment:2!==s.bill_type&&3!==s.bill_type&&8!==s.bill_type&&12!==s.bill_type&&33!==s.bill_type||(l>=t?(o.expenditure=o.expenditure+s.payment,s.index=o.size+1,o.docs.push(s),o.size++,o.empty=!1):o.cashbook_first=o.cashbook_first-s.payment)}}o.cashbook_last=o.cashbook_first+o.income-o.expenditure,r(o)}))}))},t.prototype.getReportCashBook_old=function(t,e,n,o){var i=this;return t=new Date(t),e=new Date(e),new Promise((function(a,s){var r;r="all"===n?"all"===o||void 0===o?{date:{$lte:e}}:{date:{$lte:e},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$lte:e},id_wallet:{$eq:n}}:{date:{$lte:e},id_wallet:{$eq:n},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("bills",r,{},{date:1},0).then((function(e){var n={docs:new Array,empty:!0,size:0,cashbook_first:0,income:0,expenditure:0,cashbook_last:0};if(e.length>0)for(var o=0;o<e.length;o++){var i=Object.assign({},e[o]);if(2!=(null==i?void 0:i.payment_type)){delete i.fee,delete i.discount,delete i.note,delete i.total,delete i.tax;var s=new Date(i.date);1!==i.bill_type&&7!==i.bill_type&&10!==i.bill_type&&11!==i.bill_type&&15!==i.bill_type&&34!==i.bill_type||(s>=t?(n.income=n.income+i.payment,i.index=n.size+1,n.docs.push(i),n.size++,n.empty=!1):n.cashbook_first=n.cashbook_first+i.payment),2!==i.bill_type&&3!==i.bill_type&&8!==i.bill_type&&12!==i.bill_type&&33!==i.bill_type||(s>=t?(n.expenditure=n.expenditure+i.payment,i.index=n.size+1,n.docs.push(i),n.size++,n.empty=!1):n.cashbook_first=n.cashbook_first-i.payment)}}n.cashbook_last=n.cashbook_first+n.income-n.expenditure,a(n)}))}))},t.prototype.syncCashBook=function(t){var e=this;return new Promise((function(n,o){var i={id_branch:{$eq:t},bill_type:{$in:[1,7,10,11,15,2,3,8,12]}},a=e.getlocalWallets().filter((function(e){return e.id_branch===t||"id_cash"===e._id}));e.vhmongo_firebase.database().getDocsByFields("bills",i,{},{date:1},0).then((function(n){if(n.length>=2){for(var o=e.get1stDayOfMonthArray(n[0].date,n[n.length-1].date),i=0;i<a.length;i++)if("id_cash"===a[i]._id){a[i][t]={},a[i][t].cashbook=new Array;for(var s=0;s<o.length;s++)a[i][t].cashbook[s]={},a[i][t].cashbook[s].date=o[s],a[i][t].cashbook[s].cashbook_first=0;for(var r=0;r<n.length;r++)if(a[i]._id===n[r].id_wallet)for(s=0;s<a[i][t].cashbook.length;s++)new Date(n[r].date)<new Date(a[i][t].cashbook[s].date)&&(1===n[r].bill_type||7===n[r].bill_type||10===n[r].bill_type||11===n[r].bill_type||15===n[r].bill_type||34===n[r].bill_type?a[i][t].cashbook[s].cashbook_first=a[i][t].cashbook[s].cashbook_first+n[r].payment:2!==n[r].bill_type&&3!==n[r].bill_type&&8!==n[r].bill_type&&12!==n[r].bill_type&&33!==n[r].bill_type||(a[i][t].cashbook[s].cashbook_first=a[i][t].cashbook[s].cashbook_first-n[r].payment))}else{a[i].cashbook=new Array;for(s=0;s<o.length;s++)a[i].cashbook[s]={},a[i].cashbook[s].date=o[s],a[i].cashbook[s].cashbook_first=0;for(r=0;r<n.length;r++)if(a[i]._id===n[r].id_wallet)for(s=0;s<a[i].cashbook.length;s++)new Date(n[r].date)<new Date(a[i].cashbook[s].date)&&(1===n[r].bill_type||7===n[r].bill_type||10===n[r].bill_type||11===n[r].bill_type||15===n[r].bill_type||34===n[r].bill_type?a[i].cashbook[s].cashbook_first=a[i].cashbook[s].cashbook_first+n[r].payment:2!==n[r].bill_type&&3!==n[r].bill_type&&8!==n[r].bill_type&&12!==n[r].bill_type&&33!==n[r].bill_type||(a[i].cashbook[s].cashbook_first=a[i].cashbook[s].cashbook_first-n[r].payment))}console.log("wallets",a)}}))}))},t.prototype.syncCashBookEveryDay_Stock1stDayOfMonth=function(){var t=this;return new Promise((function(e,n){var o=t.vhAuth.getStore(),i=[Object.assign({},t.getDefaultBranch())];t.vhmongo_firebase.auth().getServerDate().then((function(n){var a=t.get1stDayOfMonthArray(o.registrationdate,n);if(a.length>0){for(var s=new Array,r=function(n){for(var o=i[n]._id,r=t.getlocalWallets().filter((function(t){return t.id_branch===o||"id_cash"===t._id})),l=new Array,c=function(n){if("id_cash"===r[n]._id)if(null!=r[n][o]&&null!=r[n][o].cashbook){var i=r[n][o].cashbook[r[n][o].cashbook.length-1];if(new Date(i.date).getTime()!=new Date(a[a.length-1]).getTime()){for(var s=r[n][o].cashbook.length;s<a.length;s++)r[n][o].cashbook[s]={},r[n][o].cashbook[s].date=a[s],r[n][o].cashbook[s].cashbook_first=i.cashbook_first;l[n]=new Promise((function(e){for(var a=[],s=[1,7,10,11,15,34,2,3,8,12,33];s.length;){var l=s.splice(0,10),c={date:{$gte:new Date(i.date)},id_branch:{$eq:o},id_wallet:{$eq:"id_cash"},bill_type:{$in:l}};a.push(t.vhmongo_firebase.database().getDocsByFields("bills",c,{},{date:1},0))}Promise.all(a).then((function(t){var i=t.flat();if(i.length>0)for(var a=0;a<i.length;a++)if("id_cash"===i[a].id_wallet)for(var s=0;s<r[n][o].cashbook.length;s++)new Date(i[a].date)<new Date(r[n][o].cashbook[s].date)&&(1===i[a].bill_type||7===i[a].bill_type||10===i[a].bill_type||11===i[a].bill_type||15===i[a].bill_type||34===i[a].bill_type?r[n][o].cashbook[s].cashbook_first=r[n][o].cashbook[s].cashbook_first+i[a].payment:2!==i[a].bill_type&&3!==i[a].bill_type&&8!==i[a].bill_type&&12!==i[a].bill_type&&33!==i[a].bill_type||(r[n][o].cashbook[s].cashbook_first=r[n][o].cashbook[s].cashbook_first-i[a].payment));e(r[n])}))}))}else e(null)}else l[n]=new Promise((function(e){for(var i=[],s=[1,7,10,11,15,34,2,3,8,12,33];s.length;){var l=s.splice(0,10),c={id_branch:{$eq:o},id_wallet:{$eq:"id_cash"},bill_type:{$in:l}};i.push(t.vhmongo_firebase.database().getDocsByFields("bills",c,{},{date:1},0))}Promise.all(i).then((function(t){var i=t.flat();r[n][o]={},r[n][o].cashbook=new Array;for(var s=0;s<a.length;s++)r[n][o].cashbook[s]={},r[n][o].cashbook[s].date=a[s],r[n][o].cashbook[s].cashbook_first=0;if(i.length>0)for(var l=0;l<i.length;l++)if("id_cash"===i[l].id_wallet)for(s=0;s<r[n][o].cashbook.length;s++)new Date(i[l].date)<new Date(r[n][o].cashbook[s].date)&&(1===i[l].bill_type||7===i[l].bill_type||10===i[l].bill_type||11===i[l].bill_type||15===i[l].bill_type||34===i[l].bill_type?r[n][o].cashbook[s].cashbook_first=r[n][o].cashbook[s].cashbook_first+i[l].payment:2!==i[l].bill_type&&3!==i[l].bill_type&&8!==i[l].bill_type&&12!==i[l].bill_type&&33!==i[l].bill_type||(r[n][o].cashbook[s].cashbook_first=r[n][o].cashbook[s].cashbook_first-i[l].payment));e(r[n])}))}));else if("id_cash"!=r[n]._id)if(null!=r[n].cashbook){var c=r[n].cashbook[r[n].cashbook.length-1];if(new Date(c.date).getTime()!=new Date(a[a.length-1]).getTime()){for(s=r[n].cashbook.length;s<a.length;s++)r[n].cashbook[s]={},r[n].cashbook[s].date=a[s],r[n].cashbook[s].cashbook_first=c.cashbook_first;l[n]=new Promise((function(e){for(var i=[],a=[1,7,10,11,15,34,2,3,8,12,33];a.length;){var s=a.splice(0,10),l={date:{$gte:new Date(c.date)},id_branch:{$eq:o},id_wallet:{$eq:r[n]._id},bill_type:{$in:s}};i.push(t.vhmongo_firebase.database().getDocsByFields("bills",l,{},{date:1},0))}Promise.all(i).then((function(t){var o=t.flat();if(o.length>0)for(var i=0;i<o.length;i++)if(o[i].id_wallet===r[n]._id)for(var a=0;a<r[n].cashbook.length;a++)new Date(o[i].date)<new Date(r[n].cashbook[a].date)&&(1===o[i].bill_type||7===o[i].bill_type||10===o[i].bill_type||11===o[i].bill_type||15===o[i].bill_type||34===o[i].bill_type?r[n].cashbook[a].cashbook_first=r[n].cashbook[a].cashbook_first+o[i].payment:2!==o[i].bill_type&&3!==o[i].bill_type&&8!==o[i].bill_type&&12!==o[i].bill_type&&33!==o[i].bill_type||(r[n].cashbook[a].cashbook_first=r[n].cashbook[a].cashbook_first-o[i].payment));e(r[n])}))}))}else e(null)}else l[n]=new Promise((function(e){for(var i=[],s=[1,7,10,11,15,34,2,3,8,12,33];s.length;){var l=s.splice(0,10),c={id_branch:{$eq:o},id_wallet:{$eq:r[n]._id},bill_type:{$in:l}};i.push(t.vhmongo_firebase.database().getDocsByFields("bills",c,{},{date:1},0))}Promise.all(i).then((function(t){var o=t.flat();r[n].cashbook=new Array;for(var i=0;i<a.length;i++)r[n].cashbook[i]={},r[n].cashbook[i].date=a[i],r[n].cashbook[i].cashbook_first=0;if(o.length>0)for(var s=0;s<o.length;s++)if(o[s].id_wallet===r[n]._id)for(i=0;i<r[n].cashbook.length;i++)new Date(o[s].date)<new Date(r[n].cashbook[i].date)&&(1===o[s].bill_type||7===o[s].bill_type||10===o[s].bill_type||11===o[s].bill_type||15===o[s].bill_type||34===o[s].bill_type?r[n].cashbook[i].cashbook_first=r[n].cashbook[i].cashbook_first+o[s].payment:2!==o[s].bill_type&&3!==o[s].bill_type&&8!==o[s].bill_type&&12!==o[s].bill_type&&33!==o[s].bill_type||(r[n].cashbook[i].cashbook_first=r[n].cashbook[i].cashbook_first-o[s].payment));e(r[n])}))}))},u=0;u<r.length;u++)c(u);s[n]=new Promise((function(e){Promise.all(l).then((function(n){for(var i=0;i<n.length;i++)if(n[i])if("id_cash"===n[i]._id){var a={};a[o]=n[i][o],t.vhmongo_firebase.database().updateDoc("wallets",n[i]._id,Object.assign({},a))}else t.vhmongo_firebase.database().updateDoc("wallets",n[i]._id,{cashbook:n[i].cashbook});e(n)}))}))},l=0;l<i.length;l++)r(l);Promise.all(s).then((function(t){console.log("syncCashBookEveryDay",t),e(null)}))}else console.log("syncCashBookEveryDay"),e(null)}),(function(t){console.log("syncCashBookEveryDay",t)}))}))},t.prototype.get1stDayOfMonthArray=function(t,e){var n=new Array;for(e=new Date(e),(t=new Date(t)).setDate(1),t.setHours(0),t.setMinutes(0),t.setSeconds(0),t.setMilliseconds(0),t.setMonth(t.getMonth()+1),e.setDate(1),e.setHours(0),e.setMinutes(0),e.setSeconds(0),e.setMilliseconds(0),e.setMonth(e.getMonth()-1);t.getTime()<=e.getTime();)n.push(new Date(t)),t.setMonth(t.getMonth()+1);return n},t.prototype.getValidityDate=function(t){var e=this;return new Promise((function(n,o){t=new Date(t),e.vhmongo_firebase.auth().getServerDate().then((function(o){(o=new Date(o)).setMonth(o.getMonth()-1),o.setDate(1),o.setHours(0),o.setMinutes(0),o.setSeconds(0),t.getTime()>o.getTime()?t.getTime()<new Date(e.vhAuth.getStore().registrationdate).getTime()?n(new Date(e.vhAuth.getStore().registrationdate)):n(null):o.getTime()<new Date(e.vhAuth.getStore().registrationdate).getTime()?n(new Date(e.vhAuth.getStore().registrationdate)):n(o)}))}))},t.prototype.getReportIncomeExpenditureDiary=function(t,e,n,o,i,a){var s=this;return new Promise((function(r,l){for(var c=[];i.length;){var u=i.splice(0,10);"all"===a||void 0===a?("all"===n&&"all"===o&&c.push(s.vhmongo_firebase.database().getDocsByFields("bills",{date:{$gte:t,$lte:e},bill_type:{$in:u}},{},{date:1},0)),"all"===n&&"all"!=o&&c.push(s.vhmongo_firebase.database().getDocsByFields("bills",{date:{$gte:t,$lte:e},id_employee:{$eq:o},bill_type:{$in:u}},{},{date:1},0)),"all"!=n&&"all"===o&&c.push(s.vhmongo_firebase.database().getDocsByFields("bills",{date:{$gte:t,$lte:e},id_wallet:{$eq:n},bill_type:{$in:u}},{},{date:1},0)),"all"!=n&&"all"!=o&&c.push(s.vhmongo_firebase.database().getDocsByFields("bills",{date:{$gte:t,$lte:e},id_wallet:{$eq:n},id_employee:{$eq:o},bill_type:{$in:u}},{},{date:1},0))):("all"===n&&"all"===o&&c.push(s.vhmongo_firebase.database().getDocsByFields("bills",{date:{$gte:t,$lte:e},bill_type:{$in:u},id_branch:{$eq:a}},{},{date:1},0)),"all"===n&&"all"!=o&&c.push(s.vhmongo_firebase.database().getDocsByFields("bills",{date:{$gte:t,$lte:e},id_employee:{$eq:o},bill_type:{$in:u},id_branch:{$eq:a}},{},{date:1},0)),"all"!=n&&"all"===o&&c.push(s.vhmongo_firebase.database().getDocsByFields("bills",{date:{$gte:t,$lte:e},id_wallet:{$eq:n},bill_type:{$in:u},id_branch:{$eq:a}},{},{date:1},0)),"all"!=n&&"all"!=o&&c.push(s.vhmongo_firebase.database().getDocsByFields("bills",{date:{$gte:t,$lte:e},id_wallet:{$eq:n},id_employee:{$eq:o},bill_type:{$in:u},id_branch:{$eq:a}},{},{date:1},0)))}Promise.all(c).then((function(t){var e=t.flat(),n={docs:new Array,empty:!0,size:0,income:0,expenditure:0};if(e.length>0)for(var o=0;o<e.length;o++){var i=Object.assign({},e[o]);2!=(null==i?void 0:i.payment_type)&&(1!==i.bill_type&&7!==i.bill_type&&10!==i.bill_type&&11!==i.bill_type&&15!==i.bill_type&&34!==i.bill_type||(n.income=n.income+i.payment,n.docs.push(i),n.size++,n.empty=!1),2!==i.bill_type&&3!==i.bill_type&&8!==i.bill_type&&12!==i.bill_type&&33!==i.bill_type||(n.expenditure=n.expenditure+i.payment,n.docs.push(i),n.size++,n.empty=!1))}console.log("json",n),r(n)}))}))},t.prototype.getDebtSuppliers=function(t,e,n,o){var i=this;t=new Date(t),e=new Date(e);var a=this.vhAuth.getStore();return new Promise((function(s,r){var l=new Array;if("all"===n)l=i.vhAlgorithm.sortVietnamesebyASC(i.getlocalSuppliers(),"name");else{var c=i.getlocalSupplier(n);l.push(c)}var u,d=i.getlocalBranchs(),_=i.getDefaultBranch()._id,p=null,b=null;if(null!=l[0][_]&&null!=l[0][_].debt)for(var f=0;f<l[0][_].debt.length&&!(new Date(l[0][_].debt[f].date).getTime()>t.getTime());f++)b=new Date(l[0][_].debt[f].date),p=f;b||(b=new Date(a.registrationdate)),u="all"===n?"all"===o||void 0===o?{date:{$gte:b,$lte:e},bill_type:{$in:[2,10,12]}}:{date:{$gte:b,$lte:e},bill_type:{$in:[2,10,12]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$gte:b,$lte:e},id_supplier:{$eq:n},bill_type:{$in:[2,10,12]}}:{date:{$gte:b,$lte:e},id_supplier:{$eq:n},bill_type:{$in:[2,10,12]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("bills",u,{},{date:1},0).then((function(e){for(var n,i,a={docs:new Array,debt_beginning:0,payment:0,debt:0,rest:0},r=0;r<l.length;r++){var c={_id:l[r]._id,name:l[r].name};a.docs.push(c);for(var u=0,_=0,b=0,f=0,h=0;h<e.length;h++)e[h].id_supplier===l[r]._id&&(new Date(e[h].date).getTime()>=t.getTime()?2===e[h].bill_type?(u+=e[h].total*(1+e[h].tax/100),_+=e[h].payment):12===e[h].bill_type?_+=e[h].payment:10===e[h].bill_type&&(_+=e[h].total*(1+e[h].tax/100),u+=e[h].payment):2===e[h].bill_type?f=f+e[h].total*(1+e[h].tax/100)-e[h].payment:10===e[h].bill_type?f=f+e[h].payment-e[h].total*(1+e[h].tax/100):12===e[h].bill_type&&(f-=e[h].payment));if("all"===o||void 0===o)for(h=0;h<d.length;h++)null!=l[r][d[h]._id]&&null!=l[r][d[h]._id].debt_beginning&&(b+=l[r][d[h]._id].debt_beginning);else null!=l[r][o]&&null!=l[r][o].debt_beginning&&(b=l[r][o].debt_beginning),null!=l[r][o]&&null!=l[r][o].debt&&(p||null!=l[r][o].debt[p]&&(f+=l[r][o].debt[p].debt_first));u=b+f+u,a.docs[a.docs.length-1].index=a.docs.length,a.docs[a.docs.length-1].debt=u,a.docs[a.docs.length-1].payment=_,a.docs[a.docs.length-1].rest=u-_,a.debt_beginning=a.debt_beginning+b,a.debt=a.debt+u,a.payment=a.payment+_,a.rest=a.rest+u-_;var y={docs:new Array,empty:!0,size:0,debt_beginning:b+f,debt:b+f,payment:0,rest:b+f};for(h=0;h<e.length;h++)if(l[r]._id===e[h].id_supplier&&new Date(e[h].date).getTime()>=t.getTime()){var m=Object.assign({},e[h]);null==m||delete m.discount,null==m||delete m.fee,null==m||delete m.id_supplier,null==m||delete m.note,null==m||delete m.payment_type,null==m||delete m.tax,y.docs.push(m),y.docs[y.docs.length-1].debt=0,y.docs[y.docs.length-1].payment=0,2===e[h].bill_type?(y.docs[y.docs.length-1].debt=e[h].total*(1+(null===(n=e[h])||void 0===n?void 0:n.tax)/100),y.docs[y.docs.length-1].payment=e[h].payment,y.docs[y.docs.length-1].rest=y.docs[y.docs.length-1].debt-y.docs[y.docs.length-1].payment):10===e[h].bill_type?(y.docs[y.docs.length-1].payment=e[h].total*(1+(null===(i=e[h])||void 0===i?void 0:i.tax)/100),y.docs[y.docs.length-1].debt=e[h].payment,y.docs[y.docs.length-1].rest=y.docs[y.docs.length-1].debt-y.docs[y.docs.length-1].payment):12===e[h].bill_type&&(y.docs[y.docs.length-1].payment=e[h].payment,y.docs[y.docs.length-1].rest=-e[h].payment),y.debt=y.debt+y.docs[y.docs.length-1].debt,y.payment=y.payment+y.docs[y.docs.length-1].payment,y.rest=y.rest+y.docs[y.docs.length-1].debt-y.docs[y.docs.length-1].payment,y.size++,y.empty=!1,y.docs[y.docs.length-1].index=y.docs.length}a.docs[a.docs.length-1].json=y}console.log("json",a),s(a)}))}))},t.prototype.getDebtCustomers=function(t,e,n,o){var i=this;return new Promise((function(a,s){var r=i.vhAuth.getStore(),l=new Array;if("all"===n)l=i.vhAlgorithm.sortVietnamesebyASC(i.getlocalCustomers().filter((function(t){return"id_retail"!=t._id})),"name");else{var c=i.getlocalCustomer(n);l.push(c)}var u,d=i.getlocalBranchs(),_=i.getDefaultBranch()._id,p=null,b=null;if(null!=l[0][_]&&null!=l[0][_].debt)for(var f=0;f<l[0][_].debt.length&&!(new Date(l[0][_].debt[f].date).getTime()>t.getTime());f++)b=new Date(l[0][_].debt[f].date),p=f;b||(b=new Date(r.registrationdate)),u="all"===n?"all"===o||void 0===o?{date:{$gte:b,$lte:e},bill_type:{$in:[1,3,11,15]}}:{date:{$gte:b,$lte:e},bill_type:{$in:[1,3,11,15]},id_branch:{$eq:o}}:"all"===o||void 0===o?{date:{$gte:b,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1,3,11,15]}}:{date:{$gte:b,$lte:e},id_customer:{$eq:n},bill_type:{$in:[1,3,11,15]},id_branch:{$eq:o}},i.vhmongo_firebase.database().getDocsByFields("bills",u,{},{date:1},0).then((function(e){for(var n,i,s={docs:new Array,debt_beginning:0,payment:0,debt:0,rest:0},r=0;r<l.length;r++){var c={_id:l[r]._id,name:l[r].name};s.docs.push(c);for(var u=0,_=0,b=0,f=0,h=0;h<e.length;h++)e[h].id_customer===l[r]._id&&(new Date(e[h].date).getTime()>=t.getTime()?1===e[h].bill_type||15===e[h].bill_type?(u+=e[h].total*(1+e[h].tax/100),_+=e[h].payment):11===e[h].bill_type?_+=e[h].payment:3===e[h].bill_type&&(_+=e[h].total*(1+e[h].tax/100),u+=e[h].payment):1===e[h].bill_type||15===e[h].bill_type?f=f+e[h].total*(1+e[h].tax/100)-e[h].payment:11===e[h].bill_type?f-=e[h].payment:3===e[h].bill_type&&(f=f+e[h].payment-e[h].total*(1+e[h].tax/100)));if("all"===o||void 0===o)for(h=0;h<d.length;h++)null!=l[r][d[h]._id]&&null!=l[r][d[h]._id].debt_beginning&&(b+=l[r][d[h]._id].debt_beginning);else null!=l[r][o]&&null!=l[r][o].debt_beginning&&(b=l[r][o].debt_beginning),null!=l[r][o]&&null!=l[r][o].debt&&(p||null!=l[r][o].debt[p]&&(f+=l[r][o].debt[p].debt_first));u=b+f+u,s.docs[s.docs.length-1].index=s.docs.length,s.docs[s.docs.length-1].debt=u,s.docs[s.docs.length-1].payment=_,s.docs[s.docs.length-1].rest=u-_,s.debt_beginning=s.debt_beginning+b,s.debt=s.debt+u,s.payment=s.payment+_,s.rest=s.rest+u-_;var y={docs:new Array,empty:!0,size:0,debt_beginning:b+f,debt:b+f,payment:0,rest:b+f};for(h=0;h<e.length;h++)if(l[r]._id===e[h].id_customer&&new Date(e[h].date).getTime()>=t.getTime()){var m=Object.assign({},e[h]);null==m||delete m.discount,null==m||delete m.fee,null==m||delete m.id_customer,null==m||delete m.note,null==m||delete m.payment_type,null==m||delete m.tax,y.docs.push(m),y.docs[y.docs.length-1].debt=0,y.docs[y.docs.length-1].payment=0,1===e[h].bill_type||15===e[h].bill_type?(y.docs[y.docs.length-1].debt=e[h].total*(1+(null===(n=e[h])||void 0===n?void 0:n.tax)/100),y.docs[y.docs.length-1].payment=e[h].payment,y.docs[y.docs.length-1].rest=y.docs[y.docs.length-1].debt-y.docs[y.docs.length-1].payment):3===e[h].bill_type?(y.docs[y.docs.length-1].payment=e[h].total*(1+(null===(i=e[h])||void 0===i?void 0:i.tax)/100),y.docs[y.docs.length-1].debt=e[h].payment,y.docs[y.docs.length-1].rest=y.docs[y.docs.length-1].debt-y.docs[y.docs.length-1].payment):11===e[h].bill_type&&(y.docs[y.docs.length-1].payment=e[h].payment,y.docs[y.docs.length-1].rest=-e[h].payment),y.debt=y.debt+y.docs[y.docs.length-1].debt,y.payment=y.payment+y.docs[y.docs.length-1].payment,y.rest=y.rest+y.docs[y.docs.length-1].debt-y.docs[y.docs.length-1].payment,y.size++,y.empty=!1,y.docs[y.docs.length-1].index=y.docs.length}s.docs[s.docs.length-1].json=y}console.log("json",s),a(s)}))}))},t.prototype.getReportInventoryTime_byTimes=function(t){var e=this;return new Promise((function(n,o){var i=e.getlocalInventorytime(t),a=e.vhAlgorithm.sortVietnamesebyASC(e.getlocalProducts(1),"name"),s=e.getDefaultBranch()._id,r={docs:new Array,empty:!0,size:0};if(a.length>0){r={docs:new Array,empty:!0,size:0,total_stock:0,total_realstock:0,total_inventorynotes:new Array};var l=new Array,c=new Array,u=new Array,d=new Array,_={date:{$gte:new Date(a[0][s].inventory[a[0][s].inventory.length-1].date),$lte:new Date(i.date)},bill_type:{$in:[1,10,15,30,2,3,9,31]},id_branch:{$eq:s}};d[0]=new Promise((function(t,n){e.vhmongo_firebase.database().getDocsByFields("vhbill_details",_,{},{date:1},0).then((function(e){l=E(e),t(null)}))}));var p={id_inventorytime:{$eq:t},bill_type:{$in:[13]}};d[1]=new Promise((function(t,n){e.vhmongo_firebase.database().getDocsByFields("vhbill_details",p,{},{date:1},0).then((function(e){c=E(e),t(null)}))}));var b={id_inventorytime:{$eq:t},bill_type:{$in:[13]}};d[2]=new Promise((function(t,n){e.vhmongo_firebase.database().getDocsByFields("bills",b,{},{date:1},0).then((function(e){u=E(e),t(null)}))})),Promise.all(d).then((function(){for(var t=0,e=0,o=new Array,i=0;i<u.length;i++){var d={bill_code:u[i].bill_code,quantity:0};o.push(d)}for(var _=function(n){if(c.filter((function(t){return t.id_product===a[n]._id})).length>0){for(var i=a[n][s].inventory[a[n][s].inventory.length-1].stock_first,d=0;d<l.length;d++)if(1===l[d].ptype){if(l[d].id_product===a[n]._id){new Date(l[d].date);1===l[d].bill_type||10===l[d].bill_type||15===l[d].bill_type||30===l[d].bill_type?i-=l[d].quantity:2!==l[d].bill_type&&3!==l[d].bill_type&&31!==l[d].bill_type||(i+=l[d].quantity)}}else if(5===l[d].ptype)for(var _=0;_<l[d].combos.length;_++)l[d].combos[_].id_product===a[n]._id&&(i+=l[d].combos[_].quantity*l[d].quantity);var p=new Array,b=0;for(d=0;d<u.length;d++){var f={bill_code:u[d].bill_code,quantity:0};p.push(f)}for(d=0;d<c.length;d++)for(var h=0;h<p.length;h++)a[n]._id===c[d].id_product&&p[h].bill_code===c[d].bill_code&&(p[h].quantity=c[d].quantity,b+=c[d].quantity,o[h].quantity=o[h].quantity+c[d].quantity);t+=i,e+=b;var y={_id:a[n]._id,data:function(){var t=a[n];return delete a[n]._id,t},stock:i,realstock:b,inventorynotes:p};r.docs.push(y),r.empty=!1,r.size++}},p=0;p<a.length;p++)_(p);r.total_stock=t,r.total_realstock=e,r.total_inventorynotes=E(o),console.log("getReportInventoryTime_byTimes",r),n(r)}))}}))},t.prototype.getReportProducts_by3Time=function(t,e){var n=this;return new Promise((function(o,i){var a=n.getlocalProducts(),s={docs:new Array,empty:!0,size:0};a.length>0?(s={docs:new Array,empty:!0,size:0,outstock:0,instock:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0,profit_btax:0,profit_atax:0},n.vhmongo_firebase.database().getDocsByFields("vhbill_details",{bill_type:{$in:[1,10,15,2,3,9]}},{},{date:1},0).then((function(n){for(var i=function(o){for(var i=Object.assign({},a[o]),r={id:i._id,data:function(){return delete i._id,i},outstock:0,instock:0,revenue_btax:0,revenue_atax:0,cost_btax:0,cost_atax:0,profit_btax:0,profit_atax:0,stock_first:0,stock_last:0,cost_stock_first_btax:0,cost_stock_first_atax:0,cost_stock_last_btax:0,cost_stock_last_atax:0},l=0,c=0,u=0,d=0,_=0;_<n.length;_++)if(n[_].id_product===a[o]._id&&n[_].date<=e){var p=n[_].date;1===n[_].bill_type||10===n[_].bill_type||15===n[_].bill_type?p>=t?(r.outstock=r.outstock+n[_].quantity,r.revenue_btax=r.revenue_btax+n[_].price,r.revenue_atax=r.revenue_atax+n[_].price*(1+n[_].tax/100)):(l+=n[_].quantity,n[_].price,n[_].price*(1+n[_].tax/100)):2!==n[_].bill_type&&3!==n[_].bill_type&&9!==n[_].bill_type||(p>=t?(r.instock=r.instock+n[_].quantity,r.cost_btax=r.cost_btax+n[_].price,r.cost_atax=r.cost_atax+n[_].price*(1+n[_].tax/100)):(c+=n[_].quantity,d+=n[_].price,u+=n[_].price*(1+n[_].tax/100)))}r.stock_first=c-l,r.stock_last=r.stock_first+r.instock-r.outstock,r.cost_stock_first_btax=r.stock_first*u/c,0!=c&&(r.cost_stock_first_atax=r.stock_first*r.cost_atax_0/c),c+r.instock!=0&&(r.cost_stock_last_btax=r.stock_last*(u+r.cost_btax)/(c+r.instock)),c+r.instock!=0&&(r.cost_stock_last_atax=r.stock_last*(r.cost_atax_0+r.cost_atax)/(c+r.instock)),l+r.outstock!=0&&c+r.instock!=0&&(r.profit_btax=r.outstock*((r.revenue_btax_0+r.revenue_btax)/(l+r.outstock)-(u+r.cost_btax)/(c+r.instock))),l+r.outstock!=0&&c+r.instock!=0&&(r.profit_atax=r.outstock*((r.revenue_atax_0+r.revenue_atax)/(l+r.outstock)-(d+r.cost_btax)/(c+r.instock))),s.outstock=s.outstock+r.outstock,s.revenue_btax=s.revenue_btax+r.revenue_btax,s.revenue_atax=s.revenue_atax+r.revenue_atax,s.instock=s.instock+r.instock,s.cost_btax=s.cost_btax+r.cost_btax,s.cost_atax=s.cost_atax+r.cost_atax,s.profit_btax=s.profit_btax+r.profit_btax,s.profit_atax=s.profit_atax+r.profit_atax,s.docs.push(r),s.size++,s.empty=!1},r=0;r<a.length;r++)i(r);o(s)}))):(console.log("server -> products khong ton tai trong CSDL: "),o(s))}))},t.prototype.getReportProduct_byID=function(t,e,n){var o=this;return new Promise((function(i,a){var s={docs:new Array,empty:!0,size:0},r={date:{$gte:t,$lte:e},id_product:{$eq:n},bill_type:{$in:[1,2,3,9,10,15]}};o.vhmongo_firebase.database().getDocsByFields("vhbill_details",r,{},{date:1},0).then((function(t){if(t.length>0)for(var e=function(e){var n={_id:t[e]._id,data:function(){var n=Object.assign({},t[e]);return n.date&&delete n.date,"number"==typeof n.tax&&delete n.tax,"number"==typeof n.bill_type&&delete n.bill_type,n.id_cashier&&delete n.id_cashier,n.id_employee&&delete n.id_employee,n.id_supplier&&delete n.id_supplier,n.id_customer&&delete n.id_customer,n},bill_type:t[e].bill_type,tax:t[e].tax,date:t[e].date};s.docs.push(n),s.size++,s.empty=!1},n=0;n<t.length;n++)e(n);i(s)}))}))},t.prototype.addEarningPointsBill=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("earning_points_bills",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateEarningPointsBill=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("earning_points_bills",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteEarningPointsBill=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("earning_points_bills",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getEarningPointsBill=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("earning_points_bills",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getEarningPointsBills=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("earning_points_bills").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.addEarningPointsProduct=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("earning_points_products",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateEarningPointsProduct=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("earning_points_products",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteEarningPointsProduct=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("earning_points_products",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getEarningPointsProduct=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("earning_points_products",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getEarningPointsProducts=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("earning_points_products").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.addEmployeeClass=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("employee_classs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateEmployeeClass=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("employee_classs",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteEmployeeClass=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("employee_classs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getEmployeeClass=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("employee_classs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getEmployeeClasss=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("employee_classs").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.getlocalEmployeeClasss=function(){},t.prototype.getlocalEmployeeClass=function(t){},t.prototype.addCoupon=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("coupons",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateCoupon=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("coupons",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteCoupon=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("coupons",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getCoupon=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("coupons",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getCoupons=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("coupons").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.addCouponRelease=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("coupon_releases",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateCouponRelease=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("coupon_releases",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteCouponRelease=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("coupon_releases",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getCouponRelease=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("coupon_releases",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getCouponReleases=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("coupon_releases").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.addCouponReleaseDetail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("coupon_release_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.deleteCouponReleaseDetail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("coupon_release_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getCouponReleaseDetail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("coupon_release_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getCouponRelaseDetail_byIdCouponRelease=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("coupon_release_details",{id_coupon_release:{$eq:t}},{}).then((function(t){n(t)})).catch((function(t){o(t)}))}))},t.prototype.createCouponCode=function(t){var e=this;return new Promise((function(n,o){var i=e.vhAlgorithm.createCardCode();e.vhmongo_firebase.database().getDoc("coupon_codes",i).then((function(a){a?(i=e.vhAlgorithm.createCardCode(),e.vhmongo_firebase.database().addDocbyID("coupon_codes",i,t).then((function(t){n(t)}),(function(t){o(t)}))):e.vhmongo_firebase.database().addDocbyID("coupon_codes",i,t).then((function(t){n(t)}),(function(t){o(t)}))}),(function(t){o(t)}))}))},t.prototype.createCouponCodes=function(t,e){var n=this;return new Promise((function(o,i){for(var a=new Array,s=0;s<e;s++)a[s]=n.createCouponCode(t);Promise.all(a).then((function(a){a=a.flat(),n.vhmongo_firebase.database().getDoc("coupon_release_details",t.id_coupon_release_detail).then((function(t){if(t)if(null!=t.quantity_released){var s={quantity_released:t.quantity_released+e};n.vhmongo_firebase.database().updateDoc("coupon_release_details",t._id,s).then((function(){o(a)}),(function(t){i(t)}))}else{s={quantity_released:e};n.vhmongo_firebase.database().updateDoc("coupon_release_details",t._id,s).then((function(){o(a)}),(function(t){i(t)}))}}),(function(t){i(t)}))})).catch((function(t){i(t)}))}))},t.prototype.updateCouponCode=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("coupon_codes",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteCouponCode=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().deleteDoc("coupon_codes",t).then((function(t){t?n.vhmongo_firebase.database().getDoc("coupon_release_details",e).then((function(t){if(t)if(null!=t.quantity_released){var e={quantity_released:t.quantity_released-1};n.vhmongo_firebase.database().updateDoc("coupon_release_details",t._id,e).then((function(){o(!0)}),(function(t){i(t)}))}else{e={quantity_released:0};n.vhmongo_firebase.database().updateDoc("coupon_release_details",t._id,e).then((function(){console.log("Báo anh Huy kiểm tra lại trường hợp này"),o(!0)}),(function(t){i(t)}))}}),(function(t){i(t)})):o(!1)}),(function(t){i(t)}))}))},t.prototype.getCouponCodes_byIdCouponReleaseDetail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("coupon_codes",{id_coupon_release_detail:{$eq:t}},{}).then((function(t){n(t)})).catch((function(t){o(t)}))}))},t.prototype.getCouponCodes_byFields=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.database().getDocsByFields("coupon_codes",t,{},n,o).then((function(t){e(t)})).catch((function(t){a(t)}))}))},t.prototype.getCouponCode=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("coupon_codes",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getCoupon_Code_Name_Release=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("coupon_codes",t).then((function(t){if(t){var i=JSON.parse(JSON.stringify(t));e.vhmongo_firebase.database().getDoc("coupon_release_details",t.id_coupon_release_detail).then((function(t){t?Promise.all([e.vhmongo_firebase.database().getDoc("coupons",t.id_coupon),e.vhmongo_firebase.database().getDoc("coupon_releases",t.id_coupon_release)]).then((function(t){i.name_coupon=t[0].name,i.name_coupon_release=t[1].name,n(i)})):n(null)}),(function(t){o(t)}))}else n(null)}),(function(t){o(t)}))}))},t.prototype.exchangeCouponCode_byEarningPoints=function(t,e,n){var o=this;return new Promise((function(i,a){for(var s=new Array,r=0;r<t.length;r++)s[r]=o.vhmongo_firebase.database().getDoc("coupon_codes",t[r]);s[s.length]=o.vhmongo_firebase.database().getDoc("customers",e),Promise.all(s).then((function(t){for(var a=new Array,s=0;s<t.length-1;s++){var r={status:3,id_customer:e,date_points_exchanged:new Date};a[s]=o.vhmongo_firebase.database().updateDoc("coupon_codes",t[s]._id,r)}var l=t[t.length-1];null!=l.earned_points?l.earned_points=l.earned_points-n:l.earned_points=0;var c=o.getDefaultBranch();null!=l.branch_earned_points?null!=l.branch_earned_points[c._id]?l.branch_earned_points[c._id]=l.branch_earned_points[c._id]-n:l.branch_earned_points[c._id]=0:l.branch_earned_points={};var u={earned_points:l.earned_points,branch_earned_points:l.branch_earned_points};a[a.length]=o.vhmongo_firebase.database().updateDoc("customers",l._id,u),Promise.all(a).then((function(){i(!0)}))}))}))},t.prototype.addVoucher=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("vouchers",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateVoucher=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("vouchers",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteVoucher=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("vouchers",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getVoucher=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("vouchers",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getVouchers=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("vouchers").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.addVoucherRelease=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("voucher_releases",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateVoucherRelease=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("voucher_releases",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteVoucherRelease=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("voucher_releases",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getVoucherRelease=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("voucher_releases",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getVoucherRelases=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("voucher_releases").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.addVoucherReleaseDetail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("voucher_release_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.deleteVoucherReleaseDetail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("voucher_release_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getVoucherReleaseDetail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("voucher_release_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getVoucherRelaseDetail_byFields=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.database().getDocsByFields("voucher_release_details",t,{},n,o).then((function(t){e(t)}),(function(t){a(t)}))}))},t.prototype.createVoucherCode=function(t){var e=this;return new Promise((function(n,o){var i=e.vhAlgorithm.createCardCode();e.vhmongo_firebase.database().getDoc("voucher_codes",i).then((function(a){a?(i=e.vhAlgorithm.createCardCode(),e.vhmongo_firebase.database().addDocbyID("voucher_codes",i,t).then((function(t){n(t)}),(function(t){o(t)}))):e.vhmongo_firebase.database().addDocbyID("voucher_codes",i,t).then((function(t){n(t)}),(function(t){o(t)}))}),(function(t){o(t)}))}))},t.prototype.createVoucherCodes=function(t,e){var n=this;return new Promise((function(o,i){for(var a=new Array,s=0;s<e;s++)a[s]=n.createVoucherCode(t);Promise.all(a).then((function(a){a=a.flat(),n.vhmongo_firebase.database().getDoc("voucher_release_details",t.id_voucher_release_detail).then((function(t){if(t)if(null!=t.quantity_released){var s={quantity_released:t.quantity_released+e};n.vhmongo_firebase.database().updateDoc("voucher_release_details",t._id,s).then((function(){o(a)}),(function(t){i(t)}))}else{s={quantity_released:e};n.vhmongo_firebase.database().updateDoc("voucher_release_details",t._id,s).then((function(){o(a)}),(function(t){i(t)}))}}),(function(t){i(t)}))})).catch((function(t){i(t)}))}))},t.prototype.updateVoucherCode=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("voucher_codes",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteVoucherCode=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().deleteDoc("voucher_codes",t).then((function(t){t?n.vhmongo_firebase.database().getDoc("voucher_release_details",e).then((function(t){if(t)if(null!=t.quantity_released){var e={quantity_released:t.quantity_released-1};n.vhmongo_firebase.database().updateDoc("voucher_release_details",t._id,e).then((function(){o(!0)}),(function(t){i(t)}))}else{e={quantity_released:0};n.vhmongo_firebase.database().updateDoc("voucher_release_details",t._id,e).then((function(){console.log("Báo anh Huy kiểm tra lại trường hợp này"),o(!0)}),(function(t){i(t)}))}}),(function(t){i(t)})):o(!1)}),(function(t){i(t)}))}))},t.prototype.getVoucherCodes_byIdCouponReleaseDetail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("voucher_codes",{id_voucher_release_detail:{$eq:t}},{}).then((function(t){n(t)})).catch((function(t){o(t)}))}))},t.prototype.getVoucherCodes_byFields=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.database().getDocsByFields("voucher_codes",t,{},n,o).then((function(t){e(t)})).catch((function(t){a(t)}))}))},t.prototype.getVoucherCode=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("voucher_codes",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getVoucher_Code_Name_Release=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("voucher_codes",t).then((function(t){if(t){var i=JSON.parse(JSON.stringify(t));e.vhmongo_firebase.database().getDoc("voucher_release_details",t.id_voucher_release_detail).then((function(t){t?Promise.all([e.vhmongo_firebase.database().getDoc("vouchers",t.id_voucher),e.vhmongo_firebase.database().getDoc("voucher_releases",t.id_voucher_release)]).then((function(t){i.name_voucher=t[0].name,i.name_voucher_release=t[1].name,n(i)})):n(null)}),(function(t){o(t)}))}else n(null)}),(function(t){o(t)}))}))},t.prototype.exchangeVoucherCode_byEarningPoints=function(t,e,n){var o=this;return new Promise((function(i,a){for(var s=new Array,r=0;r<t.length;r++)s[r]=o.vhmongo_firebase.database().getDoc("voucher_codes",t[r]);s[s.length]=o.vhmongo_firebase.database().getDoc("customers",e),Promise.all(s).then((function(t){for(var a=new Array,s=0;s<t.length-1;s++){var r={status:3,id_customer:e,date_points_exchanged:new Date};a[s]=o.vhmongo_firebase.database().updateDoc("voucher_codes",t[s]._id,r)}var l=t[t.length-1];null!=l.earned_points?l.earned_points=l.earned_points-n:l.earned_points=0;var c=o.getDefaultBranch();null!=l.branch_earned_points?null!=l.branch_earned_points[c._id]?l.branch_earned_points[c._id]=l.branch_earned_points[c._id]-n:l.branch_earned_points[c._id]=0:l.branch_earned_points={};var u={earned_points:l.earned_points,branch_earned_points:l.branch_earned_points};a[a.length]=o.vhmongo_firebase.database().updateDoc("customers",l._id,u),Promise.all(a).then((function(){i(!0)}))}))}))},t.prototype.addPaymentCard=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("payment_cards",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updatePaymentCard=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("payment_cards",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deletePaymentCard=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("payment_cards",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPaymentCard=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("payment_cards",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPaymentCards=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("payment_cards").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.addPaymentCardRelease=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("payment_card_releases",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updatePaymentCardRelease=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("payment_card_releases",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deletePaymentCardRelease=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("payment_card_releases",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPaymentCardRelease=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("payment_card_releases",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPaymentCardReleases=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("payment_card_releases").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.addPaymentCardReleaseDetail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("payment_card_release_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.deletePaymentCardReleaseDetail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("payment_card_release_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPaymentCardReleaseDetail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("payment_card_release_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPaymentCardRelaseDetail_byFields=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.database().getDocsByFields("payment_card_release_details",t,{},n,o).then((function(t){e(t)}),(function(t){a(t)}))}))},t.prototype.createPaymentCardCode=function(t){var e=this;return new Promise((function(n,o){var i=e.vhAlgorithm.createCardCode();e.vhmongo_firebase.database().getDoc("payment_card_codes",i).then((function(a){a?(i=e.vhAlgorithm.createCardCode(),e.vhmongo_firebase.database().addDocbyID("payment_card_codes",i,t).then((function(t){n(t)}),(function(t){o(t)}))):e.vhmongo_firebase.database().addDocbyID("payment_card_codes",i,t).then((function(t){n(t)}),(function(t){o(t)}))}),(function(t){o(t)}))}))},t.prototype.createPaymentCardCodes=function(t,e){var n=this;return new Promise((function(o,i){for(var a=new Array,s=0;s<e;s++)a[s]=n.createPaymentCardCode(t);Promise.all(a).then((function(a){a=a.flat(),n.vhmongo_firebase.database().getDoc("payment_card_release_details",t.id_payment_card_release_detail).then((function(t){if(t)if(null!=t.quantity_released){var s={quantity_released:t.quantity_released+e};n.vhmongo_firebase.database().updateDoc("payment_card_release_details",t._id,s).then((function(){o(a)}),(function(t){i(t)}))}else{s={quantity_released:e};n.vhmongo_firebase.database().updateDoc("payment_card_release_details",t._id,s).then((function(){o(a)}),(function(t){i(t)}))}}),(function(t){i(t)}))})).catch((function(t){i(t)}))}))},t.prototype.updatePaymentCardCode=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("payment_card_codes",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deletePaymentCardCode=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().deleteDoc("payment_card_codes",t).then((function(t){t?n.vhmongo_firebase.database().getDoc("payment_card_release_details",e).then((function(t){if(t)if(null!=t.quantity_released){var e={quantity_released:t.quantity_released-1};n.vhmongo_firebase.database().updateDoc("payment_card_release_details",t._id,e).then((function(){o(!0)}),(function(t){i(t)}))}else{e={quantity_released:0};n.vhmongo_firebase.database().updateDoc("payment_card_release_details",t._id,e).then((function(){console.log("Báo anh Huy kiểm tra lại trường hợp này"),o(!0)}),(function(t){i(t)}))}}),(function(t){i(t)})):o(!1)}),(function(t){i(t)}))}))},t.prototype.getPaymentCardCodes_byIdPaymentCardReleaseDetail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("payment_card_codes",{id_payment_card_release_detail:{$eq:t}},{}).then((function(t){n(t)})).catch((function(t){o(t)}))}))},t.prototype.getPaymentCardCodes_byFields=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.database().getDocsByFields("payment_card_codes",t,{},n,o).then((function(t){e(t)})).catch((function(t){a(t)}))}))},t.prototype.getPaymentCardCode=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("payment_card_codes",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPaymentCard_Code_Name_Release=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("payment_cards",t).then((function(t){if(t){var i=JSON.parse(JSON.stringify(t));e.vhmongo_firebase.database().getDoc("payment_card_release_details",t.id_payment_card_release_detail).then((function(t){t?Promise.all([e.vhmongo_firebase.database().getDoc("payment_cards",t.id_payment_card),e.vhmongo_firebase.database().getDoc("payment_card_releases",t.id_payment_card_release)]).then((function(t){i.name_payment_card=t[0].name,i.name_payment_card_release=t[1].name,n(i)})):n(null)}),(function(t){o(t)}))}else n(null)}),(function(t){o(t)}))}))},t.prototype.updateComboPaymentCard=function(t,e,n){},t}();Y.decorators=[{type:e.Injectable}],Y.ctorParameters=function(){return[{type:o.Vhmongo_firebase},{type:V},{type:F},{type:L},{type:u.InAppPurchase2},{type:d.Platform}]};var Z=function(){function t(t,e,n,o){var i=this;this.vhmongo_firebase=t,this.vhQuery=e,this.vhAuth=n,this.vhAlgorithm=o,this.cloudcams=new Array,this.mainboards=new Array,this.functions=new Array,this.components=new Array,this.icons=new Array,this.zones=new Array,this.appsettingstations=new Array,this.scripts=new Array,this.script_details=new Array,this.logs=new Array,this.hwinfo={},r.Device.getId().then((function(t){var e=i.vhAuth.localStorageGET("hwinfo");null!=e&&null!=e?i.hwinfo=e:(i.hwinfo=Object.assign({},t),i.vhAuth.localStorageSET("hwinfo",i.hwinfo))}))}return t.prototype.startLocalStorage=function(){var t=this;return new Promise((function(e){t.getEUtokenfromDatabase().then((function(){var n=new Array;n[0]=t.vhAuth.refreshLocalMyPermission(),n[1]=t.refreshLocalComponents(),n[2]=t.refreshLocalFunctions(),n[3]=t.refreshLocalIcons(),n[4]=t.refreshLocalMainboards(),n[5]=t.refreshLocalZones(),n[6]=t.refreshLocalCloudCams(),Promise.all(n).then((function(){e(null)}))}))}))},t.prototype.getEUtokenfromDatabase=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.f3rdclouds().getEUtokenfromDatabase().then((function(){e(null)}))}))},t.prototype.getPlaybackListCamByEndUser=function(t,e,n,o){var i=this;return new Promise((function(a,s){i.vhmongo_firebase.f3rdclouds().getPlaybackListCambyEndUser(t,e,n,o).then((function(t){0===t.vcode?a(t.data):(console.log(t),a([]))}),(function(t){s(t)}))}))},t.prototype.getlocalCloudCam=function(t){for(var e=0;e<this.cloudcams.length;e++)if(this.cloudcams[e].licensecam===t)return Object.assign({},this.cloudcams[e]);return null},t.prototype.getlocalCloudCams=function(){return E(this.cloudcams)},t.prototype.refreshLocalCloudCams=function(){var t=this;return new Promise((function(e){t.getCloudCams().then((function(){e(null)}))}))},t.prototype.changeCloudCamEnableDetector=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().changeCloudCamEnableDetectorByEndUser(t,e).then((function(i){if(0===i.vcode){for(var a=0;a<n.cloudcams.length;a++)if(n.cloudcams[a].licensecam===t){n.cloudcams[a].detector_enable=e;break}o(!0)}else console.log(i.message),o(!1)}))}))},t.prototype.changeCloudCamEnableRecord=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().changeCloudCamEnableRecordByEndUser(t,e).then((function(i){if(0===i.vcode){for(var a=0;a<n.cloudcams.length;a++)if(n.cloudcams[a].licensecam===t){n.cloudcams[a].record_enable=e;break}o(!0)}else console.log(i.message),o(!1)}))}))},t.prototype.changeCloudCamEnableActive=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().changeCloudCamEnableActiveByEndUser(t,e).then((function(i){if(0===i.vcode){for(var a=0;a<n.cloudcams.length;a++)if(n.cloudcams[a].licensecam===t){n.cloudcams[a].active=e;break}o(!0)}else console.log(i.message),o(!1)}))}))},t.prototype.changeCloudCamURL=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().changeCloudCamURLbyEndUser(t,e).then((function(i){if(0===i.vcode){for(var a=0;a<n.cloudcams.length;a++)if(n.cloudcams[a].licensecam===t){n.cloudcams[a].url=e;break}o(!0)}else console.log(i.message),o(!1)}))}))},t.prototype.deleteCloudCam=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.f3rdclouds().deleteCloudCamByEndUser(t).then((function(o){if(0===o.vcode){for(var i=0;i<e.cloudcams.length;i++)if(e.cloudcams[i].licensecam===t){e.cloudcams[i].splice(i,1);break}n(!0)}else console.log(o.message),n(!1)}))}))},t.prototype.updateCloudCam=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().updateCloudCamDataByEndUser(t,e).then((function(i){if(0===i.vcode){for(var a=0;a<n.cloudcams.length;a++)if(n.cloudcams[a].licensecam===t)for(var s in e)n.cloudcams[a].data[s]=e[s];o(!0)}else console.log(i.message),o(!1)}))}))},t.prototype.addCloudCam=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().addCloudCamByEndUser(t,e).then((function(t){0===t.vcode?(n.cloudcams.push(t.data),o(t.data)):(console.log(t.message),o(null))}))}))},t.prototype.getCloudCams=function(){var t=this;return new Promise((function(e,n){var o={id_enduser:{$eq:t.vhmongo_firebase.auth().getUID()}};t.vhmongo_firebase.f3rdclouds().getCloudCamsByDataFieldsByEndUser(o,{},{},0).then((function(n){t.cloudcams=new Array,0===n.vcode?t.cloudcams=n.data:console.log(n),e(t.cloudcams)}),(function(t){n(t)}))}))},t.prototype.getlocalFunction=function(t){for(var e=0;e<this.functions.length;e++)if(this.functions[e]._id===t)return this.functions[e];return null},t.prototype.getlocalFunctions=function(){return this.functions},t.prototype.refreshLocalFunctions=function(){var t=this;return new Promise((function(e){t.getFunctions().then((function(){e(null)}))}))},t.prototype.addFunction=function(t){var e=this;return new Promise((function(n,o){var i=Object.assign({},t);i.id_enduser=e.vhAuth.getUID(),e.vhmongo_firebase.database().addDoc("functions",i).then((function(t){e.functions.push(t),n(t)}),(function(t){o(t)}))}))},t.prototype.updateFunction=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("functions",t,e).then((function(i){for(var a=0;a<n.functions.length;a++)if(n.functions[a]._id===t){n.functions[a]=Object.assign(Object.assign({},n.functions[a]),{data:e});break}o(i)}),(function(t){i(t)}))}))},t.prototype.deleteFunction=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("functions",t).then((function(o){for(var i=0;e.functions.length;i++)if(e.functions[i]._id===t){e.functions.splice(i,1);break}n(o)}),(function(t){o(t)}))}))},t.prototype.getFunctions=function(){var t=this;return new Promise((function(e,n){var o=t.vhAuth.getUID();t.vhmongo_firebase.database().getDocsByFields("functions",{id_enduser:{$eq:o}},{},{},0).then((function(n){var o;t.functions=E(n);for(var i=0;i<t.functions.length;i++)null===(o=t.functions[i])||void 0===o||delete o.id_enduser;e(n)}),(function(t){n(t)}))}))},t.prototype.getFunctions_byFields=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.database().getDocsByFields("functions",t,{},n,o).then((function(t){e(t)}),(function(t){a(t)}))}))},t.prototype.getlocalComponent=function(t){for(var e=0;e<this.components.length;e++)if(this.components[e]._id===t)return this.components[e];return null},t.prototype.getlocalComponents=function(){return this.components},t.prototype.refreshLocalComponents=function(){var t=this;return new Promise((function(e){t.getComponents().then((function(){e(null)}))}))},t.prototype.addComponent=function(t){var e=this;return new Promise((function(n,o){var i=Object.assign({},t);i.id_enduser=e.vhAuth.getUID(),e.vhmongo_firebase.database().addDoc("components",i).then((function(t){e.components.push(t),n(t)}),(function(t){o(t)}))}))},t.prototype.updateComponent=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("components",t,e).then((function(i){for(var a=0;a<n.components.length;a++)if(n.components[a]._id===t){n.components[a]=Object.assign(Object.assign({},n.components[a]),e);break}o(i)}),(function(t){i(t)}))}))},t.prototype.deleteComponent=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("components",t).then((function(o){for(var i=0;e.components.length;i++)if(e.components[i]._id===t){e.components.splice(i,1);break}n(o)}),(function(t){o(t)}))}))},t.prototype.getComponents=function(){var t=this;return new Promise((function(e,n){var o=t.vhAuth.getUID();t.vhmongo_firebase.database().getDocsByFields("components",{id_enduser:{$eq:o}},{},{},0).then((function(n){var o;t.components=E(n);for(var i=0;i<t.components.length;i++)null===(o=t.components[i])||void 0===o||delete o.id_enduser;e(n)}),(function(t){n(t)}))}))},t.prototype.getComponents_byFields=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.database().getDocsByFields("components",t,{},n,o).then((function(t){e(t)}),(function(t){a(t)}))}))},t.prototype.getlocalIcon=function(t){for(var e=0;e<this.icons.length;e++)if(this.icons[e]._id===t)return this.icons[e];return null},t.prototype.getlocalIcons=function(){return this.icons},t.prototype.refreshLocalIcons=function(){var t=this;return new Promise((function(e){t.getIcons().then((function(){e(null)}))}))},t.prototype.addIcon=function(t){var e=this;return new Promise((function(n,o){var i=Object.assign({},t);i.id_enduser=e.vhAuth.getUID(),e.vhmongo_firebase.database().addDoc("icons",i).then((function(t){e.icons.push(t),n(t)}),(function(t){o(t)}))}))},t.prototype.updateIcon=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("icons",t,e).then((function(i){for(var a=0;a<n.icons.length;a++)if(n.icons[a]._id===t){n.icons[a]=Object.assign(Object.assign({},n.icons[a]),e);break}o(i)}),(function(t){i(t)}))}))},t.prototype.deleteIcon=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("icons",t).then((function(o){for(var i=0;e.icons.length;i++)if(e.icons[i]._id===t){e.icons.splice(i,1);break}n(o)}),(function(t){o(t)}))}))},t.prototype.getIcons=function(){var t=this;return new Promise((function(e,n){var o=t.vhAuth.getUID();t.vhmongo_firebase.database().getDocsByFields("icons",{id_enduser:{$eq:o}},{},{},0).then((function(n){var o;t.icons=E(n);for(var i=0;i<t.icons.length;i++)null===(o=t.icons[i])||void 0===o||delete o.id_enduser;e(n)}),(function(t){n(t)}))}))},t.prototype.getIcons_byFields=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.database().getDocsByFields("icons",t,{},n,o).then((function(t){e(t)}),(function(t){a(t)}))}))},t.prototype.getlocalMainboard=function(t){for(var e=0;e<this.mainboards.length;e++)if(this.mainboards[e]._id===t)return this.mainboards[e];return null},t.prototype.getlocalMainboards=function(){return this.mainboards},t.prototype.refreshLocalMainboards=function(){var t=this;return new Promise((function(e){t.getMainboards().then((function(){e(null)}))}))},t.prototype.addMainboard=function(t){var e=this;return new Promise((function(n,o){var i=Object.assign({},t);i.id_enduser=e.vhAuth.getUID(),e.vhmongo_firebase.database().addDoc("mainboards",i).then((function(t){e.icons.push(t),n(t)}),(function(t){o(t)}))}))},t.prototype.updateMainboard=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("mainboards",t,e).then((function(i){for(var a=0;a<n.mainboards.length;a++)if(n.mainboards[a]._id===t){n.mainboards[a]=Object.assign(Object.assign({},n.mainboards[a]),e);break}o(i)}),(function(t){i(t)}))}))},t.prototype.deleteMainboard=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("mainboards",t).then((function(o){for(var i=0;e.mainboards.length;i++)if(e.mainboards[i]._id===t){e.mainboards.splice(i,1);break}n(o)}),(function(t){o(t)}))}))},t.prototype.getMainboard=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("mainboards",t).then((function(t){n(t)}))}))},t.prototype.getMainboards=function(){var t=this;return new Promise((function(e,n){var o=t.vhAuth.getUID();t.vhmongo_firebase.database().getDocsByFields("mainboards",{id_enduser:{$eq:o}},{},{},0).then((function(n){var o;t.mainboards=E(n);for(var i=0;i<t.mainboards.length;i++)null===(o=t.mainboards[i])||void 0===o||delete o.id_enduser;e(n)}),(function(t){n(t)}))}))},t.prototype.getMainboards_byFields=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.database().getDocsByFields("mainboards",t,{},n,o).then((function(t){e(t)}),(function(t){a(t)}))}))},t.prototype.getlocalZone=function(t){for(var e=0;e<this.zones.length;e++)if(this.zones[e]._id===t)return this.zones[e];return null},t.prototype.getlocalZones=function(){return this.zones},t.prototype.refreshLocalZones=function(){var t=this;return new Promise((function(e){t.getZones().then((function(){e(null)}))}))},t.prototype.addZone=function(t){var e=this;return new Promise((function(n,o){var i=Object.assign({},t);i.id_enduser=e.vhAuth.getUID(),e.vhmongo_firebase.database().addDoc("zones",i).then((function(t){e.zones.push(t),n(t)}),(function(t){o(t)}))}))},t.prototype.updateZone=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("zones",t,e).then((function(i){for(var a=0;a<n.zones.length;a++)if(n.zones[a]._id===t){n.zones[a]=Object.assign(Object.assign({},n.zones[a]),e);break}o(i)}),(function(t){i(t)}))}))},t.prototype.deleteZone=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("zones",t).then((function(o){for(var i=0;e.zones.length;i++)if(e.zones[i]._id===t){e.zones.splice(i,1);break}n(o)}),(function(t){o(t)}))}))},t.prototype.getZones=function(){var t=this;return new Promise((function(e,n){var o=t.vhAuth.getUID();t.vhmongo_firebase.database().getDocsByFields("zones",{id_enduser:{$eq:o}},{},{},0).then((function(n){var o;t.zones=E(n);for(var i=0;i<t.zones.length;i++)null===(o=t.zones[i])||void 0===o||delete o.id_enduser;e(n)}),(function(t){n(t)}))}))},t.prototype.getZones_byFields=function(t,e,n,o){var i=this;return new Promise((function(e,a){i.vhmongo_firebase.database().getDocsByFields("zones",t,{},n,o).then((function(t){e(t)}),(function(t){a(t)}))}))},t}();Z.decorators=[{type:e.Injectable}],Z.ctorParameters=function(){return[{type:o.Vhmongo_firebase},{type:V},{type:F},{type:L}]};var K=function(){function t(t,e,n,o){var i=this;this.vhmongo_firebase=t,this.vhQuery=e,this.vhAuth=n,this.vhAlgorithm=o,this.cameras=new Array,this.provinces=new Array,this.rooms=new Array,this.positions=new Array,this.areas=new Array,this.mainboards=new Array,this.functions=new Array,this.components=new Array,this.icons=new Array,this.appsettingstations=new Array,this.scripts=new Array,this.script_details=new Array,this.logs=new Array,this.hwinfo={},this.subjectcameras=new c.Subject,this.subjectappsettingstations=new c.Subject,this.subjectrooms=new c.Subject,this.subjectmainboards=new c.Subject,this.subjectfunctions=new c.Subject,this.subjecticons=new c.Subject,this.subjectpositions=new c.Subject,this.subjectareas=new c.Subject,this.subjectpages=new c.Subject,this.subjectcomponents=new c.Subject,r.Device.getId().then((function(t){var e=i.vhAuth.localStorageGET("hwinfo");null!=e&&null!=e?i.hwinfo=e:(i.hwinfo=Object.assign({},t),i.vhAuth.localStorageSET("hwinfo",i.hwinfo))}))}return t.prototype.syncCollections=function(){var t=this;return new Promise((function(e,n){t.initSyncCollections(),t.callbackCollectionInsert().subscribe(),t.callbackCollectionUpdate().subscribe(),t.callbackCollectionDelete().subscribe(),t.getEUtokenfromDatabase(),setTimeout((function(){e(!0)}),3e3)}))},t.prototype.initSyncCollections=function(){var t=new Array;return t[8]="vhemployees",t[9]="appsettingstations",this.vhmongo_firebase.socketMongoDB().initSyncCollections(t)},t.prototype.closeSyncCollections=function(){this.vhmongo_firebase.socketMongoDB().closeSyncCollections()},t.prototype.callbackCollectionInsert=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackCollectionInsert().subscribe((function(n){if("vhemployees"===n.colname?n.colname="employees":"appsettingstations"===n.colname&&(n.colname="appsettingstations"),"employees"===n.colname)(o=Object.assign({},n.data))._id=n._id,t.vhAuth.insertlocalEmployeeFromSyncCollection(o),t.vhAuth.publishObservableEventEmployees(),e.next(n.colname);else if("appsettingstations"===n.colname){var o;if(!t.getLocalAppSettingStation(n._id))if(n.data.uuid===t.hwinfo.uuid)(o=Object.assign({},n.data))._id=n._id,delete o.uuid,t.appsettingstations.push(o),t.publishObservableEventAppSettingNameStations(),e.next(n.colname)}console.log("inserted",n.colname)}))}))},t.prototype.callbackCollectionUpdate=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackCollectionUpdate().subscribe((function(n){if("vhemployees"===n.colname?n.colname="employees":"appsettingstations"===n.colname&&(n.colname="appsettingstations"),"employees"===n.colname)t.vhAuth.updateLocalEmployeeFromSyncCollection(n._id,n.data),t.vhAuth.publishObservableEventEmployees(),e.next(n.colname);else if("appsettingstations"===n.colname)for(var o=0;o<t.appsettingstations.length;o++)if(t.appsettingstations[o]._id===n._id){t.appsettingstations[o]=Object.assign(Object.assign({},t.appsettingstations[o]),n.data),t.publishObservableEventAppSettingNameStations(),e.next(n.colname);break}console.log("updated",n.colname)}))}))},t.prototype.callbackCollectionDelete=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackCollectionDelete().subscribe((function(n){if("vhemployees"===n.colname?n.colname="employees":"appsettingstations"===n.colname&&(n.colname="appsettingstations"),"employees"===n.colname)t.vhAuth.deleteLocalEmployeeFromSyncCollection(n._id),t.vhAuth.publishObservableEventEmployees(),e.next(n.colname);else if("appsettingstations"===n.colname)for(var o=0;o<t.appsettingstations.length;o++)if(t.appsettingstations[o]._id===n._id){t.appsettingstations.splice(o,1),t.publishObservableEventAppSettingNameStations(),e.next(n.colname);break}console.log("deleted",n.colname)}))}))},t.prototype.startLocalStorage=function(){var t=this;return new Promise((function(e){var n=new Array;n[0]=t.vhAuth.refreshLocalMyPermission(),n[1]=t.refreshLocalProvinces(),t.vhQuery.asyncPromiseAll(n).then((function(){e(null)}))}))},t.prototype.publishObservableEventCameras=function(){this.subjectcameras.next(this.cameras)},t.prototype.observableLocalCameras=function(){return this.subjectcameras},t.prototype.getObservableLocalCameras=function(){var t=this;return new c.Observable((function(e){t.observableLocalCameras().subscribe((function(t){e.next(t)})),t.publishObservableEventCameras()}))},t.prototype.getlocalCamera=function(t){for(var e=0;e<this.cameras.length;e++)if(this.cameras[e]._id===t)return this.cameras[e];return null},t.prototype.getlocalCameras=function(){return this.cameras},t.prototype.refreshLocalCameras=function(){var t=this;return new Promise((function(e){t.getCameras().then((function(){e(null)}))}))},t.prototype.addCamera=function(t){return new Promise((function(t,e){}))},t.prototype.updateCamera=function(t,e){return new Promise((function(t,e){}))},t.prototype.deleteCamera=function(t){return new Promise((function(t,e){}))},t.prototype.getCamera=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("cameras",t).then((function(t){n(t)}))}))},t.prototype.getCameras=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("cameras").then((function(n){t.cameras=new Array,t.cameras=n,e(n)}),(function(t){n(t)}))}))},t.prototype.getLocalEUtoken=function(){return this.vhmongo_firebase.f3rdclouds().getLocalEUtoken()},t.prototype.getEUtokenfromDatabase=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.f3rdclouds().getEUtokenfromDatabase().then((function(){e(null)}))}))},t.prototype.checkExpiredUtoken=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.f3rdclouds().checkExpiredUtoken().then((function(t){0===t.vcode?e(!0):(console.log(t.message),e(!1))}))}))},t.prototype.changeCloudCamEnableCLPRbyEndUser=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().changeCloudCamEnableCLPRbyEndUser(t,e).then((function(t){0===t.vcode?o(!0):(console.log(t.message),o(!1))}))}))},t.prototype.changeCloudCamEnableRLPRbyEndUser=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().changeCloudCamEnableRLPRbyEndUser(t,e).then((function(t){0===t.vcode?o(!0):(console.log(t.message),o(!1))}))}))},t.prototype.changeCloudCamEnableDetectorByEndUser=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().changeCloudCamEnableDetectorByEndUser(t,e).then((function(t){0===t.vcode?o(!0):(console.log(t.message),o(!1))}))}))},t.prototype.changeCloudCamEnableRecordByEndUser=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().changeCloudCamEnableRecordByEndUser(t,e).then((function(t){0===t.vcode?o(!0):(console.log(t.message),o(!1))}))}))},t.prototype.changeCloudCamEnableActiveByEndUser=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().changeCloudCamEnableActiveByEndUser(t,e).then((function(t){0===t.vcode?o(!0):(console.log(t.message),o(!1))}))}))},t.prototype.changeCloudCamURLbyEndUser=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().changeCloudCamURLbyEndUser(t,e).then((function(t){0===t.vcode?o(!0):(console.log(t.message),o(!1))}))}))},t.prototype.addCloudCamByEndUser=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().addCloudCamByEndUser(t,e).then((function(t){0===t.vcode?o(t.data):(console.log(t.message),o(null))}))}))},t.prototype.updateCloudCamDataByEndUser=function(t,e){var n=this;return new Promise((function(o){n.vhmongo_firebase.f3rdclouds().updateCloudCamDataByEndUser(t,e).then((function(t){0===t.vcode?o(!0):(console.log(t.message),o(!1))}))}))},t.prototype.deleteCloudCamByEndUser=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.f3rdclouds().deleteCloudCamByEndUser(t).then((function(t){0===t.vcode?n(!0):(console.log(t.message),n(!1))}))}))},t.prototype.getCloudCamByEndUser=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.f3rdclouds().getCloudCamByEndUser(t).then((function(t){0===t.vcode?n(t.data):(console.log(t.message),n(null))}))}))},t.prototype.getCloudCamsByDataFieldsByEndUser=function(t,e,n,o){var i=this;return new Promise((function(a,s){i.vhmongo_firebase.f3rdclouds().getCloudCamsByDataFieldsByEndUser(t,e,n,o).then((function(t){var e=new Array;0===t.vcode?e=E(t.data):console.log(t),a(e)}),(function(t){s(t)}))}))},t.prototype.getPlaybackListCamByEndUser=function(t,e,n,o){var i=this;return new Promise((function(a,s){i.vhmongo_firebase.f3rdclouds().getPlaybackListCambyEndUser(t,e,n,o).then((function(t){0===t.vcode?a(t.data):(console.log(t),a([]))}),(function(t){s(t)}))}))},t.prototype.getlocalProvince=function(t){for(var e=function(e){if(n.provinces[e]._id===t){var o=Object.assign({},n.provinces[e]);if(null!=o.subs){var i=E(o.subs);o.subs=new Array,i.forEach((function(t){o.subs.push(Object.assign({},t))}))}return{value:o}}},n=this,o=0;o<this.provinces.length;o++){var i=e(o);if("object"==typeof i)return i.value}return null},t.prototype.getlocalProvinces=function(){return this.provinces},t.prototype.refreshLocalProvinces=function(){var t=this;return new Promise((function(e){t.getProvinces().then((function(){e(null)}))}))},t.prototype.addProvince=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("provinces",t).then((function(t){e.provinces.push(t),n(t)}),(function(t){o(t)}))}))},t.prototype.updateProvince=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("provinces",t,e).then((function(i){for(var a=0;a<n.provinces.length;a++)if(n.provinces[a]._id===t){n.provinces[a]=E(n.provinces[a],[e]);break}o(i)}),(function(t){i(t)}))}))},t.prototype.deleteProvince=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("provinces",t).then((function(o){for(var i=0;i<e.provinces.length;i++)if(e.provinces[i]._id===t){e.provinces.splice(i,1);break}n(o)}),(function(t){o(t)}))}))},t.prototype.getProvinces=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("provinces").then((function(n){t.provinces=new Array,t.provinces=n,e(n)}),(function(t){n(t)}))}))},t.prototype.addSubsProvince=function(t,e){var n=this;return new Promise((function(o,i){for(var a=new Array,s=0;s<e.length;s++)a[s]=Object.assign(Object.assign({},e[s]),{_id:n.vhAlgorithm.ObjectId()});var r,l=!1,c=0,u=setInterval((function(){if(c++,r=n.getlocalProvince(t)){l=!0,void 0===r.subs&&(r.subs=new Array);var e=E(r.subs,a);n.vhmongo_firebase.database().updateDoc("provinces",t,{subs:e}).then((function(){for(var i=0;i<n.provinces.length;i++)if(n.provinces[i]._id===t){n.provinces[i].subs=e;break}o(a)}),(function(){o(null)}))}!0!==l&&20!==c||clearInterval(u)}),100)}))},t.prototype.updateSubProvince=function(t,e,n){var o=this;return new Promise((function(i,a){var s=o.getlocalProvince(t);if(null!=s.subs)for(var r=function(r){if(s.subs[r]._id===e){for(var l in n)s.subs[r][l]=n[l];var c=E(s.subs);return o.vhmongo_firebase.database().updateDoc("provinces",t,{subs:c}).then((function(e){for(var n=0;n<o.provinces.length;n++)if(o.provinces[n]._id===t){o.provinces[n].subs=c;break}i(e)}),(function(t){a(t)})),"break"}},l=0;l<s.subs.length;l++){if("break"===r(l))break}}))},t.prototype.deleteSubProvince=function(t,e){var n=this;return new Promise((function(o,i){var a=n.getlocalProvince(t);if(null!=a.subs)for(var s=0;s<a.subs.length;s++)if(a.subs[s]._id===e){a.subs.splice(s,1),n.vhmongo_firebase.database().updateDoc("provinces",t,{subs:a.subs}).then((function(t){for(var i=0;i<n.provinces.length;i++)for(var a=0;a<n.provinces[i].subs.length;a++)if(n.provinces[i].subs[a]._id===e){n.provinces[i].subs.splice(a,1);break}o(t)}),(function(t){i(t)}));break}}))},t.prototype.addDistrict=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("districts",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateDistrict=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("districts",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteDistrict=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("districts",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getDistrict=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("districts",t).then((function(t){n(t)}))}))},t.prototype.getDistricts=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("districts").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.getDistricts_byIDprovince=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("districts",{id_province:{$eq:t}},{},{},0).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.addSubsDistrict=function(t,e){var n=this;return new Promise((function(o,i){for(var a=new Array,s=0;s<e.length;s++)a[s]=Object.assign(Object.assign({},e[s]),{_id:n.vhAlgorithm.ObjectId()});n.getDistrict(t).then((function(e){if(e){void 0===e.subs&&(e.subs=new Array);var i=E(e.subs,a);n.vhmongo_firebase.database().updateDoc("districts",t,{subs:i}).then((function(){o(a)}),(function(){o(null)}))}}))}))},t.prototype.updateSubDistrict=function(t,e,n){var o=this;return new Promise((function(i,a){o.getDistrict(t).then((function(s){if(s&&null!=s.subs)for(var r=0;r<s.subs.length;r++)if(s.subs[r]._id===e){for(var l in s.subs[r]=Object.assign(Object.assign({},s.subs[r]),n),n)s.subs[r][l]=n[l];var c=E(s.subs);o.vhmongo_firebase.database().updateDoc("districts",t,{subs:c}).then((function(t){i(t)}),(function(t){a(t)}));break}}))}))},t.prototype.deleteSubDistrict=function(t,e){var n=this;return new Promise((function(o,i){n.getDistrict(t).then((function(t){if(t&&null!=t.subs)for(var a=0;a<t.subs.length;a++)if(t.subs[a]._id===e){t.subs.splice(a,1),n.vhmongo_firebase.database().updateDoc("districts",t._id,{subs:t.subs}).then((function(t){o(t)}),(function(t){i(t)}));break}}),(function(t){i(t)}))}))},t.prototype.addWard=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("wards",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateWard=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("wards",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteWard=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("wards",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getWard=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("wards",t).then((function(t){n(t)}))}))},t.prototype.getWards=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("wards").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.getWards_byIDdistrict=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("wards",{id_district:{$eq:t}},{},{},0).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.addSubsWard=function(t,e){var n=this;return new Promise((function(o,i){for(var a=new Array,s=0;s<e.length;s++)a[s]=Object.assign(Object.assign({},e[s]),{_id:n.vhAlgorithm.ObjectId()});n.getWard(t).then((function(e){if(e){void 0===e.subs&&(e.subs=new Array);var i=E(e.subs,a);n.vhmongo_firebase.database().updateDoc("wards",t,{subs:i}).then((function(){o(a)}),(function(){o(null)}))}}))}))},t.prototype.updateSubWard=function(t,e,n){var o=this;return new Promise((function(i,a){o.getWard(t).then((function(s){if(s&&null!=s.subs)for(var r=0;r<s.subs.length;r++)if(s.subs[r]._id===e){for(var l in n)s.subs[r][l]=n[l];var c=E(s.subs);o.vhmongo_firebase.database().updateDoc("wards",t,{subs:c}).then((function(t){i(t)}),(function(t){a(t)}));break}}))}))},t.prototype.deleteSubWard=function(t,e){var n=this;return new Promise((function(o,i){n.getWard(t).then((function(a){if(a&&null!=a.subs)for(var s=0;s<a.subs.length;s++)if(a.subs[s]._id===e){a.subs.splice(s,1),n.vhmongo_firebase.database().updateDoc("wards",t,{subs:a.subs}).then((function(t){o(t)}),(function(t){i(t)}));break}}),(function(t){i(t)}))}))},t.prototype.publishObservableEventRooms=function(){this.subjectrooms.next(this.rooms)},t.prototype.observableLocalRooms=function(){return this.subjectrooms},t.prototype.getObservableLocalRooms=function(){var t=this;return new c.Observable((function(e){t.observableLocalRooms().subscribe((function(t){e.next(t)})),t.publishObservableEventRooms()}))},t.prototype.getlocalRoom=function(t){for(var e=0;e<this.rooms.length;e++)if(this.rooms[e]._id===t)return this.rooms[e];return null},t.prototype.getlocalRooms=function(){return this.rooms},t.prototype.refreshLocalRooms=function(){var t=this;return new Promise((function(e){t.getRooms().then((function(){e(null)}))}))},t.prototype.addRoom=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("rooms",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateRoom=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("rooms",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteRoom=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("rooms",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getRoom=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("rooms",t).then((function(t){n(t)}))}))},t.prototype.getRooms=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("rooms").then((function(n){t.rooms=new Array,t.rooms=n,e(n)}),(function(t){n(t)}))}))},t.prototype.addPage=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("pages",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updatePage=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("pages",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deletePage=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("pages",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPage=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("pages",t).then((function(t){n(t)}))}))},t.prototype.getPages=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("pages").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.getPages_byIDdistrict=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("pages",{id_district:{$eq:t}},{},{},0).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPages_byIDemployee=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("pages",{id_employee:{$eq:t}},{},{},0).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.publishObservableEventAreas=function(){this.subjectareas.next(this.areas)},t.prototype.observableLocalAreas=function(){return this.subjectareas},t.prototype.getObservableLocalAreas=function(){var t=this;return new c.Observable((function(e){t.observableLocalAreas().subscribe((function(t){e.next(t)})),t.publishObservableEventAreas()}))},t.prototype.getlocalArea=function(t){for(var e=0;e<this.areas.length;e++)if(this.areas[e]._id===t)return this.areas[e];return null},t.prototype.getlocalAreas=function(){return this.areas},t.prototype.refreshLocalAreas=function(){var t=this;return new Promise((function(e){t.getAreas().then((function(){e(null)}))}))},t.prototype.addArea=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("areas",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateArea=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("areas",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteArea=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("areas",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getArea=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("areas",t).then((function(t){n(t)}))}))},t.prototype.getAreas=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("areas").then((function(n){t.areas=new Array,t.areas=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventPositions=function(){this.subjectpositions.next(this.positions)},t.prototype.observableLocalPositions=function(){return this.subjectpositions},t.prototype.getObservableLocalPositions=function(){var t=this;return new c.Observable((function(e){t.observableLocalPositions().subscribe((function(t){e.next(t)})),t.publishObservableEventPositions()}))},t.prototype.getlocalPosition=function(t){for(var e=0;e<this.positions.length;e++)if(this.positions[e]._id===t)return this.positions[e];return null},t.prototype.getlocalPositions=function(){return this.positions},t.prototype.refreshLocalPositions=function(){var t=this;return new Promise((function(e){t.getPositions().then((function(){e(null)}))}))},t.prototype.addPosition=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("positions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updatePosition=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("positions",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deletePosition=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("positions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getPosition=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("positions",t).then((function(t){n(t)}))}))},t.prototype.getPositions=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("positions").then((function(n){t.positions=new Array,t.positions=n,e(n)}),(function(t){n(t)}))}))},t.prototype.getlocalLog=function(t){for(var e=0;e<this.logs.length;e++)if(this.logs[e]._id===t)return this.logs[e];return null},t.prototype.getlocalLogs=function(){return this.logs},t.prototype.refreshLocalLogs=function(){var t=this;return new Promise((function(e){t.getLogs().then((function(){e(null)}))}))},t.prototype.addLog=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("logs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateLog=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("logs",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteLog=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("logs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getLog=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("logs",t).then((function(t){n(t)}))}))},t.prototype.getLogs=function(){var t=this;return new Promise((function(e,n){t.logs=new Array,t.vhmongo_firebase.database().getDocs("logs").then((function(n){t.logs=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventMainboards=function(){this.subjectmainboards.next(this.mainboards)},t.prototype.observableLocalMainboards=function(){return this.subjectmainboards},t.prototype.getObservableLocalMainboards=function(){var t=this;return new c.Observable((function(e){t.observableLocalMainboards().subscribe((function(t){e.next(t)})),t.publishObservableEventMainboards()}))},t.prototype.getlocalMainboard=function(t){for(var e=0;e<this.mainboards.length;e++)if(this.mainboards[e]._id===t)return this.mainboards[e];return null},t.prototype.getlocalMainboards=function(){return this.mainboards},t.prototype.refreshLocalMainboards=function(){var t=this;return new Promise((function(e){t.getMainboards().then((function(){e(null)}))}))},t.prototype.addMainboard=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("mainboards",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateMainboard=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("mainboards",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteMainboard=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("mainboards",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getMainboard=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("mainboards",t).then((function(t){n(t)}))}))},t.prototype.getMainboards=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("mainboards").then((function(n){t.mainboards=new Array,t.mainboards=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventFunctions=function(){this.subjectfunctions.next(this.functions)},t.prototype.observableLocalFunctions=function(){return this.subjectfunctions},t.prototype.getObservableLocalFunctions=function(){var t=this;return new c.Observable((function(e){t.observableLocalFunctions().subscribe((function(t){e.next(t)})),t.publishObservableEventFunctions()}))},t.prototype.getlocalFunction=function(t){for(var e=0;e<this.functions.length;e++)if(this.functions[e]._id===t)return this.functions[e];return null},t.prototype.getlocalFunctions=function(){return this.functions},t.prototype.refreshLocalFunctions=function(){var t=this;return new Promise((function(e){t.getFunctions().then((function(){e(null)}))}))},t.prototype.addFunction=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("functions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateFunction=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("functions",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteFunction=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("functions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getFunction=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("functions",t).then((function(t){n(t)}))}))},t.prototype.getFunctions=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("functions").then((function(n){t.functions=new Array,t.functions=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventComponents=function(){this.subjectcomponents.next(this.components)},t.prototype.observableLocalComponents=function(){return this.subjectcomponents},t.prototype.getObservableLocalComponents=function(){var t=this;return new c.Observable((function(e){t.observableLocalComponents().subscribe((function(t){e.next(t)})),t.publishObservableEventComponents()}))},t.prototype.getlocalComponent=function(t){for(var e=0;e<this.components.length;e++)if(this.components[e]._id===t)return this.components[e];return null},t.prototype.getlocalComponents=function(){return this.components},t.prototype.refreshLocalComponents=function(){var t=this;return new Promise((function(e){t.getComponents().then((function(){e(null)}))}))},t.prototype.addComponent=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("components",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateComponent=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("components",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteComponent=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("components",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getComponent=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("components",t).then((function(t){n(t)}))}))},t.prototype.getComponents=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("components").then((function(n){t.components=new Array,t.components=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventIcons=function(){this.subjecticons.next(this.icons)},t.prototype.observableLocalIcons=function(){return this.subjecticons},t.prototype.getObservableLocalIcons=function(){var t=this;return new c.Observable((function(e){t.observableLocalIcons().subscribe((function(t){e.next(t)})),t.publishObservableEventIcons()}))},t.prototype.getlocalIcon=function(t){for(var e=0;e<this.icons.length;e++)if(this.icons[e]._id===t)return this.icons[e];return null},t.prototype.getlocalIcons=function(){return this.icons},t.prototype.refreshLocalIcons=function(){var t=this;return new Promise((function(e){t.getIcons().then((function(){e(null)}))}))},t.prototype.addIcon=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("icons",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateIcon=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("icons",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteIcon=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("icons",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getIcon=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("icons",t).then((function(t){n(t)}))}))},t.prototype.getIcons=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("icons").then((function(n){t.icons=new Array,t.icons=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventAppSettingNameStations=function(){this.subjectappsettingstations.next()},t.prototype.observableLocalAppSettingNameStations=function(){return this.subjectappsettingstations},t.prototype.getObservableLocalAppSettingNameStations=function(){var t=this;return new c.Observable((function(e){t.observableLocalAppSettingNameStations().subscribe((function(){for(var n=new Array,o=0;o<t.appsettingstations.length;o++)n.push(t.appsettingstations[o].appsetting_name);e.next(n)})),t.publishObservableEventAppSettingNameStations()}))},t.prototype.getLocalAppSettingNameStations=function(){for(var t=new Array,e=0;e<this.appsettingstations.length;e++)t.push(this.appsettingstations[e].appsetting_name);return t},t.prototype.getLocalAppSettingNameStation=function(t){for(var e={},n=0;n<this.appsettingstations.length;n++)if(this.appsettingstations[n].appsetting_name===t){delete(e=Object.assign({},this.appsettingstations[n]))._id,delete e.appsetting_name;break}return e},t.prototype.getLocalAppSettingStation=function(t){for(var e=0;e<this.appsettingstations.length;e++)if(this.appsettingstations[e]._id===t)return this.appsettingstations[e];return null},t.prototype.refreshLocalAppSettingNameStations=function(){return new Promise((function(t,e){t(null)}))},t.prototype.getAppSettingStations=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocsByFields("appsettingstations",{uuid:{$eq:t.hwinfo.uuid}},{},{},0).then((function(n){n.length>0&&(t.appsettingstations=n),e(null)}),(function(t){n(t)}))}))},t.prototype.updateAppSettingNameStation=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().getDocsByFields("appsettingstations",{appsetting_name:{$eq:t},uuid:{$eq:n.hwinfo.uuid}},{},{},0).then((function(a){if(a.length>0)n.vhmongo_firebase.database().updateDoc("appsettingstations",a[0]._id,e).then((function(t){o(t)}),(function(t){i(t)}));else{var s=Object.assign({},e);s.appsetting_name=t,s.uuid=n.hwinfo.uuid,n.vhmongo_firebase.database().addDoc("appsettingstations",s).then((function(){o(!0)}),(function(t){i(t)}))}}))}))},t.prototype.deleteAppSettingNameStation=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("appsettingstations",{appsetting_name:{$eq:t},uuid:{$eq:e.hwinfo.uuid}},{},{},0).then((function(t){t.length>0?e.vhmongo_firebase.database().deleteDoc("appsettingstations",t[0]._id).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}))}))},t.prototype.getlocalScript=function(t){for(var e=0;e<this.scripts.length;e++)if(this.scripts[e]._id===t)return this.scripts[e];return null},t.prototype.getlocalScripts=function(){return this.scripts},t.prototype.refreshLocalScripts=function(){var t=this;return new Promise((function(e){t.getScripts().then((function(){e(null)}))}))},t.prototype.addScript=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("scripts",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateScript=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("scripts",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteScript=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("scripts",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getScript=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("scripts",t).then((function(t){n(t)}))}))},t.prototype.getScripts=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("scripts").then((function(n){t.scripts=new Array,t.scripts=n,e(n)}),(function(t){n(t)}))}))},t.prototype.getlocalScript_detail=function(t){for(var e=0;e<this.script_details.length;e++)if(this.script_details[e]._id===t)return this.script_details[e];return null},t.prototype.getlocalScript_details=function(){return this.script_details},t.prototype.refreshLocalScript_details=function(){var t=this;return new Promise((function(e){t.getScript_details().then((function(){e(null)}))}))},t.prototype.addScript_detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("script_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateScript_detail=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("script_details",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteScript_detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("script_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getScript_detail=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("script_details",t).then((function(t){n(t)}))}))},t.prototype.getScript_details=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("script_details").then((function(n){t.script_details=new Array,t.script_details=n,e(n)}),(function(t){n(t)}))}))},t}();K.decorators=[{type:e.Injectable}],K.ctorParameters=function(){return[{type:o.Vhmongo_firebase},{type:V},{type:F},{type:L}]};var X=function(){function t(t,e,n,o){var i=this;this.vhmongo_firebase=t,this.vhQuery=e,this.vhAuth=n,this.vhAlgorithm=o,this.cameras=new Array,this.rooms=new Array,this.mainboards=new Array,this.functions=new Array,this.components=new Array,this.icons=new Array,this.appsettingstations=new Array,this.scripts=new Array,this.script_details=new Array,this.logs=new Array,this.hwinfo={},this.subjectcameras=new c.Subject,this.subjectappsettingstations=new c.Subject,this.subjectrooms=new c.Subject,this.subjectmainboards=new c.Subject,this.subjectfunctions=new c.Subject,this.subjecticons=new c.Subject,this.subjectcomponents=new c.Subject,r.Device.getId().then((function(t){var e=i.vhAuth.localStorageGET("hwinfo");null!=e&&null!=e?i.hwinfo=e:(i.hwinfo=Object.assign({},t),i.vhAuth.localStorageSET("hwinfo",i.hwinfo))}))}return t.prototype.syncCollections=function(){var t=this;return new Promise((function(e,n){t.initSyncCollections(),t.callbackCollectionInsert().subscribe(),t.callbackCollectionUpdate().subscribe(),t.callbackCollectionDelete().subscribe(),setTimeout((function(){e(!0)}),3e3)}))},t.prototype.initSyncCollections=function(){var t=new Array;return t[0]="cameras",t[1]="rooms",t[2]="mainboards",t[3]="components",t[4]="icons",t[5]="functions",t[6]="vhemployees",t[7]="appsettingstations",this.vhmongo_firebase.socketMongoDB().initSyncCollections(t)},t.prototype.closeSyncCollections=function(){this.vhmongo_firebase.socketMongoDB().closeSyncCollections()},t.prototype.callbackCollectionInsert=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackCollectionInsert().subscribe((function(n){if("vhemployees"===n.colname?n.colname="employees":"appsettingstations"===n.colname&&(n.colname="appsettingstations"),"cameras"===n.colname)t.getlocalCamera(n._id)||((o=Object.assign({},n.data))._id=n._id,t.cameras.push(o),t.publishObservableEventCameras(),e.next(n.colname));else if("rooms"===n.colname){if(!t.getlocalRoom(n._id))(o=Object.assign({},n.data))._id=n._id,t.rooms.push(o),t.publishObservableEventRooms(),e.next(n.colname)}else if("mainboards"===n.colname){if(!t.getlocalMainboard(n._id))(o=Object.assign({},n.data))._id=n._id,t.mainboards.push(o),t.publishObservableEventMainboards(),e.next(n.colname)}else if("components"===n.colname){if(!t.getlocalComponent(n._id))(o=Object.assign({},n.data))._id=n._id,t.components.push(o),t.publishObservableEventComponents(),e.next(n.colname)}else if("icons"===n.colname){if(!t.getlocalIcon(n._id))(o=Object.assign({},n.data))._id=n._id,t.icons.push(o),t.publishObservableEventIcons(),e.next(n.colname)}else if("functions"===n.colname){if(!t.getlocalFunction(n._id))(o=Object.assign({},n.data))._id=n._id,t.functions.push(o),t.publishObservableEventFunctions(),e.next(n.colname)}else if("employees"===n.colname){(o=Object.assign({},n.data))._id=n._id,t.vhAuth.insertlocalEmployeeFromSyncCollection(o),t.vhAuth.publishObservableEventEmployees(),e.next(n.colname)}else if("appsettingstations"===n.colname){var o;if(!t.getLocalAppSettingStation(n._id))if(n.data.uuid===t.hwinfo.uuid)(o=Object.assign({},n.data))._id=n._id,delete o.uuid,t.appsettingstations.push(o),t.publishObservableEventAppSettingNameStations(),e.next(n.colname)}console.log("inserted",n.colname)}))}))},t.prototype.callbackCollectionUpdate=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackCollectionUpdate().subscribe((function(n){if("vhemployees"===n.colname?n.colname="employees":"appsettingstations"===n.colname&&(n.colname="appsettingstations"),"cameras"===n.colname){for(var o=0;o<t.cameras.length;o++)if(t.cameras[o]._id===n._id){t.cameras[o]=Object.assign(Object.assign({},t.cameras[o]),n.data),t.publishObservableEventCameras(),e.next(n.colname);break}}else if("rooms"===n.colname){for(o=0;o<t.rooms.length;o++)if(t.rooms[o]._id===n._id){t.rooms[o]=Object.assign(Object.assign({},t.rooms[o]),n.data),t.publishObservableEventRooms(),e.next(n.colname);break}}else if("mainboards"===n.colname){for(o=0;o<t.mainboards.length;o++)if(t.mainboards[o]._id===n._id){t.mainboards[o]=Object.assign(Object.assign({},t.mainboards[o]),n.data),t.publishObservableEventMainboards(),e.next(n.colname);break}}else if("components"===n.colname){for(o=0;o<t.components.length;o++)if(t.rooms[o]._id===n._id){t.rooms[o]=Object.assign(Object.assign({},t.components[o]),n.data),t.publishObservableEventComponents(),e.next(n.colname);break}}else if("icons"===n.colname){for(o=0;o<t.icons.length;o++)if(t.icons[o]._id===n._id){t.icons[o]=Object.assign(Object.assign({},t.icons[o]),n.data),t.publishObservableEventIcons(),e.next(n.colname);break}}else if("functions"===n.colname){for(o=0;o<t.icons.functions;o++)if(t.functions[o]._id===n._id){t.functions[o]=Object.assign(Object.assign({},t.functions[o]),n.data),t.publishObservableEventFunctions(),e.next(n.colname);break}}else if("employees"===n.colname)t.vhAuth.updateLocalEmployeeFromSyncCollection(n._id,n.data),t.vhAuth.publishObservableEventEmployees(),e.next(n.colname);else if("appsettingstations"===n.colname)for(o=0;o<t.appsettingstations.length;o++)if(t.appsettingstations[o]._id===n._id){t.appsettingstations[o]=Object.assign(Object.assign({},t.appsettingstations[o]),n.data),t.publishObservableEventAppSettingNameStations(),e.next(n.colname);break}console.log("updated",n.colname)}))}))},t.prototype.callbackCollectionDelete=function(){var t=this;return new c.Observable((function(e){t.vhmongo_firebase.socketMongoDB().callbackCollectionDelete().subscribe((function(n){if("vhemployees"===n.colname?n.colname="employees":"appsettingstations"===n.colname&&(n.colname="appsettingstations"),"cameras"===n.colname){for(var o=0;o<t.cameras.length;o++)if(t.cameras[o]._id===n._id){t.cameras.splice(o,1),t.publishObservableEventCameras(),e.next(n.colname);break}}else if("rooms"===n.colname){for(o=0;o<t.rooms.length;o++)if(t.rooms[o]._id===n._id){t.rooms.splice(o,1),t.publishObservableEventRooms(),e.next(n.colname);break}}else if("mainboards"===n.colname){for(o=0;o<t.mainboards.length;o++)if(t.mainboards[o]._id===n._id){t.mainboards.splice(o,1),t.publishObservableEventMainboards(),e.next(n.colname);break}}else if("components"===n.colname){for(o=0;o<t.components.length;o++)if(t.components[o]._id===n._id){t.components.splice(o,1),t.publishObservableEventComponents(),e.next(n.colname);break}}else if("icons"===n.colname){for(o=0;o<t.icons.length;o++)if(t.icons[o]._id===n._id){t.icons.splice(o,1),t.publishObservableEventIcons(),e.next(n.colname);break}}else if("functions"===n.colname){for(o=0;o<t.functions.length;o++)if(t.functions[o]._id===n._id){t.functions.splice(o,1),t.publishObservableEventFunctions(),e.next(n.colname);break}}else if("employees"===n.colname)t.vhAuth.deleteLocalEmployeeFromSyncCollection(n._id),t.vhAuth.publishObservableEventEmployees(),e.next(n.colname);else if("appsettingstations"===n.colname)for(o=0;o<t.appsettingstations.length;o++)if(t.appsettingstations[o]._id===n._id){t.appsettingstations.splice(o,1),t.publishObservableEventAppSettingNameStations(),e.next(n.colname);break}console.log("deleted",n.colname)}))}))},t.prototype.startLocalStorage=function(){var t=this;return new Promise((function(e){var n=new Array;n[0]=t.vhAuth.refreshLocalEmployees(),n[1]=t.vhAuth.refreshLocalMyPermission(),n[2]=t.refreshLocalRooms(),n[3]=t.refreshLocalCameras(),n[4]=t.refreshLocalComponents(),n[5]=t.refreshLocalFunctions(),n[6]=t.refreshLocalIcons(),n[7]=t.refreshLocalMainboards(),t.vhQuery.asyncPromiseAll(n).then((function(){e(null)}))}))},t.prototype.publishObservableEventCameras=function(){this.subjectcameras.next(this.cameras)},t.prototype.observableLocalCameras=function(){return this.subjectcameras},t.prototype.getObservableLocalCameras=function(){var t=this;return new c.Observable((function(e){t.observableLocalCameras().subscribe((function(t){e.next(t)})),t.publishObservableEventCameras()}))},t.prototype.getlocalCamera=function(t){for(var e=0;e<this.cameras.length;e++)if(this.cameras[e]._id===t)return this.cameras[e];return null},t.prototype.getlocalCameras=function(){return this.cameras},t.prototype.refreshLocalCameras=function(){var t=this;return new Promise((function(e){t.getCameras().then((function(){e(null)}))}))},t.prototype.addCamera=function(t){return new Promise((function(t,e){}))},t.prototype.updateCamera=function(t,e){return new Promise((function(t,e){}))},t.prototype.deleteCamera=function(t){return new Promise((function(t,e){}))},t.prototype.getCamera=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("cameras",t).then((function(t){n(t)}))}))},t.prototype.getCameras=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("cameras").then((function(n){t.cameras=new Array,t.cameras=n,e(n)}),(function(t){n(t)}))}))},t.prototype.getPlaybackListCambyEndUser=function(t,e,n,o){var i=this;return new Promise((function(a,s){i.vhmongo_firebase.f3rdclouds().getPlaybackListCambyEndUser(t,e,n,o).then((function(t){0===t.vcode?a(t.data):(console.log(t),a([]))}),(function(t){s(t)}))}))},t.prototype.publishObservableEventRooms=function(){this.subjectrooms.next(this.rooms)},t.prototype.observableLocalRooms=function(){return this.subjectrooms},t.prototype.getObservableLocalRooms=function(){var t=this;return new c.Observable((function(e){t.observableLocalRooms().subscribe((function(t){e.next(t)})),t.publishObservableEventRooms()}))},t.prototype.getlocalRoom=function(t){for(var e=0;e<this.rooms.length;e++)if(this.rooms[e]._id===t)return this.rooms[e];return null},t.prototype.getlocalRooms=function(){return this.rooms},t.prototype.refreshLocalRooms=function(){var t=this;return new Promise((function(e){t.getRooms().then((function(){e(null)}))}))},t.prototype.addRoom=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("rooms",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateRoom=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("rooms",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteRoom=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("rooms",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getRoom=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("rooms",t).then((function(t){n(t)}))}))},t.prototype.getRooms=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("rooms").then((function(n){t.rooms=new Array,t.rooms=n,e(n)}),(function(t){n(t)}))}))},t.prototype.getlocalLog=function(t){for(var e=0;e<this.logs.length;e++)if(this.logs[e]._id===t)return this.logs[e];return null},t.prototype.getlocalLogs=function(){return this.logs},t.prototype.refreshLocalLogs=function(){var t=this;return new Promise((function(e){t.getLogs().then((function(){e(null)}))}))},t.prototype.addLog=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("logs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateLog=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("logs",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteLog=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("logs",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getLog=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("logs",t).then((function(t){n(t)}))}))},t.prototype.getLogs=function(){var t=this;return new Promise((function(e,n){t.logs=new Array,t.vhmongo_firebase.database().getDocs("logs").then((function(n){t.logs=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventMainboards=function(){this.subjectmainboards.next(this.mainboards)},t.prototype.observableLocalMainboards=function(){return this.subjectmainboards},t.prototype.getObservableLocalMainboards=function(){var t=this;return new c.Observable((function(e){t.observableLocalMainboards().subscribe((function(t){e.next(t)})),t.publishObservableEventMainboards()}))},t.prototype.getlocalMainboard=function(t){for(var e=0;e<this.mainboards.length;e++)if(this.mainboards[e]._id===t)return this.mainboards[e];return null},t.prototype.getlocalMainboards=function(){return this.mainboards},t.prototype.refreshLocalMainboards=function(){var t=this;return new Promise((function(e){t.getMainboards().then((function(){e(null)}))}))},t.prototype.addMainboard=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("mainboards",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateMainboard=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("mainboards",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteMainboard=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("mainboards",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getMainboard=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("mainboards",t).then((function(t){n(t)}))}))},t.prototype.getMainboards=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("mainboards").then((function(n){t.mainboards=new Array,t.mainboards=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventFunctions=function(){this.subjectfunctions.next(this.functions)},t.prototype.observableLocalFunctions=function(){return this.subjectfunctions},t.prototype.getObservableLocalFunctions=function(){var t=this;return new c.Observable((function(e){t.observableLocalFunctions().subscribe((function(t){e.next(t)})),t.publishObservableEventFunctions()}))},t.prototype.getlocalFunction=function(t){for(var e=0;e<this.functions.length;e++)if(this.functions[e]._id===t)return this.functions[e];return null},t.prototype.getlocalFunctions=function(){return this.functions},t.prototype.refreshLocalFunctions=function(){var t=this;return new Promise((function(e){t.getFunctions().then((function(){e(null)}))}))},t.prototype.addFunction=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("functions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateFunction=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("functions",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteFunction=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("functions",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getFunction=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("functions",t).then((function(t){n(t)}))}))},t.prototype.getFunctions=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("functions").then((function(n){t.functions=new Array,t.functions=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventComponents=function(){this.subjectcomponents.next(this.components)},t.prototype.observableLocalComponents=function(){return this.subjectcomponents},t.prototype.getObservableLocalComponents=function(){var t=this;return new c.Observable((function(e){t.observableLocalComponents().subscribe((function(t){e.next(t)})),t.publishObservableEventComponents()}))},t.prototype.getlocalComponent=function(t){for(var e=0;e<this.components.length;e++)if(this.components[e]._id===t)return this.components[e];return null},t.prototype.getlocalComponents=function(){return this.components},t.prototype.refreshLocalComponents=function(){var t=this;return new Promise((function(e){t.getComponents().then((function(){e(null)}))}))},t.prototype.addComponent=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("components",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateComponent=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("components",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteComponent=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("components",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getComponent=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("components",t).then((function(t){n(t)}))}))},t.prototype.getComponents=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("components").then((function(n){t.components=new Array,t.components=n,e(n)}),(function(t){n(t)}))}))},t.prototype.addIRManufacturer_byID=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.rootdatabase().addDocbyID("IRmanufacturers",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.updateIRManufacturer=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.rootdatabase().updateDoc("IRmanufacturers",t,e).then((function(){o(void 0)}),(function(t){i(t)}))}))},t.prototype.deleteIRManufacturer=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.rootdatabase().deleteDoc("IRmanufacturers",t).then((function(){n(void 0)}),(function(t){o(t)}))}))},t.prototype.getIRManufacturer=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.rootdatabase().getDoc("IRmanufacturers",t).then((function(t){n(t)}),(function(t){n(t)}))}))},t.prototype.getIRManufacturers=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.rootdatabase().getDocsByFields("IRmanufacturers",{type:{$eq:t}},{}).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.publishObservableEventIcons=function(){this.subjecticons.next(this.icons)},t.prototype.observableLocalIcons=function(){return this.subjecticons},t.prototype.getObservableLocalIcons=function(){var t=this;return new c.Observable((function(e){t.observableLocalIcons().subscribe((function(t){e.next(t)})),t.publishObservableEventIcons()}))},t.prototype.getlocalIcon=function(t){for(var e=0;e<this.icons.length;e++)if(this.icons[e]._id===t)return this.icons[e];return null},t.prototype.getlocalIcons=function(){return this.icons},t.prototype.refreshLocalIcons=function(){var t=this;return new Promise((function(e){t.getIcons().then((function(){e(null)}))}))},t.prototype.addIcon=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("icons",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateIcon=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("icons",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteIcon=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("icons",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getIcon=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("icons",t).then((function(t){n(t)}))}))},t.prototype.getIcons=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("icons").then((function(n){t.icons=new Array,t.icons=n,e(n)}),(function(t){n(t)}))}))},t.prototype.publishObservableEventAppSettingNameStations=function(){this.subjectappsettingstations.next()},t.prototype.observableLocalAppSettingNameStations=function(){return this.subjectappsettingstations},t.prototype.getObservableLocalAppSettingNameStations=function(){var t=this;return new c.Observable((function(e){t.observableLocalAppSettingNameStations().subscribe((function(){for(var n=new Array,o=0;o<t.appsettingstations.length;o++)n.push(t.appsettingstations[o].appsetting_name);e.next(n)})),t.publishObservableEventAppSettingNameStations()}))},t.prototype.getLocalAppSettingNameStations=function(){for(var t=new Array,e=0;e<this.appsettingstations.length;e++)t.push(this.appsettingstations[e].appsetting_name);return t},t.prototype.getLocalAppSettingNameStation=function(t){for(var e={},n=0;n<this.appsettingstations.length;n++)if(this.appsettingstations[n].appsetting_name===t){delete(e=Object.assign({},this.appsettingstations[n]))._id,delete e.appsetting_name;break}return e},t.prototype.getLocalAppSettingStation=function(t){for(var e=0;e<this.appsettingstations.length;e++)if(this.appsettingstations[e]._id===t)return this.appsettingstations[e];return null},t.prototype.refreshLocalAppSettingNameStations=function(){return new Promise((function(t,e){t(null)}))},t.prototype.getAppSettingStations=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocsByFields("appsettingstations",{uuid:{$eq:t.hwinfo.uuid}},{},{},0).then((function(n){n.length>0&&(t.appsettingstations=n),e(null)}),(function(t){n(t)}))}))},t.prototype.updateAppSettingNameStation=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().getDocsByFields("appsettingstations",{appsetting_name:{$eq:t},uuid:{$eq:n.hwinfo.uuid}},{},{},0).then((function(a){if(a.length>0)n.vhmongo_firebase.database().updateDoc("appsettingstations",a[0]._id,e).then((function(t){o(t)}),(function(t){i(t)}));else{var s=Object.assign({},e);s.appsetting_name=t,s.uuid=n.hwinfo.uuid,n.vhmongo_firebase.database().addDoc("appsettingstations",s).then((function(){o(!0)}),(function(t){i(t)}))}}))}))},t.prototype.deleteAppSettingNameStation=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("appsettingstations",{appsetting_name:{$eq:t},uuid:{$eq:e.hwinfo.uuid}},{},{},0).then((function(t){t.length>0?e.vhmongo_firebase.database().deleteDoc("appsettingstations",t[0]._id).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}))}))},t.prototype.getlocalScript=function(t){for(var e=0;e<this.scripts.length;e++)if(this.scripts[e]._id===t)return this.scripts[e];return null},t.prototype.getlocalScripts=function(){return this.scripts},t.prototype.refreshLocalScripts=function(){var t=this;return new Promise((function(e){t.getScripts().then((function(){e(null)}))}))},t.prototype.addScript=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("scripts",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateScript=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("scripts",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteScript=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("scripts",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getScript=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("scripts",t).then((function(t){n(t)}))}))},t.prototype.getScripts=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("scripts").then((function(n){t.scripts=new Array,t.scripts=n,e(n)}),(function(t){n(t)}))}))},t.prototype.getlocalScript_detail=function(t){for(var e=0;e<this.script_details.length;e++)if(this.script_details[e]._id===t)return this.script_details[e];return null},t.prototype.getlocalScript_details=function(){return this.script_details},t.prototype.refreshLocalScript_details=function(){var t=this;return new Promise((function(e){t.getScript_details().then((function(){e(null)}))}))},t.prototype.addScript_detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("script_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateScript_detail=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("script_details",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteScript_detail=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().deleteDoc("script_details",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getScript_detail=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("script_details",t).then((function(t){n(t)}))}))},t.prototype.getScript_details=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("script_details").then((function(n){t.script_details=new Array,t.script_details=n,e(n)}),(function(t){n(t)}))}))},t}();X.decorators=[{type:e.Injectable}],X.ctorParameters=function(){return[{type:o.Vhmongo_firebase},{type:V},{type:F},{type:L}]};var tt=function(){function t(t){this.http=t}return t.prototype.getTranslation=function(t){var e=this,n="assets/i18n/"+t+".json";return new c.Observable((function(t){e.http.get(n).subscribe((function(e){t.next(e),t.complete()}),(function(t){}))}))},t}();tt.decorators=[{type:e.Injectable}],tt.ctorParameters=function(){return[{type:D.HttpClient}]};var et=function(){function t(t){this.translate=t}return t.prototype.list=function(){return[{id:"vn",name:"Vietnamese",icon:"assets/icon/vn.svg"},{id:"en",name:"English",icon:"assets/icon/en.svg"}]},t.prototype.get=function(){return JSON.parse(localStorage.getItem("vh_language")).id},t.prototype.set=function(t){this.translate.use(t),localStorage.setItem("vh_language",JSON.stringify(this.list().filter((function(e){return e.id==t}))[0]))},t.prototype.syncExistedLanguage=function(){var t=localStorage.getItem("vh_language");t?this.translate.use(JSON.parse(t).id):(this.translate.setDefaultLang("en"),localStorage.setItem("vh_language",JSON.stringify({id:"en",name:"English",icon:"assets/icon/en.svg"})))},t}();et.decorators=[{type:e.Injectable}],et.ctorParameters=function(){return[{type:P.TranslateService}]};var nt=function(){function t(t){this.bluetoothSerial=t,this.socketId=0,this.win=window,this.device=new Array,this.ESC="",this.GS="",this.InitializePrinter=this.ESC+"@",this.BoldOn=this.ESC+"E",this.BoldOff=this.ESC+"E\0",this.DoubleHeight=this.GS+"!",this.DoubleWidth=this.GS+"!",this.DoubleOn=this.GS+"!",this.DoubleOff=this.GS+"!\0",this.PrintAndFeedMaxLine=this.ESC+"Jÿ",this.TextAlignLeft=this.ESC+"a0",this.TextAlignCenter=this.ESC+"a1",this.TextAlignRight=this.ESC+"a2",this.commend=this.ESC+"t19",this.cutpaper=this.GS+"V",this.whiteblackmode=this.GS+"B",this.leftmargin=this.GS+"Lāā",this.bitmap=this.ESC+"*\0Đ0100\0",this.font=this.ESC+"M0",this.linefeed=this.ESC+"LF",this.dots=this.ESC+"4A 20"}return t.prototype.BluetoothSerialPrinter=function(){var t=this;return{search:function(){return t.bluetoothSerial.list()},printInvoice:function(e,n){return new Promise((function(o,i){var a={bgcolor:"white",height:n.clientHeight,width:n.clientWidth,size:e.size};$.default.toJpeg(n,a).then((function(n){t.encodeCommand(n,a).then((function(n){var i,a=t.useEscPrintImage(n),s=(i=e.address,t.bluetoothSerial.connect(i)).subscribe((function(e){t.bluetoothSerial.write(a).then((function(t){s.unsubscribe(),o(null)}),(function(t){console.log("WRITE FAILED",t),o(null)}))}),(function(t){console.log("CONNECTION ERROR",t)}))}))}))}))}}},t.prototype.IPSerialPrinter=function(){var t=this;return{printInvoice:function(e,n){return new Promise((function(o){var i=0,a=setInterval((function(){i++,chrome.sockets.tcp.create((function(i){if(!t.socketId){t.socketId=i.socketId;var s=setTimeout((function(){clearTimeout(s),chrome.sockets.tcp.connect(i.socketId,e.ip,e.port,(function(i){if(!i){clearInterval(a);var s={bgcolor:"white",height:n.clientHeight,width:n.clientWidth,size:e.size};$.default.toJpeg(n,s).then((function(e){t.encodeCommand(e,s).then((function(e){var n=t.useEscPrintImage(e);t.rawPrint(t.socketId,n).then((function(){var e=new Uint8Array(8);e.set([29,86,1,0,0,0,0,0],0),t.rawPrint(t.socketId,e).then((function(){new Promise((function(e){chrome.sockets.tcp.disconnect(t.socketId,(function(t){e(t)}))})).then((function(){t.socketId=0,o(!0)}))}))}))}))}))}}))}),1e3)}})),i>16&&(clearInterval(a),o(!1))}),500)}))}}},t.prototype.getImageData=function(t,e){if(0!=t.width||0!=t.height){(e=e||{}).x=e.x||0,e.y=e.y||0,e.width="number"==typeof e.width?e.width:t.width,e.height="number"==typeof e.height?e.height:t.height;var n,o=document.createElement("canvas"),i=o.getContext("2d");o.width=e.width,o.height=e.height,i.drawImage(t,e.x,e.y,e.width,e.height,0,0,e.width,e.height);try{n=i.getImageData(0,0,e.width,e.height)}catch(t){throw t}return n}},t.prototype.rawPrint=function(t,e){return new Promise((function(n,o){chrome.sockets.tcp.send(t,e.buffer,(function(t){n(t)}))}))},t.prototype.useEscPrintImage=function(t){var e=this.getImageData(t,0);this.threshold(e,"");var n=this.rgbToPixel(e.data),o=t.width,i=t.height,a=this.toEscPrintData(n,o,i);return this.printImage(0,o,i,a)},t.prototype.rgbToPixel=function(t){for(var e=[],n=0;n<t.length;n+=4){var o=t[n],i=t[n+1],a=t[n+2],s=(t[n+3]<<24)+(o<<16)+(i<<8)+a;e.push(s)}return e},t.prototype.threshold=function(t,e){null==e&&(e=180),e=180;for(var n=0;n<t.data.length;n+=4){var o=.299*t.data[n]+.587*t.data[n+1]+.114*t.data[n+2]<e?0:255;t.data.fill(o,n,n+3)}},t.prototype.toEscPrintData=function(t,e,n){for(var o=Math.floor((e+7)/8),i=new Array(o*n),a=0;a<n;a++)for(var s=0;s<8*o;s++)s<e?(16711680&t[a*e+s])>>16!=0?i[Math.floor(a*o+s/8)]|=1<<7-s%8:i[Math.floor(a*o+s/8)]&=-2<<7-s%8:s>=e&&(i[Math.floor(a*o+s/8)]|=1<<7-s%8);for(var r=0;r<i.length;r++)i[r]=~i[r];return i},t.prototype.encodeCommand=function(t,e){return new Promise((function(n,o){var i=document.createElement("canvas"),a=i.getContext("2d"),s=new Image,r=568;"K57"==e.size?r=400:"K80"==e.size?r=600:"A4"!=e.size&&"A5"!=e.size||(r=1500),s.onload=function(){i.width=r,i.height=e.height*r/e.width+100,a.drawImage(s,0,0,r,e.height*r/e.width),n(i)},s.src=t}))},t.prototype.PrintAndFeedLine=function(t){return this.ESC="",t>255&&(t=255),t<0&&(t=0),this.ESC+"J"+String.fromCharCode(t)},t.prototype.CutAndFeedLine=function(t){return this.ESC="",void 0===t?this.ESC+"V1":(t>255&&(t=255),t<0&&(t=0),this.ESC+"V"+String.fromCharCode(t))},t.prototype.printAndFeedLine=function(t){return t>255&&(t=255),t<0&&(t=0),this.ESC+"J"+String.fromCharCode(t)},t.prototype.cutAndFeedLine=function(t){return void 0===t?this.ESC+"V1":(t>255&&(t=255),t<0&&(t=0),this.ESC+"V66"+String.fromCharCode(t))},t.prototype.printImage=function(t,e,n,o){var i=Math.floor((e+7)/8%256),a=Math.floor((e+7)/8/256),s=Math.floor(n%256),r=Math.floor(n/256),l=new Uint8Array(o.length+8);return l.set([29,118,48,1&t,i,a,s,r],0),l.set(o,8),l},t}();nt.decorators=[{type:e.Injectable}],nt.ctorParameters=function(){return[{type:q.BluetoothSerial}]};var ot=function(){function t(t,e){this.mqttService=t,this.wifiWizard2=e,this.boolean=!0}return t.prototype.callbackTopic=function(t,e){return void 0===e?this.mqttService.observe(t):this.mqttService.observe(t+e)},t.prototype.publish=function(t,e,n){void 0===n?this.mqttService.unsafePublish(t,e,{qos:1,retain:!1}):this.mqttService.unsafePublish(t+n,e,{qos:1,retain:!1})},t.prototype.startESPsmartconfig=function(t){var e=this;return new Promise((function(n,o){e.wifiWizard2.getConnectedBSSID().then((function(i){esptouch.start(t.ssid,i,t.password,"1","1",(function(t){var o="";t.bssid?(""===(o=e.getIotID(t.bssid))&&console.log("vui lòng 1, báo với anh Huy lỗi này startESPsmartconfig"),n(o)):(""===o&&console.log("vui lòng 2, báo với anh Huy lỗi này startESPsmartconfig"),n(o))}),(function(t){console.log("error",t),o(t)}))}),(function(t){console.log("error1",t),o(t)}))}))},t.prototype.stopESPsmartconfig=function(){return new Promise((function(t,e){esptouch.stop((function(e){console.log("res",e),t(e)}),(function(t){console.log("err",t),e(t)}))}))},t.prototype.getConnectedSSID=function(){var t=this;return new Promise((function(e,n){t.wifiWizard2.getConnectedSSID().then((function(t){e(t)}))}))},t.prototype.getIotID=function(t){var e=t,n="";if(12===e.length){var o=e.slice(0,4),i=parseInt(o,16),a=e.slice(4,8),s=parseInt(a,16),r=e.slice(8,12),l=parseInt(r,16);parseInt(r,16)%2?(i>>>=1,i+=parseInt("8000",16)):i>>>=1,parseInt(o,16)%2?(s>>>=1,s+=parseInt("8000",16)):s>>>=1,parseInt(a,16)%2?(l>>>=1,l+=parseInt("8000",16)):l>>>=1;var c="0000",u="0000",d="0000";1===i.toString(16).length?c="000"+i.toString(16):2===i.toString(16).length?c="00"+i.toString(16):3===i.toString(16).length?c="0"+i.toString(16):4===i.toString(16).length&&(c=i.toString(16)),1===s.toString(16).length?u="000"+s.toString(16):2===s.toString(16).length?u="00"+s.toString(16):3===s.toString(16).length?u="0"+s.toString(16):4===s.toString(16).length&&(u=s.toString(16)),1===l.toString(16).length?d="000"+l.toString(16):2===l.toString(16).length?d="00"+l.toString(16):3===l.toString(16).length?d="0"+l.toString(16):4===l.toString(16).length&&(d=l.toString(16)),"000000000000"===(n=c.slice(0,1)+u+d)&&(n=""),9!=n.length&&(n="")}return n},t}();ot.decorators=[{type:e.Injectable}],ot.ctorParameters=function(){return[{type:g.MqttService},{type:x.WifiWizard2}]};var it=function(){function t(t,e,n,o){this.vhmongo_firebase=t,this.vhQuery=e,this.vhAuth=n,this.vhAlgorithm=o}return t.prototype.getBranch=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("branchs",t).then((function(t){n(t)}))}))},t.prototype.getBranchs=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("branchs").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.getProduct=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("products",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getProductsByFields=function(t,e,n,o){var i=this;return new Promise((function(a,s){i.vhQuery.getDocsByFields("products",t,e,n,o).then((function(t){a(t)}),(function(t){s(t)}))}))},t.prototype.getCategory=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("categorys",t).then((function(t){n(t)}))}))},t.prototype.getCategorys=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("categorys").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.getCategorysByFields=function(t,e,n,o){var i=this;return new Promise((function(a){i.vhQuery.getDocsByFields("categorys",t,e,n,o).then((function(t){a(t)}))}))},t}();it.decorators=[{type:e.Injectable}],it.ctorParameters=function(){return[{type:o.Vhmongo_firebase},{type:V},{type:F},{type:L}]};var at=function(){function t(t,e,n,o){this.vhmongo_firebase=t,this.vhQuery=e,this.vhAuth=n,this.vhAlgorithm=o}return t.prototype.getBranch=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("branchs",t).then((function(t){n(t)}))}))},t.prototype.getBranchs=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("branchs").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.addProduct=function(t){var e=this;return new Promise((function(n,o){1===(null==t?void 0:t.type)?e.getBranchs().then((function(i){t.quantity=0,t.quantity_branch={},i.forEach((function(e){t.quantity_branch[e._id]=0})),e.vhmongo_firebase.database().addDoc("products",t).then((function(t){n(t)}),(function(t){o(t)}))}),(function(t){o(t)})):e.vhmongo_firebase.database().addDoc("products",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateProduct=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("products",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteProduct=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("vhbill_details",{id_product:{$eq:t}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("products",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getProduct=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("products",t).then((function(t){n(t)}))}))},t.prototype.getProductsByFields=function(t,e,n,o){var i=this;return new Promise((function(a){i.vhQuery.getDocsByFields("products",t,e,n,o).then((function(t){a(t)}))}))},t.prototype.addCategory=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("categorys",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateCategory=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("categorys",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteCategory=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("products",{id_category:{$eq:t}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("categorys",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getCategory=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("categorys",t).then((function(t){n(t)}))}))},t.prototype.getCategorys=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("categorys").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.getCategorysByFields=function(t,e,n,o){var i=this;return new Promise((function(a){i.vhQuery.getDocsByFields("categorys",t,e,n,o).then((function(t){a(t)}))}))},t}();at.decorators=[{type:e.Injectable}],at.ctorParameters=function(){return[{type:o.Vhmongo_firebase},{type:V},{type:F},{type:L}]};var st=function(){function t(t,e,n,o){this.vhmongo_firebase=t,this.vhQuery=e,this.vhAuth=n,this.vhAlgorithm=o}return t.prototype.getBranch=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("branchs",t).then((function(t){n(t)}))}))},t.prototype.getBranchs=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("branchs").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.getProduct=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDoc("products",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.getProductsByFields=function(t,e,n,o){var i=this;return new Promise((function(a,s){i.vhQuery.getDocsByFields("products",t,e,n,o).then((function(t){a(t)}),(function(t){s(t)}))}))},t.prototype.getCategory=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("categorys",t).then((function(t){n(t)}))}))},t.prototype.getCategorys=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("categorys").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.getCategorysByFields=function(t,e,n,o){var i=this;return new Promise((function(a){i.vhQuery.getDocsByFields("categorys",t,e,n,o).then((function(t){a(t)}))}))},t}();st.decorators=[{type:e.Injectable}],st.ctorParameters=function(){return[{type:o.Vhmongo_firebase},{type:V},{type:F},{type:L}]};var rt=function(){function t(t,e,n,o){this.vhmongo_firebase=t,this.vhQuery=e,this.vhAuth=n,this.vhAlgorithm=o,this.products=new Array}return t.prototype.getlocalProductAndCombosAndToppings=function(t){for(var e=new Array,n=0;n<this.products.length;n++){if(this.products[n]._id===t&&(e.push(Object.assign({},this.products[n])),null!=this.products[n].subs)){var o=E(this.products[n].subs);e[e.length-1].subs=new Array,o.forEach((function(t){e[e.length-1].subs.push(Object.assign({},t))}))}if(null!=this.products[n].combos)for(var i=0;i<this.products[n].combos.length;i++)if(this.products[n].combos[i].id_product===t){e.push(Object.assign({},this.products[n]));break}if(null!=this.products[n].toppings)for(i=0;i<this.products[n].toppings.length;i++)if(this.products[n].toppings[i].id_product===t){e.push(Object.assign({},this.products[n]));break}}return e},t.prototype.getlocalProduct=function(t){for(var e=function(e){if(n.products[e]._id===t){var o=Object.assign({},n.products[e]);if(null!=o.subs){var i=E(o.subs);o.subs=new Array,i.forEach((function(t){o.subs.push(Object.assign({},t))}))}if(null!=o.toppings){var a=E(o.toppings);o.toppings=new Array,a.forEach((function(t){o.toppings.push(Object.assign({},t))}))}if(null!=o.combos){var s=E(o.combos);o.combos=new Array,s.forEach((function(t){o.combos.push(Object.assign({},t))}))}return{value:o}}},n=this,o=0;o<this.products.length;o++){var i=e(o);if("object"==typeof i)return i.value}return null},t.prototype.getBranch=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("branchs",t).then((function(t){n(t)}))}))},t.prototype.getBranchs=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("branchs").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.addProduct=function(t){var e=this;return new Promise((function(n,o){3===(null==t?void 0:t.type)?e.getBranchs().then((function(i){t.quantity=0,t.quantity_branch={},i.forEach((function(e){t.quantity_branch[e._id]=0})),e.vhmongo_firebase.database().addDoc("products",t).then((function(t){n(t)}),(function(t){o(t)}))}),(function(t){o(t)})):e.vhmongo_firebase.database().addDoc("products",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.addSubsProduct=function(t,e){var n=this;return new Promise((function(o,i){for(var a=new Array,s=0;s<e.length;s++)a[s]=Object.assign(Object.assign({},e[s]),{_id:n.vhAlgorithm.ObjectId()});n.vhmongo_firebase.database().getDoc("products",t).then((function(e){if(e){void 0===e.subs&&(e.subs=new Array);var i=E(e.subs,a);n.vhmongo_firebase.database().updateDoc("products",t,{subs:i}).then((function(){o(a)}),(function(t){o(null)}))}else o(null)}))}))},t.prototype.updateSubProduct=function(t,e,n){var o=this;return new Promise((function(i,a){o.vhmongo_firebase.database().getDoc("products",t).then((function(t){t||i(!1),void 0===t.subs&&i(!1);for(var s=-1,r=0;r<t.subs.length;r++)if(t.subs[r]._id===e){s=r;break}-1===s?i(!1):(t.subs[s]=Object.assign(Object.assign({},t.subs[s]),n),o.vhmongo_firebase.database().updateDoc("products",t._id,{subs:t.subs}).then((function(t){i(t)}),(function(t){a(t)})))}))}))},t.prototype.deleteSubProduct=function(t,e){var n=this;return new Promise((function(o,i){var a=new Array;n.getlocalProductAndCombosAndToppings(t).forEach((function(t){a.push(t._id)})),1===a.length?n.vhmongo_firebase.database().getDocsByFields("vhbill_details",{id_subproduct:{$eq:e}},{},{},1).then((function(a){if(0===a.length){var s=n.getlocalProduct(t);if(null!=s.subs)for(var r=0;r<s.subs.length;r++)if(s.subs[r]._id===e){s.subs.splice(r,1),n.vhmongo_firebase.database().updateDoc("products",s._id,{subs:s.subs}).then((function(t){o(t)}),(function(t){i(t)}));break}}else o(!1)}),(function(t){i(t)})):(console.log("Bạn không thể xóa, vì sản phẩm đang liên kết với sản phẩm khác"),o(!1))}))},t.prototype.updateProduct=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("products",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteProduct=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("vhbill_details",{id_product:{$eq:t}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("products",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getProduct=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("products",t).then((function(t){n(t)}))}))},t.prototype.getProductsByFields=function(t,e,n,o){var i=this;return new Promise((function(a){i.vhQuery.getDocsByFields("products",t,e,n,o).then((function(t){i.products=JSON.parse(JSON.stringify(t)),a(t)}))}))},t.prototype.addCategory=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().addDoc("categorys",t).then((function(t){n(t)}),(function(t){o(t)}))}))},t.prototype.updateCategory=function(t,e){var n=this;return new Promise((function(o,i){n.vhmongo_firebase.database().updateDoc("categorys",t,e).then((function(t){o(t)}),(function(t){i(t)}))}))},t.prototype.deleteCategory=function(t){var e=this;return new Promise((function(n,o){e.vhmongo_firebase.database().getDocsByFields("products",{id_category:{$eq:t}},{},{},1).then((function(i){0===i.length?e.vhmongo_firebase.database().deleteDoc("categorys",t).then((function(t){n(t)}),(function(t){o(t)})):n(!1)}),(function(t){o(t)}))}))},t.prototype.getCategory=function(t){var e=this;return new Promise((function(n){e.vhmongo_firebase.database().getDoc("categorys",t).then((function(t){n(t)}))}))},t.prototype.getCategorys=function(){var t=this;return new Promise((function(e,n){t.vhmongo_firebase.database().getDocs("categorys").then((function(t){e(t)}),(function(t){n(t)}))}))},t.prototype.getCategorysByFields=function(t,e,n,o){var i=this;return new Promise((function(a){i.vhQuery.getDocsByFields("categorys",t,e,n,o).then((function(t){a(t)}))}))},t}();rt.decorators=[{type:e.Injectable}],rt.ctorParameters=function(){return[{type:o.Vhmongo_firebase},{type:V},{type:F},{type:L}]};var lt=function(){function t(){}return t.prototype.transform=function(t,e,n,o,i){return void 0===e&&(e="VND"),void 0===n&&(n="symbol"),void 0===o&&(o=""),void 0===i&&(i="en-VI"),_.formatCurrency(t,i,"",e,o)},t}();lt.decorators=[{type:e.Pipe,args:[{name:"vhcurrency"}]}];var ct=function(){function t(){}return t.prototype.transform=function(t,e,n,o,i){return void 0===e&&(e="en-VI"),void 0===n&&(n=""),void 0===o&&(o="symbol"),void 0===i&&(i="4.0-0"),_.formatCurrency(t,e,_.getCurrencySymbol(n,"wide"),n,i)},t}();ct.decorators=[{type:e.Pipe,args:[{name:"vhcurrencyunit"}]}];var ut=function(){function t(){}return t.prototype.transform=function(t,e,n){return void 0===e&&(e="en-VI"),void 0===n&&(n="1.2-2"),_.formatPercent(t,e,n)},t}();ut.decorators=[{type:e.Pipe,args:[{name:"vhpercent"}]}];var dt=function(){function t(t){this.dom=t}return t.prototype.transform=function(t,e){return this.dom.bypassSecurityTrustResourceUrl(e+t)},t}();dt.decorators=[{type:e.Pipe,args:[{name:"vhlink"}]}],dt.ctorParameters=function(){return[{type:p.DomSanitizer}]};var _t=function(){function t(t){this.dom=t}return t.prototype.transform=function(t){return this.dom.bypassSecurityTrustResourceUrl("https://www.youtube.com/embed/"+t)},t}();_t.decorators=[{type:e.Pipe,args:[{name:"vhyoutubelink"}]}],_t.ctorParameters=function(){return[{type:p.DomSanitizer}]};var pt=function(){function t(){}return t.prototype.transform=function(t,e,n){void 0===e&&(e=""),void 0===n&&(n="en-VI");var o="";if("time"===e)o="HH:mm:ss";else if("date"===e)o="dd/MM/YYYY";else{if("datetime"!==e)return"wrong format";o="dd/MM/YYYY HH:mm:ss"}return _.formatDate(t,o,"en-VI")},t}();pt.decorators=[{type:e.Pipe,args:[{name:"vhdate"}]}];var bt=function(){function t(){}return t.prototype.ngOnInit=function(){},t}();bt.decorators=[{type:e.Component,args:[{selector:"lib-ionic-vhframeworks",template:"\n <p>\n ionic-vhframeworks works!\n </p>\n "}]}],bt.ctorParameters=function(){return[]};var ft=function(){};ft.decorators=[{type:e.NgModule,args:[{declarations:[bt,z,M,T,N,R,dt,lt,ct,ut,_t,pt],imports:[],exports:[bt,z,M,T,N,R,dt,lt,ct,ut,_t,pt]}]}],t.DefaultLanguage=et,t.HttpLoaderFactory=tt,t.IonicVhframeworksComponent=bt,t.IonicVhframeworksModule=ft,t.VhAlgorithm=L,t.VhAuth=F,t.VhCamPlaybackComponent=z,t.VhCameraH265Ccomponent=T,t.VhCameraIMGcomponent=R,t.VhCameraJSMPEGCcomponent=N,t.VhCameraMSEVcomponent=M,t.VhCurrencyPipe=lt,t.VhCurrencyUnitPipe=ct,t.VhDate=pt,t.VhDriver=nt,t.VhEcommerce=G,t.VhForFirstTime=I,t.VhImage=U,t.VhLinkPipe=dt,t.VhMqttService=ot,t.VhPercentPipe=ut,t.VhQuery=V,t.VhQueryCafe=W,t.VhQueryCafeWebAdmin=rt,t.VhQueryCafeWebUser=st,t.VhQueryCare=Q,t.VhQueryCloudCam=J,t.VhQueryClouds=H,t.VhQuerySCclient=Z,t.VhQuerySales=Y,t.VhQuerySalesWebAdmin=at,t.VhQuerySalesWebUser=it,t.VhQuerySecurityCam=K,t.VhQuerySmhome=X,t.VhYoutubeLinkPipe=_t,t.vhDate=B,Object.defineProperty(t,"__esModule",{value:!0})}));
2
2
  //# sourceMappingURL=ionic-vhframeworks.umd.min.js.map