Subversion Repositories SmartDukaan

Rev

Rev 34168 | Rev 34805 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 34168 Rev 34798
Line 75... Line 75...
75
        }
75
        }
76
        let that = this;
76
        let that = this;
77
        doGetAjaxRequestHandler(`${context}/checkplans?price=${price}&itemId=${itemId}&poiId=${poiId}`, function (response) {
77
        doGetAjaxRequestHandler(`${context}/checkplans?price=${price}&itemId=${itemId}&poiId=${poiId}`, function (response) {
78
            var obj = JSON.parse(response);
78
            var obj = JSON.parse(response);
79
            if (obj != null) {
79
            if (obj != null) {
80
                getInsurancePlansModal(obj, that);
80
                getInsurancePlansModal(obj, that, price, itemId);
81
                return;
81
                return;
82
            } else {
82
            } else {
83
                if (typeof source === "undefined") {
83
                if (typeof source === "undefined") {
84
                    alert("Product is not eligible for insurance");
84
                    alert("Product is not eligible for insurance");
85
                }
85
                }
Line 92... Line 92...
92
class InsuranceElement extends React.Component {
92
class InsuranceElement extends React.Component {
93
    planChecked;
93
    planChecked;
94
 
94
 
95
    constructor(props) {
95
    constructor(props) {
96
        super(props);
96
        super(props);
-
 
97
        this.state = {
-
 
98
            quotedPlans: {}
-
 
99
        };
97
    }
100
    }
98
 
101
 
99
    render() {
102
    render() {
100
        console.log(this.props);
103
        console.log(this.props);
101
        return <table className="table table-sm">
104
        return <table className="table table-sm">
Line 108... Line 111...
108
                <th>Action</th>
111
                <th>Action</th>
109
            </tr>
112
            </tr>
110
            </thead>
113
            </thead>
111
            <tbody>
114
            <tbody>
112
            {Object.keys(this.props.plans).map((planName, i) =>
115
            {Object.keys(this.props.plans).map((planName, i) =>
113
                this.props.plans[planName].map((plan, i) =>
116
                this.props.plans[planName].map((plan, j) => {
-
 
117
                    const quoted = this.state.quotedPlans[plan.productId];
-
 
118
                    const isQuoted = !!quoted;
-
 
119
                    const displayPremium = isQuoted ? quoted.premium : (plan.premium || 0);
-
 
120
                    const displayDP = isQuoted ? quoted.premium : (plan.dp || 0);
-
 
121
 
114
                    <tr key={i}>
122
                    return (
-
 
123
                        <tr key={`${i}-${j}`}>
115
                        <td>{planName}</td>
124
                            <td>{planName}</td>
116
                        <td>{plan.duration}</td>
125
                            <td>{plan.duration}</td>
117
                        <td>{plan.dp}</td>
126
                            <td>{displayDP ? displayDP.toFixed(2) : "-"}</td>
118
                        <td>{plan.premium}</td>
127
                            <td>{displayPremium ? displayPremium.toFixed(2) : "-"}</td>
-
 
128
 
119
                        <td>
129
                            <td>
-
 
130
                                {isQuoted || (plan.dp > 0 && plan.premium > 0) ? (
-
 
131
                                    <button
-
 
132
                                        className="btn btn-primary"
120
                            <button className="btn btn-primary" data-key={plan.productId}
133
                                        data-key={plan.productId}
-
 
134
                                        data-amount={isQuoted ? quoted.premium.toFixed(2) : plan.premium.toFixed(2)}
-
 
135
                                        data-correlationid={isQuoted ? quoted.correlationId : ''}
121
                                    data-amount={plan.premium} onClick={this.planChecked}>Add
136
                                        onClick={this.planChecked}
-
 
137
                                    >
-
 
138
                                        Add
-
 
139
                                    </button>
-
 
140
                                ) : (
-
 
141
                                    <button className="btn btn-warning" onClick={(e) => this.checkQuote(e, plan)}>
-
 
142
                                        Check Quote
-
 
143
                                    </button>
-
 
144
                                )}
122
                            </button>
145
                            </td>
123
                        </td>
146
                        </tr>
124
                    </tr>))}
147
                    );
-
 
148
                })
-
 
149
            )}
125
            </tbody>
150
            </tbody>
-
 
151
 
126
        </table>;
152
        </table>;
127
    }
153
    }
128
 
154
 
129
    planChecked = (e) => {
155
    planChecked = (e) => {
130
        debugger;
156
        //debugger;
131
        let $itemDetails = $('div.itemdetails');
157
        let $itemDetails = $('div.itemdetails');
132
        if ($itemDetails.find('.dgram').val() === '') {
158
        if ($itemDetails.find('.dgram').val() === '') {
133
            bootbox.alert('Mobile RAM is required');
159
            bootbox.alert('Mobile RAM is required');
134
            return;
160
            return;
135
        }
161
        }
Line 141... Line 167...
141
            bootbox.alert('Mobile Mfg Date is required');
167
            bootbox.alert('Mobile Mfg Date is required');
142
            return;
168
            return;
143
        }
169
        }
144
        let $orderItemRow = $(this.props.elePlanCheckedOn).closest('td');
170
        let $orderItemRow = $(this.props.elePlanCheckedOn).closest('td');
145
        $orderItemRow.find('.insuranceid').val($(e.target).data('key'));
171
        $orderItemRow.find('.insuranceid').val($(e.target).data('key'));
-
 
172
        $orderItemRow.find('.correlationid').val($(e.target).data('correlationid'));
146
        $orderItemRow.find('.insuranceamount').val($(e.target).data('amount'));
173
        $orderItemRow.find('.insuranceamount').val($(e.target).data('amount'));
147
        $orderItemRow.find('.ram').val($itemDetails.find('.dgram').val());
174
        $orderItemRow.find('.ram').val($itemDetails.find('.dgram').val());
148
        $orderItemRow.find('.memory').val($itemDetails.find('.dgmemory').val());
175
        $orderItemRow.find('.memory').val($itemDetails.find('.dgmemory').val());
149
        $orderItemRow.find('.mfgdate').val(window.mfgDate);
176
        // $orderItemRow.find('.mfgdate').val(window.mfgDate);
-
 
177
        $orderItemRow.find('.mfgdate').val($itemDetails.find('.dgmfgdate').val());
150
        $('#mobilePlansModal').modal('hide');
178
        $('#mobilePlansModal').modal('hide');
151
        calculateTotalAmount();
179
        calculateTotalAmount();
152
    }
180
    }
-
 
181
 
-
 
182
    checkQuote = (e, plan) => {
-
 
183
        //debugger;
-
 
184
        let $itemDetails = $('div.itemdetails');
-
 
185
        if ($itemDetails.find('.dgram').val() === '') {
-
 
186
            bootbox.alert('Mobile RAM is required');
-
 
187
            return;
-
 
188
        }
-
 
189
        if ($itemDetails.find('.dgmemory').val() === '') {
-
 
190
            bootbox.alert('Mobile Memory is required');
-
 
191
            return;
-
 
192
        }
-
 
193
        if ($itemDetails.find('#dgmfgdate').val() === '') {
-
 
194
            bootbox.alert('Mobile Mfg Date is required');
-
 
195
            return;
-
 
196
        }
-
 
197
        let planCode = plan.productId;
-
 
198
        let manuFacturedDate = $itemDetails.find('.dgmfgdate').val();
-
 
199
        this.calculateQuote(planCode, this.props.itemId, this.props.devicePrice, manuFacturedDate);
-
 
200
 
-
 
201
    }
-
 
202
 
-
 
203
    calculateQuote = (planCode, itemId, devicePrice, manuFacturedDate) => {
-
 
204
        doGetAjaxRequestHandler(
-
 
205
            `${context}/getPlanQuote?planCode=${planCode}&itemId=${itemId}&sumInsured=${devicePrice}&manufacturedDate=${manuFacturedDate}`,
-
 
206
            (responseText) => {
-
 
207
                const response = JSON.parse(responseText);
-
 
208
                console.log("quote call back", response);
-
 
209
 
-
 
210
                if (response.statusMessage === "Success" && response.policyStatus === "APPROVE") {
-
 
211
                    const updatedPlan = {
-
 
212
                        premium: response.totalPremium,
-
 
213
                        correlationId: response.correlationId
-
 
214
                    };
-
 
215
 
-
 
216
                    this.setState((prevState) => ({
-
 
217
                        quotedPlans: {
-
 
218
                            ...prevState.quotedPlans,
-
 
219
                            [planCode]: updatedPlan
-
 
220
                        }
-
 
221
                    }));
-
 
222
                } else {
-
 
223
                    bootbox.alert("Quote failed: " + (response.message || "Unknown error"));
-
 
224
                }
-
 
225
            }
-
 
226
        );
-
 
227
    }
153
}
228
}
154
 
229
 
155
let reactRoot = null;
230
let reactRoot = null;
156
 
231
 
157
function getInsurancePlansModal(insurancePlans, elePlanCheckedOn) {
232
function getInsurancePlansModal(insurancePlans, elePlanCheckedOn, devicePrice, itemId) {
158
    const domContainer = document.querySelector('.insurancedetails');
233
    const domContainer = document.querySelector('.insurancedetails');
159
    reactRoot = ReactDOM.createRoot(domContainer);
234
    reactRoot = ReactDOM.createRoot(domContainer);
160
    reactRoot.render(<InsuranceElement plans={insurancePlans} elePlanCheckedOn={elePlanCheckedOn}/>)
235
    reactRoot.render(<InsuranceElement plans={insurancePlans} elePlanCheckedOn={elePlanCheckedOn}
-
 
236
                                       devicePrice={devicePrice} itemId={itemId}/>)
161
    $('#mobilePlansModal').modal({show: true});
237
    $('#mobilePlansModal').modal({show: true});
162
 
238
 
163
}
239
}
164
 
240
 
165
 
241