1"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[6244],{39252(t,e,i){i.d(e,{$X:()=>n,iU:()=>a,nX:()=>o});const a={longTermContracts:"longTermRental",shortTermContracts:"shortTermRental",maintenanceContracts:"maintenance",leasingContracts:"leasing",subscriptionContracts:"subscription"},s=(new Date).toISOString().split("T")[0],r={all:{$or:[{status:{$ne:"inProgress"}},{status:"inProgress",startDate:{$lte:s}}],status:{$notIn:["cart"]}},quote:{status:"quote"},validated:{$or:[{status:{$in:["validated","contractValidated","toPrepare"]}},{status:"inProgress",startDate:{$gt:s}}]},bookingRequest:{status:{$in:["bookingRequest"]}},inProgress:{status:"inProgress",startDate:{$lte:s}},completed:{status:{$in:["completed","completedInvoiced","waintingReturn"]}}};function n(t,e){return{...r[t],type:e}}function o(){return r}},64005(t,e,i){i.d(e,{default:()=>p});var a=i(17243),s=i(42689),r=i(99489),n=i(26681),o=i(78762),l=i(39252),c=i(20188),d=i(54266);const h=window.blg||{},g="contract/contract";class u extends c.A{constructor(...t){super(...t),this.renderData={},this.pagination=new r.A(this._data.options.currentPage,this._data.options.pagination),this.scrollPosition=0,this.objectDescription={contract:{location:g,field:["id","reference","tag","type"]},company:{location:"crm/company"}},this.orderMap={"date-desc":{field:"id",isAsc:!1},"date-asc":{field:"id",isAsc:!0},reference:{field:"reference",isAsc:!0},"amount-desc":{field:"amountTotal",isAsc:!1},"amount-asc":{field:"amountTotal",isAsc:!0},delivery:{field:"delivery.companyName",isAsc:!0}},this.filterMap=(0,l.nX)(),"infinite-scroll"===a.get(this._data,"options.paginationMode")&&(this.loading=!1)}async initialize(){if(super.initialize(),this._serviceHandler.getUserService().getUserToken()){this.rentConfig=this.getConfigByKey("defaultRentConfig");const t=this._serviceHandler.getTwigHelper();t.register(this._data.templates);const e=this._serviceHandler.getTemplateHelper();this._root.addClass("loading"),this._setupInitialFilter(),this._setupInitialOrder(),await this.getData(),this.renderData={modulePath:this._data.path,count:this._data.contracts?.count||null,data:this._data.contracts?.results||null,moduleConfig:this.config,configs:{defaultRentConfig:this.rentConfig},templates:this._data.templates||null,options:this._data.options||null,userCanSeePrices:this._data.userCanSeePrices,orderMap:this.orderMap,filterMap:this.filterMap,yearFilters:await this._getYearFilterYears(),format:this.format.bind(this),isDelivered:this.isDelivered.bind(this),isInvoiced:this.isInvoiced.bind(this),getCurrentFilter:this.getCurrentFilter.bind(this),getObjectTitle:e.getObjectTitle.bind(e),stringifyAttribute:e.stringifyAttribute.bind(e),userInfo:this._serviceHandler.getUserService().getUserInfo(),round:e.round.bind(e),requirementTypeList:this._getRequirementTypeList(),currentYearFilter:this._data.options.yearFilter||this._yearFilter,visibleFilters:this._data.visibleFilters,currentOrderFilter:this._data.options.currentOrderFilter||this.order,currentOrder:this._data.options.order||this.currentOrder,pagination:{currentPage:this.pagination.getCurrentPage(),lastPage:this.pagination.getLastPage(),hasPrevPage:this.pagination.hasPrevPage(),hasNextPage:this.pagination.hasNextPage()},getPictureUrl:this._getPictureUrl.bind(this)};const i=this.renderTwig(t,"ContractList",this.renderData,this._translations);this._root.removeClass("loading"),this._root.append(i),this._root.find(".js-contract-order").val(this.currentOrder),this._root.find(".js-contract-filter").val(this.currentFilter),this._setupEvents()}else this._serviceHandler.getUserService().loginRedirect(window.location)}_setupEvents(){const t=this._serviceHandler.getTemplateHelper();if(window.blg.getServiceOnLoad("pdfViewer",t=>{t.setupEvents()}),this._data.options.templateData.contractContactRequest&&(window.blg.getServiceOnLoad("formModal",t=>{t.setupEvents()}),d(".blgModFormFormModal").off("needRefresh").on("needRefresh",this._updateList.bind(this))),"simple-page-nav"===a.get(this._data,"options.paginationMode")&&this._root.find(".js-change-page").off().on("click",async e=>{this._root.find(".js-change-page").off("click");const i=e.currentTarget.getAttribute("js-target-page");this.pagination=new r.A(i,this._data.options.pagination);const a=new URL(window.location.href);a.searchParams.set("page",i),window.history.replaceState(null,null,a),await this._updateList(!0),this._updatePageBrowser(),t.scrollToTop()}),d(window).off("scroll").on("scroll",()=>{if("infinite-scroll"===a.get(this._data,"options.paginationMode")&&this._amendList(),a.get(this._data,"options.backToTop")){const t=this._root.find(".js-back-to-top");d(window).scrollTop()>200?t.hasClass("visible")||t.addClass("visible"):d(window).scrollTop()<200&&t.hasClass("visible")&&t.removeClass("visible")}}),a.get(this._data,"options.backToTop")&&this._root.find(".js-back-to-top").off("
1click").on("click",t.scrollToTop),a.get(this._data,"options.orderSelector")){const e=this._root.find(".js-contract-order");e.off("change").on("change",async()=>{e.off("click"),this._setOrder(e.val()),await this._updateList(!0),t.scrollToTop()})}if("select"===a.get(this._data,"options.filterSelector")){const e=this._root.find(".js-contract-filter");e.off("change").on("change",async()=>{e.off("click"),this._setFilter(e.val()),await this._updateList(!0),t.scrollToTop()})}if("tabs"===a.get(this._data,"options.filterSelector")){const e=this._root.find(".js-contract-filter-tab");e.off("click").on("click",async i=>{e.off("click"),this._setFilter(i.target.getAttribute("value")),await this._updateList(!0),e.removeClass("active-tab"),i.target.classList.add("active-tab"),t.scrollToTop()})}const e=this._root.find(".js-contract-year-filter");e.off("change").on("change",async i=>{e.off("click"),this._setYearFilter(d(i.target).val()),await this._updateList(!0),t.scrollToTop()}),this._root.find(".js-contract-search").off("input").on("input",a.debounce(async function(){this.pagination=new r.A(1,this._data.options.pagination);const t=new URL(window.location.href);t.searchParams.delete("page"),window.history.replaceState(null,null,t),this._root.find(".js-contract-search").val().length>=0&&await this._updateList(!0)}.bind(this),500));const i=this._root.find(".js-mode-btn"),s=this._root.find(".js-infinite-scroll");d(i).off("click").on("click",t=>{d(i).removeClass("active"),d(t.target).addClass("active"),d(s).toggleClass("single-row",d(t.target).hasClass("js-mode-row"))});const n=d(document).find(".mainTemplate"),o=this._root.find("#filterBox");d(o).on("hide.bs.modal",function(){n.removeClass("modalOpen")}),d(o).on("show.bs.modal",function(){n.addClass("modalOpen")})}async _getYearFilterYears(){const t=this._serviceHandler.getApiClient(),e=await t.getFirstObjectBy(g,{order:["id","asc"],limit:1,field:["createdAt"],filter:{createdAt:{$isNull:!1}}}),i=e?s(e.createdAt).year():s().year(),a=s().year(),r=[];for(let t=i;t<=a;t++)r.push(t);return r.reverse()}_setupInitialFilter(){this._yearFilter=null;const t=new URL(window.location.href),{pathname:e}=t,i=["all",...this.getConfigByKey("defaultContractConfig")[`${"/subscribe"===e?"subscription":a.camelCase(e)}Statuses`]];this._data.visibleFilters=i,this._setFilter(this._data.options.filter||"all",!0),this._data.options.yearFilter&&this._setYearFilter(this._data.options.yearFilter)}_setupInitialOrder(){const t=this._data.options.order||this._data.options.defaultOrder;this._setOrder(t)}async getData(){const t=this._serviceHandler.getApiClient(),e=this._root.find(".js-contract-search"),i={filter:{$and:[{extranetDiffusion:!0}]},"with-count":!0,field:["id"]};if(this.filter&&i.filter.$and.push(this.filter),this._yearFilter&&i.filter.$and.push(this._yearFilter),e&&d(e).val()){const a=d(e).val(),s=await t.search({searchString:a,paths:["contract/contract","partner/company"]}),r=s.filter(t=>"company"===t.target?.objectName).map(t=>t.data.id);i.filter.$and=[...i.filter.$and,{$or:[{id:{$in:s.filter(t=>"contract"===t.target?.objectName).map(t=>t.data.id)}},{delivery:{id:{$in:r}}},{emitter:{id:{$in:r}}}]}]}this._data.options.tagsToDisplay&&(i.field=[...i.field||[],"tags.tag.name","tags.tag.title","tags.tag.tagCategory.name"],i.join=[...i.join||[],"tags.tag.tagCategory"]),this.pagination&&this.pagination.appendApiParameters(i),this.order&&this.order.appendApiParameters(i),this._data.contracts=await t.listObjects(g,i);try{this._data.contracts.results=await Promise.all(this._data.contracts.results.map(async e=>o.mA(t,e.id,this.rentConfig)))}catch(t){console.warn(t)}for(const t of this._data.contracts.results)this._data.options.contactJob&&(t.mailContact=this._getContactByJob(t.emitter?.contacts)||t.emitterContact,t.mailContact.companyForActivity=t.emitter.crmId),this._data.options.tagsToDisplay&&(t.tagsToDisplay=this._setTagsToDisplay(t.tags)),o.OX(t);const s=[];this._data.contracts.results.map(t=>{t.renewalDuration=null;try{t.renewalDuration=o.bX(t.endDate)}catch(t){console.warn(t)}let e=0;for(const i of t.equipmentRequirements)i.assignments?.length&&e++;this.rentConfig.display.projectedConsumption&&1===e&&s.push(o.I3(t))}),await Promise.all(s),this.pagination.setElemCount(a.get(this,"_data.contracts.count"))}_getContactByJob(t){return t?t.find(t=>t.contact.jobTitle.includes(this._data.options.contactJob))?.contact:null}_setTagsToDisplay(t){const e=this._data.options.tagsToDisplay;return t.map(t=>e.name?.includes(t.tag?.name)||e.category?.includes(t.tag?.tagCategory?.name)?t.tag.name:null).filter(t=>t)}format(t,e,i){return this._serviceHandler.getApiFormater().format(g,t,e,i||null)}isDelivered(t){return t.deliveryStatus}isInvoiced(t){const e=a.filter(t.invoiceDocuments,{internalTag:"normal"}),i=a.filter(t.invoiceDocuments,{internalTag:"draft"});return"partiallyInvoiced"===t.invoiceStatus||e.length&&i.length?"partiallyInvoiced":t.invoiceDocuments.length&&!i.length?"invoiced":"notInvoiced"}getCurrentFilter(){return this.currentFilter}_setOrder(t){if(t){this.currentOrder=t;
1const e=a.chain(this.orderMap).map("field").uniq().value();this.order=new n.A(e,this.orderMap[t].field,this.orderMap[t].isAsc);const i=new URL(window.location.href);i.searchParams.set("order",t),window.history.replaceState(null,null,i)}}_setFilter(t,e=!1){if(t){this.currentFilter=t;const i={maintenance:"maintenance",leasing:"leasing",subscribe:"subscription",long_term:"longTermRental",short_term:"shortTermRental"};this.pagination=new r.A(e?this._data.options.currentPage:1,this._data.options.pagination);const a=new URL(window.location.href);a.searchParams.set("filter",t);const s=a.pathname.replace(/^\/+/g,"");i[s]&&(this.filter=(0,l.$X)(t,i[s])),e||a.searchParams.delete("page"),window.history.replaceState(null,null,a)}}_setYearFilter(t){const e=new URL(window.location.href);if(t)if("past6months"===t){const i=s().subtract(6,"months").format();this._yearFilter={createdAt:{$gte:i}},e.searchParams.set("yearFilter",t)}else{const i=s().year(t).startOf("year").format(),a=s().year(t).endOf("year").format();this._yearFilter={createdAt:{$gte:i,$lte:a}},e.searchParams.set("yearFilter",t)}else this._yearFilter=null,e.searchParams.delete("yearFilter");window.history.replaceState(null,null,e)}async _amendList(){const t=d(window).scrollTop();if(!this.loading&&this.scrollPosition<t){this.scrollPosition=t;const e=this._root.find(".js-infinite-scroll").offset(),i=this._root.find(".js-infinite-scroll").height();(t+d(window).height()-a.get(e,"top"))/i>.8&&this.pagination.getCurrentPage()<this.pagination.getLastPage()&&(this.loading=!0,this.pagination=new r.A(this._data.options.currentPage+1,this._data.options.pagination),await this._updateList(!1),this.loading=!1)}}_getRequirementTypeList(){return a.uniqBy(a.flatten(this._data.contracts.results.map(t=>t.equipmentRequirements)).map(t=>({id:t.requirementType?.id,title:t.requirementType?.title})),"id")}async _updateList(t){t&&this._root.find(".contract-list").empty(),this._root.addClass("loading"),await this.getData(),this.renderData=a.assign(this.renderData,{count:this._data.contracts?.count||null,data:this._data.contracts?.results||null,pagination:{currentPage:this.pagination.getCurrentPage(),lastPage:this.pagination.getLastPage(),hasPrevPage:this.pagination.hasPrevPage(),hasNextPage:this.pagination.hasNextPage()}});const e=this._serviceHandler.getTwigHelper(),i=this.renderTwig(e,"ContractListTab",this.renderData,this._translations);this._root.removeClass("loading"),this._root.find(".contract-list").append(i),this._updatePageBrowser(),this._setupEvents(),a.has(h,["Nav","ConnectedMenu"])&&window.blg.getServiceOnLoad("connectedMenu",t=>{t.hideElementByRight()})}_updatePageBrowser(){if("simple-page-nav"===this._data.options.paginationMode){const t=this._serviceHandler.getTwigHelper(),e=this.renderTwig(t,"pagination",this.renderData,this._translations);this._root.find(".js-page-browser").empty(),this._root.find(".js-page-browser").append(e),this._setupEvents()}}_getPictureUrl(t){return this._data.apiUrl+"/image/"+t+"/small"}}a.set(window,["blg","Extranet","ContractList"],u);const p=u},26681(t,e,i){i.d(e,{A:()=>r});var a=i(17243);class s{constructor(t,e,i){this.allowedOrderFields=t,this.field=e,this.isAsc=i}hasVal(t,e){return this.field===t&&this.isAsc===e}getCurrentSortField(){return this.field}getAvailableFields(){return a.keys(this.allowedOrderFields)}create(t,e,i){s._parseField(t,e);const a=s._parseDirection(i);return new s(t,e,a)}createQueryParams(t,e,i,s="desc"){let r=i,n=s;if(e.has("order")){const t=a.get(e,"order").split("-",3);if(2!==t.length)throw new Error("Bad order string");if(r=t[0],n=t[1],"asc"!==n&&"desc"!==n)throw new Error("Bad order direction");if(!r.match("/^[a-zA-Z]+/"))throw new Error("Bad order field")}return this.create(t,r,n)}static _parseField(t,e){if(t.indexOf(e)>=0)return e;throw new Error('Field "'+e+'" not found')}static _parseDirection(t){if("asc"!==t&&"desc"!==t)throw new Error("Bad order direction");return"asc"===t}getRouteData(){return"date"!==this.field||this.isAsc?{order:this.field+"-"+(this.isAsc?"asc":"desc")}:{}}appendApiParameters(t){const e=this.isAsc?"asc":"desc",i=s._parseField(this.allowedOrderFields,this.field);t.order="price"===i?[[i+".hidden",e],[i+".value",e]]:[i,e]}}a.set(window,["blg","Order"],s);const r=s},99489(t,e,i){i.d(e,{A:()=>r});var a=i(17243);class s{constructor(t=1,e=10){if(this.elemCount=-1,this.currentPage=t,this.elemPerPage=e,this.currentPage<this.getFirstPage())throw new Error('Page "'+this.currentPage+"\" doesn't exist.")}createQueryParams(t,e){let i=1;if(a.has(t,"page")){if(!a.isFinite(a.get(t,"page")))throw new Error("Bad page");if(i=parseInt(a.get(t,"page"),10),i<=0)throw new Error("Bad page")}return new s(i,e)}setElemCount(t){this.elemCount=t,this._checkData()}appendApiParameters(t){return t.first=(this.getCurrentPage()-this.getFirstPage())*this.getElemPerPage(),t.limit=this.getElemPerPage(),t}getElemCount(){if(-1===this.elemCount)throw new Error("getElementCount before setElemCount");return this.elemCount}getElemPerPage(){return this.elemPerPage}getCurrentPage(){return this.currentPage}getPageCount(){return a.max([a.ceil(this.getElemCount()/this.getElemPerPage()),1])}getLastPage(){return this.getPageCount()}getFirstPage(){return 1}hasPrevPage(){return this.currentPage>this.getFirstPage()}hasNextPage(){return this.currentPage<this.getLastPage()}getRouteData(){return 1===this.getCurrentPage()?[]:{page:this.getCurrentPage()}}getPrevPage(){return 2===this.currentPage?null:this.currentPage-1}getNextPage(){return this.currentPage+1}_checkData(){if(this.currentPage<this.getFirstPage()||this.currentPage>this.getLastPage())throw new Error('Page "'+this.currentPage+"\" doesn't exist.")}}a.set(window,["blg","Pagination"],s);const r=s}}]); 2//# sourceMappingURL=Extranet-ContractList-js-ContractList-js.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.