public function makeCostBookProductSelection($datas, $opportunityId) { $categories = Category::getAll(); $TotalDirectCost = 0; $content = '<div>'; $opportunityProducts = OpportunityProduct::getAllByOpptId(intval($opportunityId)); $opportunity = Opportunity::getById(intval($opportunityId)); $countOfSelectedRow = 0; if ($opportunity->recordType->value == 'Recurring Final') { $content .= '<div class="cgrid-view type-opportunityProducts" id="list-view"> <div class="summary"> 5 result(s) </div> <div id="add_Product_list_table" class="table_border_width"> <table id="add_Product_List_table_Value" class="items"> <tr> <td><label id="totalMhr"> Total Mhr ' . OpportunityProductUtils::getCurrencyType() . ': 0 </label></td> <td><label id="totalDirectCost"> Total Direct Cost ' . OpportunityProductUtils::getCurrencyType() . ': 0 </label></td> <td><label id="budget"> Budget ' . OpportunityProductUtils::getCurrencyType() . ': 0 </label></td> </tr> <tr> <td><label id="Revenue_MHR"> Revenue / MHR ' . OpportunityProductUtils::getCurrencyType() . ': 0.0 </label></td> <td><label id="Aggregate_GPM"> Aggregate GPM %: 0 </label></td> <td><label id="Suggested_Price"> Suggested Price ' . OpportunityProductUtils::getCurrencyType() . ': 0 </label></td> </tr> </table> </div>'; if (count($opportunityProducts) > 0) { $content .= '<div id="selected_products" class="table_border_width" style="padding: 0%;"> <div class="align_left" style="background-color:#E0D1D1; color:black;padding:0.5%; font-weight:bold;"> Selected Products <span id="showresults" style="color:green; font-weight:none;"></span> </div> <div style="margin:0.5% 0% 0.5% 45%"> <a href="#" onclick="javascript:updateSelectedProducts(\'' . $opportunityId . '\');"> <span class="z-label"> Update Values </span> </a> </div>'; $content .= '<table class="items selected_products_table"> <tr style="color:black; padding:0.5%;"> <th>Product Code</th> <th>Product Name</th> <th>Unit of Measure</th> <th>Quantity</th> <th>Frequency</th> <th>MH</th> <th>L+B</th> <th>M</th> <th>E</th> <th>S</th> <th>O</th> <th>Total Direct Cost</th> </tr>'; foreach ($opportunityProducts as $row) { $opportunityPdctMap[$row->Category][] = $row; } $CategoryKeyCount = 0; $totalMhr = 0; $totalDirectCost = 0; $totalFinalPrice = 0.0; $actualGPM = 0; $totalRevenue = 0.0; foreach ($opportunityPdctMap as $CategoryKey => $opportunityArray) { $content .= '<tr> <th colspan="12" class="align_left" style="background-color:gray;color:white;">' . $CategoryKey . '</th> <input type="hidden" name="CategoryKey" id="CategoryKey_' . $CategoryKeyCount . '" value="' . $CategoryKey . '"> </tr>'; foreach ($opportunityArray as $opportunityKey => $opportunitypdt) { $totalMhr += $opportunitypdt->Total_MHR; $totalDirectCost += $opportunitypdt->Total_Direct_Cost->value; $totalFinalPrice += $opportunitypdt->Final_Cost->value; $content .= '<tr> <td>' . $opportunitypdt->costbook->productcode . '</td> <input value=' . $opportunitypdt->id . ' name="list_View_Add_Product_SelectedIds"id="list_View_Producted_SelectedIds_' . $countOfSelectedRow . '" type="hidden"> <td>' . $opportunitypdt->name . '</td> <td>' . $opportunitypdt->costbook->unitofmeasure . '</td> <td><input type="text" name="updateFrequency&Quantity" id="updateQuantity_' . $countOfSelectedRow . '" value=' . $opportunitypdt->Quantity . '></td> <td><input name="updateFrequency&Quantity" type="text" id="updateFrequency_' . $countOfSelectedRow . '" value=' . $opportunitypdt->Frequency . '></td> <td>' . $opportunitypdt->Total_MHR . '</td> <td>' . OpportunityProductUtils::getCurrencyType() . ($opportunitypdt->Labor_Cost->value + $opportunitypdt->Burden_Cost->value) . '</td> <td>' . OpportunityProductUtils::getCurrencyType() . $opportunitypdt->Materials_Cost . '</td> <td>' . OpportunityProductUtils::getCurrencyType() . $opportunitypdt->Equipment_Cost . '</td> <td>' . OpportunityProductUtils::getCurrencyType() . $opportunitypdt->Sub_Cost . '</td> <td>' . OpportunityProductUtils::getCurrencyType() . $opportunitypdt->Other_Cost . '</td> <td>' . OpportunityProductUtils::getCurrencyType() . $opportunitypdt->Total_Direct_Cost->value . '</td> </tr>'; $countOfSelectedRow++; } $CategoryKeyCount++; } if ($totalFinalPrice > 0) { $actualGPM = ($totalFinalPrice - $totalDirectCost) / $totalFinalPrice * 100; } if ($totalMhr > 0) { $totalRevenue = $totalFinalPrice / $totalMhr; } Yii::app()->clientScript->registerScript('calculationForAddProductScreenRecurring', '$("#totalMhr").text("Total Mhr ' . OpportunityProductUtils::getCurrencyType() . ': ' . $totalMhr . '"); $("#totalDirectCost").text("Total Direct Cost ' . OpportunityProductUtils::getCurrencyType() . ': ' . $totalDirectCost . '"); $("#budget").text("Budget ' . OpportunityProductUtils::getCurrencyType() . ' : ' . $opportunity->budget->value . '"); $("#Suggested_Price").text("Suggested Price ' . OpportunityProductUtils::getCurrencyType() . ': ' . sprintf('%.2f', $totalFinalPrice) . '"); $("#Aggregate_GPM").text("Aggregate GPM %: ' . sprintf('%.2f', $actualGPM) . '"); //$("#Roundedvalue").text(" Rounded value").css({"color":"red"}); $("#Revenue_MHR").text("Revenue / MHR ' . OpportunityProductUtils::getCurrencyType() . ': ' . sprintf('%.2f', $totalRevenue) . '"); '); $content .= '<input value="' . $countOfSelectedRow . '" name="Selected_Products_Ids" id="Selected_Products_Ids" type="hidden">'; $content .= ' </table></div></td></tr></table></div>'; } $content .= '<div class="table_border_width" id="add_product_search" style="padding: 0px;"> <div class="panel"> <div class="align_left" style="color:black; background-color:#E0D1D1; color:black; padding:0.5%; font-weight:bold;">Search</div> <table class="form-fields"> <colgroup><col class="col-0"><col class="col-1"></colgroup> <tbody> <tr> <th width="20%"> <label for="oppt_AddProductcategory_value">Select Category</label> </th> <td colspan="1" > <div class="hasDropDown"> <span class="select-arrow"></span> <select id="oppt_AddProductcategory_value" name="Costbook[assemblycategory][value]"> <option value="All">All</option>'; foreach ($categories as $values) { $content .= '<option value="' . $values->name . '">' . $values->name . '</option>'; } $content .= '</select> </div> </td> </tr> <tr> <th> <label for="costofgoodssoldassembly">Select COGS</label> </th> <td colspan="1" style="margin: 0px;"> <div class="hasDropDown"> <span class="select-arrow"></span> <select id="oppt_AddProductcostofgoodssold_value" name="Costbook[costofgoodssoldassembly][value][assemblycategory][value]"> <option selected="selected" value="All">All</option> <option value="Labor">Labor</option> <option value="Equipment">Equipment</option> <option value="Material">Material</option> <option value="Subcontractor">Subcontractor</option> <option value="Other">Other</option> </select> </div> </td> </tr> <tr> <td> <label for="costofgoodssoldassembly"></label> </td> <td colspan="1"> <div style="margin-left:32%;"> <a id="search" onClick="javascript:searchProducts(\'' . $opportunityId . '\');" class="attachLoading z-button cancel-button" name="Search" href="#"> <span class="z-spinner"></span> <span class="z-icon"></span> <span class="z-label">Search</span> </a> </div> </td> </tr> </tbody> </table> </div> <div id="result_div"></div> </div> </div>'; $content .= OpportunityProductUtils::appendButton($opportunityId); $content .= '<div class="items-wrapper" id="addProductWrapper"> <input type="hidden" id="selectedProductCnt" value="' . $countOfSelectedRow . '" /> <div id="searchProducts">'; } else { $content .= '<div class="cgrid-view type-opportunityProducts" id="list-view"> <div class="summary"> 5 result(s) </div> <div id="add_product_outer"> <div id="add_Product_list_table" class="table_border_width"> <table id="add_Product_List_table_Value" class="items"> <tr> <td><label id="totalMhr"> Total Mhr ' . OpportunityProductUtils::getCurrencyType() . ': 0 </label></td> <td><label id="totalDirectCost"> Total Direct Cost ' . OpportunityProductUtils::getCurrencyType() . ': 0 </label></td> <td><label id="budget"> Budget ' . OpportunityProductUtils::getCurrencyType() . ': 0 </label></td> </tr> <tr> <td><label id="Revenue_MHR"> Revenue / MHR ' . OpportunityProductUtils::getCurrencyType() . ': 0.0 </label></td> <td><label id="Aggregate_GPM"> Aggregate GPM %: 0 </label></td> <td><label id="Suggested_Price"> Suggested Price ' . OpportunityProductUtils::getCurrencyType() . ': 0 </label></td> </tr> </table> </div>'; if (count($opportunityProducts) > 0) { $content .= '<div id="selected_products" class="table_border_width" style="padding: 0px;"> <div class="align_left" style="background-color:#E0D1D1; color:black;padding:0.5%; font-weight:bold;"> Selected Products <span id="showresults" style="color:green; font-weight:none;"></span> </div> <div style="margin:0.5% 0% 0.5% 45%"> <a href="#" onclick="javascript:updateSelectedProducts(\'' . $opportunityId . '\');"> <span class="z-label"> Update Values </span> </a> </div>'; $content .= '<table class="items selected_products_table"> <tr style="color:black; padding:0.5%;"> <th>Product Code</th> <th>Product Name</th> <th>Unit of Measure</th> <th>Quantity</th> <th>MH</th> <th>L+B</th> <th>M</th> <th>E</th> <th>S</th> <th>O</th> <th>Total Direct Cost</th> </tr>'; foreach ($opportunityProducts as $row) { $opportunityPdctMap[$row->Category][] = $row; } $CategoryKeyCount = 0; $totalMhr = 0; $totalDirectCost = 0; $totalFinalPrice = 0.0; $actualGPM = 0; $totalRevenue = 0.0; foreach ($opportunityPdctMap as $CategoryKey => $opportunityArray) { $content .= '<tr> <th colspan="11" class="align_left" style="background-color:gray; color:white;">' . $CategoryKey . '</th> <input type="hidden" name="CategoryKey" id="CategoryKey_' . $CategoryKeyCount . '" value="' . $CategoryKey . '"> </tr>'; foreach ($opportunityArray as $opportunityKey => $opportunitypdt) { $totalMhr += $opportunitypdt->Total_MHR; $totalDirectCost += $opportunitypdt->Total_Direct_Cost->value; $totalFinalPrice += $opportunitypdt->Final_Cost->value; $content .= '<tr> <td>' . $opportunitypdt->costbook->productcode . '</td> <input value=' . $opportunitypdt->costbook->productcode . ' name="productCode" id="productCode_' . $countOfSelectedRow . '" type="hidden"> <input value=' . $opportunitypdt->id . ' name="list_View_Add_Product_SelectedIds"id="list_View_Producted_SelectedIds_' . $countOfSelectedRow . '" type="hidden"> <td>' . $opportunitypdt->name . '</td> <td>' . $opportunitypdt->costbook->unitofmeasure . '</td> <td><input type="text" id="updateQuantity_' . $countOfSelectedRow . '" value=' . $opportunitypdt->Quantity . '></td> <td>' . $opportunitypdt->Total_MHR . '</td> <td>' . OpportunityProductUtils::getCurrencyType() . ($opportunitypdt->Labor_Cost->value + $opportunitypdt->Burden_Cost->value) . '</td> <td>' . OpportunityProductUtils::getCurrencyType() . $opportunitypdt->Materials_Cost . '</td> <td>' . OpportunityProductUtils::getCurrencyType() . $opportunitypdt->Equipment_Cost . '</td> <td>' . OpportunityProductUtils::getCurrencyType() . $opportunitypdt->Sub_Cost . '</td> <td>' . OpportunityProductUtils::getCurrencyType() . $opportunitypdt->Other_Cost . '</td> <td>' . OpportunityProductUtils::getCurrencyType() . $opportunitypdt->Total_Direct_Cost->value . '</td> </tr>'; $countOfSelectedRow++; } $CategoryKeyCount++; } if ($totalFinalPrice > 0) { $actualGPM = ($totalFinalPrice - $totalDirectCost) / $totalFinalPrice * 100; } if ($totalMhr > 0) { $totalRevenue = $totalFinalPrice / $totalMhr; } Yii::app()->clientScript->registerScript('calculationForAddProductScreen', '$("#totalMhr").text("Total Mhr ' . OpportunityProductUtils::getCurrencyType() . ': ' . $totalMhr . '"); $("#totalDirectCost").text("Total Direct Cost ' . OpportunityProductUtils::getCurrencyType() . ': ' . $totalDirectCost . '"); $("#budget").text("Budget ' . OpportunityProductUtils::getCurrencyType() . ': ' . $opportunity->budget->value . '"); $("#Suggested_Price").text("Suggested Price ' . OpportunityProductUtils::getCurrencyType() . ': ' . sprintf('%.2f', $totalFinalPrice) . '"); $("#Aggregate_GPM").text("Aggregate GPM %: ' . sprintf('%.2f', $actualGPM) . '"); //$("#Roundedvalue").text(" Rounded value").css({"color":"red"}); $("#Revenue_MHR").text("Revenue / MHR ' . OpportunityProductUtils::getCurrencyType() . ': ' . sprintf('%.2f', $totalRevenue) . '"); //alert("' . $totalMhr . '"); '); $content .= '<input value="' . $countOfSelectedRow . '" name="Selected_Products_Ids" id="Selected_Products_Ids" type="hidden">'; $content .= ' </table></div></td></tr></table></div> </div>'; } $content .= '<div class="table_border_width" id="add_product_search" style="padding: 0px;"> <div class="panel"> <div class="align_left" style="color:black; background-color:#E0D1D1; color:black; padding:0.5%; font-weight:bold;">Search</div> <table class="form-fields items"> <colgroup><col class="col-0"><col class="col-1"></colgroup> <tbody> <tr> <th width="20%"> <label for="oppt_AddProductcategory_value">Select Category</label> </th> <td colspan="1"> <div class="hasDropDown"> <span class="select-arrow"></span> <select id="oppt_AddProductcategory_value" name="Costbook[assemblycategory][value]"> <option value="All">All</option>'; foreach ($categories as $values) { $content .= '<option value="' . $values->name . '">' . $values->name . '</option>'; } $content .= '</select> </div> </td> </tr> <tr> <th> <label for="costofgoodssoldassembly">Select COGS</label> </th> <td colspan="1"> <div class="hasDropDown"> <span class="select-arrow"></span> <select id="oppt_AddProductcostofgoodssold_value" name="Costbook[costofgoodssoldassembly][value][assemblycategory][value]"> <option selected="selected" value="All">All</option> <option value="Labor">Labor</option> <option value="Equipment">Equipment</option> <option value="Material">Material</option> <option value="Subcontractor">Subcontractor</option> <option value="Other">Other</option> </select> </div> </td> </tr> <tr> <td> <label for="costofgoodssoldassembly"></label> </td> <td colspan="1"> <div style="margin-left:32%;"> <a id="search" onclick="javascript:searchProducts(\'' . $opportunityId . '\');" class="attachLoading cancel-button" name="Search" href="#"> <span class="z-spinner"></span> <span class="z-icon"></span> <span class="z-label">Search</span> </a> </div> </td> </tr> </tbody> </table> </div> <div id="result_div"></div> </div>'; $content .= OpportunityProductUtils::appendButton($opportunityId); $content .= '<div class="items-wrapper" id="addProductWrapper"> <input type="hidden" id="selectedProductCnt" value="' . $countOfSelectedRow . '" /> <div id="searchProducts"><a id="" href="searchResult"></a>'; } $count = 0; $content1 = ''; if ($opportunity->recordType->value == 'Recurring Final') { foreach ($datas as $data) { $dispCategory = OpportunityProductUtils::makeDropDownByCategory($data->category, $count, $opportunityId, $data->productcode); $count++; } } else { foreach ($datas as $data) { $dispCategory = OpportunityProductUtils::makeDropDownByCategory($data->category, $count, $opportunityId, $data->productcode); $count++; } } $content .= '</tbody> </table> <input value="" name="list-view-selectedIds" id="list-view-selectedIds" type="hidden"> </div> </div></div> <input value="' . $opportunity->recordType->value . '" name="recordType" id="recordType_Ids" type="hidden">'; return $content; }