Created
July 14, 2020 18:24
-
-
Save mushfiqweb/6366ae0244870c05cdd0329066e6a9d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (setSearchView === "searchtenant") { | |
| inQuery.push({ Building: { $in: buildingId } }); | |
| orQuery.push({ | |
| "CompanyTBL.TenantNumber": { $regex: text, $options: "i" } | |
| }); | |
| orQuery.push({ | |
| TenantName: { $regex: text, $options: "i" } | |
| }); | |
| orQuery.push({ | |
| "InventoryBuilding.BuildingName": { $regex: text, $options: "i" } | |
| }); | |
| orQuery.push({ | |
| "InventoryBuilding.BuildingNumber": { $regex: text, $options: "i" } | |
| }); | |
| /** Joining other two tables with main table */ | |
| query.push(JSON.stringify({ | |
| $lookup: { | |
| from: UserStore.getAppName() + "_" + "Inventory_Building", | |
| localField: "Building", | |
| foreignField: "Did", | |
| as: "InventoryBuilding" | |
| } | |
| })); | |
| query.push(JSON.stringify({ | |
| $lookup: { | |
| from: UserStore.getAppName() + "_" + "Company", | |
| localField: "CompanyId", | |
| foreignField: "Did", | |
| as: "CompanyTBL" | |
| } | |
| })); | |
| query.push(JSON.stringify({ | |
| $lookup: { | |
| from: UserStore.getAppName() + "_" + "QRCOI_Setup", | |
| localField: "CompanyId", | |
| foreignField: "TenantID", | |
| as: "QRCOISetup" | |
| } | |
| })); | |
| /** matching the text with the columns */ | |
| if (isActive) { | |
| inQuery.push({ "CompanyTBL.IsActive": "1" }) | |
| query.push( | |
| JSON.stringify({ | |
| $match: { $and: [inQuery[0], inQuery[1], { $or: orQuery }] } | |
| }) | |
| ); | |
| } else { | |
| query.push(JSON.stringify({ | |
| $match: { $and: [inQuery[0], { $or: orQuery }] } | |
| }) | |
| ); | |
| } | |
| query.push(JSON.stringify({ | |
| $group: { | |
| _id: { "Did": '$CompanyTBL.Did' }, | |
| "Did": { $first: "$CompanyTBL.Did" }, | |
| "TenantNumber": { $first: "$CompanyTBL.TenantNumber" }, | |
| "TenantName": { $first: "$TenantName" }, | |
| "BuildingNumber": { $first: "$InventoryBuilding.BuildingNumber" }, | |
| "BuildingName": { $first: "$InventoryBuilding.BuildingName" }, | |
| "SetupTenantId": { $first: "$QRCOISetup.TenantID"}, | |
| "IsActive": { $first: "$CompanyTBL.IsActive"} | |
| } | |
| })) | |
| query.push(JSON.stringify({ | |
| $sort: {TenantNumber: 1} | |
| })) | |
| apiHandler.aggregate(JSON.stringify(query), "Company_Building", function (CompanyBuildingData) { | |
| if (CompanyBuildingData.Status === "Success") { | |
| var option = []; | |
| let data = JSON.parse(CompanyBuildingData.Data); | |
| if (obj.props.setSelectedTenantAry) obj.props.setSelectedTenantAry(data); | |
| data.map((val, indx) => { | |
| if (indx < 10) { | |
| if (val.Did.length !== 0) { | |
| let buildingInfo = (val.BuildingNumber[0] && val.BuildingNumber[0].length) ? val.BuildingNumber[0] + ", " + val.BuildingName[0] + ")" : val.BuildingName[0] + ")"; | |
| let newTenant = val.SetupTenantId.length ? "" : <span className="badge pull-right" style={{fontWeight: "normal", fontSize: 10, background: "#17a2b8"}}>new</span>; | |
| let isActive = val.IsActive[0] == "1" ? "" : <span className="badge pull-right" style={{fontWeight: "normal", fontSize: 10, background: "#dc3545"}}>inactive</span>; | |
| let da = { | |
| value: val.Did[0], | |
| label: isOnlyTenantName ? val.TenantName : val.TenantNumber[0] + " (" + val.TenantName + ", " + buildingInfo, | |
| buildingNumber: val.BuildingNumber, | |
| listLabel: isOnlyTenantName ? val.TenantName : <div>{newTenant} {isActive} {val.TenantNumber[0]} ({val.TenantName}, {buildingInfo} </div> | |
| }; | |
| option.push(da); | |
| } | |
| } | |
| }) | |
| if (option.length !== 0) return callBack({ options: option }); | |
| return callBack({ options: [{ value: "", label: "" }] }); | |
| } | |
| }) | |
| } | |
| else if (setSearchView === "searchproppertybuilding") { | |
| inQuery.push({ Did: { $in: buildingId } }); | |
| orQuery.push({ | |
| "InventoryPropertyTBL.Name": { $regex: text, $options: "i" } | |
| }); | |
| orQuery.push({ | |
| BuildingName: { $regex: text, $options: "i" } | |
| }); | |
| query.push(JSON.stringify({ | |
| $lookup: { | |
| from: UserStore.getAppName() + "_" + "Inventory_Property", | |
| localField: "Property", | |
| foreignField: "Did", | |
| as: "InventoryPropertyTBL" | |
| } | |
| })) | |
| query.push( | |
| JSON.stringify({ | |
| $match: { $and: [inQuery[0], { $or: orQuery }] } | |
| }) | |
| ); | |
| query.push(JSON.stringify({ $limit: 10 })); | |
| { $project: { itemDescription: { $concat: ["$item", " - ", "$description"] } } } | |
| query.push( | |
| JSON.stringify({ | |
| $project: { | |
| "Did": "$Did", | |
| "PropertyDid": "$InventoryPropertyTBL.Did", | |
| "Property": "$InventoryPropertyTBL.Name", | |
| "Building": "$BuildingName", | |
| } | |
| }) | |
| ); | |
| query.push(JSON.stringify({ | |
| $sort: {Property: 1} | |
| })); | |
| apiHandler.aggregate(JSON.stringify(query), "Inventory_Building", function (CompanyBuildingData) { | |
| if (CompanyBuildingData.Status === "Success") { | |
| var option = []; | |
| let data = JSON.parse(CompanyBuildingData.Data); | |
| if (obj.props.setSelectedPropertyAry) obj.props.setSelectedPropertyAry(data); | |
| data.map(val => { | |
| let da = { | |
| value: val.PropertyDid[0] + "-" + val.Did, | |
| label: val.Property[0] + " - " + val.Building | |
| }; | |
| option.push(da); | |
| }) | |
| if (option.length !== 0) return callBack({ options: option }); | |
| return callBack({ options: [{ value: "", label: "" }] }); | |
| } | |
| }) | |
| } | |
| else if (setSearchView === "searchfloor") { | |
| var buildingID = otherCondition[0] ? otherCondition[0]["value"] : undefined; | |
| if (buildingID === undefined) { | |
| notify("Please select Building", 3000); | |
| return callBack({ options: [{ value: "", label: "" }] }); | |
| } | |
| andQuery.push({ BuildingId: buildingID }); | |
| orQuery.push({ | |
| Floor: { $regex: text, $options: "i" } | |
| }); | |
| query.push( | |
| JSON.stringify({ | |
| $match: { $and: [andQuery[0], { $or: orQuery }] } | |
| }) | |
| ); | |
| query.push(JSON.stringify({ $limit: 5 })); | |
| query.push( | |
| JSON.stringify({ | |
| $project: { | |
| "Did": "$Did", | |
| "Floor": "$Floor" | |
| } | |
| }) | |
| ); | |
| query.push(JSON.stringify({ | |
| $sort: {Floor: 1} | |
| })); | |
| apiHandler.aggregate(JSON.stringify(query), "Inventory_Floor", function (CompanyFloorData) { | |
| if (CompanyFloorData.Status === "Success") { | |
| var option = []; | |
| let data = JSON.parse(CompanyFloorData.Data); | |
| data.map(val => { | |
| let da = { | |
| value: val.Did, | |
| label: val.Floor | |
| }; | |
| option.push(da); | |
| }) | |
| if (option.length !== 0) return callBack({ options: option }); | |
| return callBack({ options: [{ value: "", label: "" }] }); | |
| } | |
| }) | |
| } | |
| else if (setSearchView === "searchsuite") { | |
| var buildingID = otherCondition[0] ? otherCondition[0]["value"] : undefined; | |
| var floorId = otherCondition[1] ? otherCondition[1]["value"] : undefined; | |
| if (buildingID === undefined || floorId === undefined) { | |
| notify("Please select Building and Floor", 3000); | |
| return callBack({ options: [{ value: "", label: "" }] }); | |
| } | |
| andQuery.push({ BuildingId: buildingID }); | |
| andQuery.push({ FloorId: floorId }); | |
| orQuery.push({ | |
| SuiteNo: { $regex: text, $options: "i" } | |
| }); | |
| query.push( | |
| JSON.stringify({ | |
| $match: { $and: [andQuery[0], andQuery[1], { $or: orQuery }] } | |
| }) | |
| ); | |
| query.push(JSON.stringify({ $limit: 10 })); | |
| query.push( | |
| JSON.stringify({ | |
| $project: { | |
| "Did": "$Did", | |
| "SuiteNo": "$SuiteNo" | |
| } | |
| }) | |
| ); | |
| query.push(JSON.stringify({ | |
| $sort: {SuiteNo: 1} | |
| })); | |
| apiHandler.aggregate(JSON.stringify(query), "Inventory_Suite", function (CompanySuiteData) { | |
| if (CompanySuiteData.Status === "Success") { | |
| var option = []; | |
| let data = JSON.parse(CompanySuiteData.Data); | |
| data.map(val => { | |
| let da = { | |
| value: val.Did, | |
| label: val.SuiteNo | |
| }; | |
| option.push(da); | |
| }) | |
| if (option.length !== 0) return callBack({ options: option }); | |
| return callBack({ options: [{ value: "", label: "" }] }); | |
| } | |
| }) | |
| } else if (setSearchView === "searchcity") { | |
| var stateID = otherCondition[0]["value"] || ""; | |
| andQuery.push({ ProvinceID: stateID }); | |
| orQuery.push({ | |
| City: { $regex: text, $options: "i" } | |
| }); | |
| query.push( | |
| JSON.stringify({ | |
| $match: { $and: [andQuery[0], { $or: orQuery }] } | |
| }) | |
| ); | |
| query.push( | |
| JSON.stringify({ | |
| $project: { | |
| 1: "$Did", | |
| 2: "$City" | |
| } | |
| }) | |
| ); | |
| query.push(JSON.stringify({ | |
| $sort: {2: 1} | |
| })); | |
| query.push(JSON.stringify({ $limit: 5 })); | |
| apiHandler.aggregate(JSON.stringify(query), "Inventory_City", function (CompanySuiteData) { | |
| if (CompanySuiteData.Status === "Success") { | |
| var option = []; | |
| let data = JSON.parse(CompanySuiteData.Data); | |
| data.map(val => { | |
| let da = { | |
| value: val[1], | |
| label: val[2] | |
| }; | |
| option.push(da); | |
| }) | |
| if (option.length !== 0) return callBack({ options: option }); | |
| return callBack({ options: [{ value: "", label: "" }] }); | |
| } | |
| }) | |
| } else if (setSearchView === "searchprovince") { | |
| var countryID = otherCondition[0]["value"] || ""; | |
| andQuery.push({ CountryId: countryID }); | |
| orQuery.push({ | |
| Province: { $regex: text, $options: "i" } | |
| }); | |
| orQuery.push({ | |
| Code: { $regex: text, $options: "i" } | |
| }); | |
| query.push( | |
| JSON.stringify({ | |
| $match: { $and: [andQuery[0], { $or: orQuery }] } | |
| }) | |
| ); | |
| query.push( | |
| JSON.stringify({ | |
| $project: { | |
| 1: "$Did", | |
| 2: "$Province", | |
| 3: "$Code" | |
| } | |
| }) | |
| ); | |
| query.push(JSON.stringify({ | |
| $sort: {2: 1} | |
| })); | |
| query.push(JSON.stringify({ $limit: 5 })); | |
| apiHandler.aggregate(JSON.stringify(query), "Inventory_Province", function (CompanySuiteData) { | |
| if (CompanySuiteData.Status === "Success") { | |
| var option = []; | |
| let data = JSON.parse(CompanySuiteData.Data); | |
| data.map(val => { | |
| let da = { | |
| value: val[1], | |
| label: val[2] | |
| }; | |
| option.push(da); | |
| }) | |
| if (option.length !== 0) return callBack({ options: option }); | |
| return callBack({ options: [{ value: "", label: "" }] }); | |
| } | |
| }) | |
| } else if (setSearchView === "searchCountry") { | |
| orQuery.push({ | |
| Name: { $regex: text, $options: "i" } | |
| }); | |
| query.push( | |
| JSON.stringify({ | |
| $match: { $or: orQuery } | |
| }) | |
| ); | |
| query.push( | |
| JSON.stringify({ | |
| $project: { | |
| 1: "$Did", | |
| 2: "$Name" | |
| } | |
| }) | |
| ); | |
| query.push(JSON.stringify({ | |
| $sort: {2: 1} | |
| })); | |
| query.push(JSON.stringify({ $limit: 5 })); | |
| apiHandler.aggregate(JSON.stringify(query), "Inventory_Country", function (countryData) { | |
| if (countryData.Status === "Success") { | |
| var option = []; | |
| let data = JSON.parse(countryData.Data); | |
| data.map(val => { | |
| let da = { | |
| value: val[1], | |
| label: val[2] | |
| }; | |
| option.push(da); | |
| }) | |
| if (option.length !== 0) return callBack({ options: option }); | |
| return callBack({ options: [{ value: "", label: "" }] }); | |
| } | |
| }) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment