예제 #1
0
 function totalCostCalculation(Costbook $costbook, $ids)
 {
     try {
         if ($costbook != null) {
             if ($ids != null) {
                 $assemblyDetails = explode(";", $ids);
                 $totalDirectCost = 0.0;
                 $totalManHour = 0.0;
                 $totalRatio = 0.0;
                 foreach ($assemblyDetails as $assemblyDetail) {
                     $productCode = explode("|", $assemblyDetail);
                     $cb = Costbook::getByProductCode($productCode[1]);
                     $ratio = $productCode[2];
                     if ($cb[0]->costofgoodssold->value == 'Labor') {
                         $totalDirectCost += intval($cb[0]->laborCost) * $ratio + intval($cb[0]->burdenCost) * $ratio;
                     } else {
                         if ($cb[0]->costofgoodssold->value == 'Material') {
                             $totalDirectCost += $cb[0]->unitdirectcost * $ratio;
                         } else {
                             if ($cb[0]->costofgoodssold->value == 'Equipment') {
                                 $totalDirectCost += $cb[0]->unitdirectcost * $ratio;
                             } else {
                                 if ($cb[0]->costofgoodssold->value == 'Subcontractor') {
                                     $totalDirectCost += $cb[0]->unitdirectcost * $ratio;
                                 } else {
                                     if ($cb[0]->costofgoodssold->value == 'Other') {
                                         $totalDirectCost += $cb[0]->unitdirectcost * $ratio;
                                     }
                                 }
                             }
                         }
                     }
                     $totalManHour += $ratio * $cb[0]->costperunit;
                     $totalRatio += $ratio;
                 }
                 $costbook->unitdirectcost = $totalDirectCost;
                 $costbook->costperunit = $totalDirectCost;
                 if (!$costbook->save()) {
                     throw new Exception('Exception While saving model');
                 } else {
                     return 1;
                 }
             } else {
                 throw new Exception('Please select a product');
             }
         } else {
             throw new Exception('Cost book should not be null');
         }
     } catch (Exception $ex) {
         throw new Exception($ex);
     }
 }
 public function make()
 {
     $values = array(Zurmo::t('CustomField', 'Labor'), Zurmo::t('CustomField', 'Equipment'), Zurmo::t('CustomField', 'Material'), Zurmo::t('CustomField', 'Subcontractor'), Zurmo::t('CustomField', 'Other'), Zurmo::t('CustomField', 'Assembly'));
     static::makeCustomFieldDataByValuesAndDefault('CostOfGoodsTypes', $values);
     $values = array(Zurmo::t('CustomField', 'All'), Zurmo::t('CustomField', 'Labor'), Zurmo::t('CustomField', 'Equipment'), Zurmo::t('CustomField', 'Material'), Zurmo::t('CustomField', 'Subcontractor'), Zurmo::t('CustomField', 'Other'));
     static::makeCustomFieldDataByValuesAndDefault('CostOfGoodsTypesAssembly', $values, $values[0]);
     $unitofMeasuresDropdownOptions = array();
     foreach (Unitofmeasure::getAll('name') as $uom) {
         $unitofMeasuresDropdownOptions[] = Zurmo::t('CustomField', $uom->name);
     }
     static::makeCustomFieldDataByValuesAndDefault('UnitOfMeasureTypes', $unitofMeasuresDropdownOptions);
     $categoriesDropdownOptions = array();
     foreach (Category::getAll('name') as $categroy) {
         $categoriesDropdownOptions[] = Zurmo::t('CustomField', $categroy->name);
     }
     static::makeCustomFieldDataByValuesAndDefault('CategoryTypes', $categoriesDropdownOptions);
     $assemblyDetailvalues = Costbook::getAllAssemblyDetails();
     $assemblyDetailDropdownOptions = array();
     foreach ($assemblyDetailvalues as $assemblyDetail) {
         if ($assemblyDetail['assemblydetail'] != NULL) {
             $tmpAssemblyoptions = explode(";", $assemblyDetail['assemblydetail']);
             foreach ($tmpAssemblyoptions as $assemblyOption) {
                 $assemblyDetailDropdownOptions[] = Zurmo::t('CustomField', $assemblyOption);
             }
         }
     }
     static::makeCustomFieldDataByValuesAndDefault('AssemblyDetailSearchTypes', $assemblyDetailDropdownOptions);
 }
예제 #3
0
 /**
  * For a given partialName, run search by partial name and retrieve costbook models.
  * @param string $partialName
  * @param null|int $pageSize
  */
 public static function getCostbooksByPartialName($partialName, $pageSize = null)
 {
     assert('is_string($partialName)');
     $metadata = array();
     $metadata['clauses'] = array(1 => array('attributeName' => 'name', 'operatorType' => 'contains', 'value' => $partialName));
     $metadata['structure'] = '1';
     $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('Costbook');
     $where = RedBeanModelDataProvider::makeWhere('Costbook', $metadata, $joinTablesAdapter);
     return Costbook::getSubset($joinTablesAdapter, null, $pageSize, $where);
 }
예제 #4
0
    public static function getAssemblySearch($category, $costOfGoods, $productId)
    {
        $data = Costbook::getById($productId);
        $vCondition = '';
        $vAssemblyDetails = '';
        $assembly_count = 0;
        if ($productId != '0') {
            if ($data->assemblydetail != '' && $data->assemblydetailsearch == '(None)') {
                $vAssemblyDetails = explode(';', $data->assemblydetail);
            } else {
                if ($data->assemblydetail == '' && $data->assemblydetailsearch != '(None)') {
                    $vAssemblyDetails = explode(', ', $data->assemblydetailsearch);
                } else {
                    if ($data->assemblydetail != '' && $data->assemblydetailsearch != '(None)') {
                        $assembly_details = explode(';', $data->assemblydetail);
                        $vAssemblySearchDetails = explode(', ', $data->assemblydetailsearch);
                        $vAssemblyDetails = array_merge($assembly_details, $vAssemblySearchDetails);
                    }
                }
            }
            $assembly_count = count($vAssemblyDetails);
        }
        if ($vAssemblyDetails != '') {
            $productCodes = '';
            for ($i = 0; $i < $assembly_count; $i++) {
                $str = explode('|', $vAssemblyDetails[$i]);
                if ($i == $assembly_count - 1) {
                    $productCodes .= '"' . $str[1] . '"';
                } else {
                    $productCodes .= '"' . $str[1] . '",';
                }
            }
            $vCondition = 'AND productcode NOT IN(' . $productCodes . ')';
        }
        return ZurmoRedBean::getAll('SELECT A.*, D.value AS UnitOfMeasure FROM 
costbook A 
LEFT JOIN customfieldvalue AS B ON B.multiplevaluescustomfield_id=A.category_multiplevaluescustomfield_id
LEFT JOIN customfield AS C ON C.id =A.costofgoodssold_customfield_id
LEFT JOIN customfield AS D ON A.unitofmeasure_customfield_id =D.id
WHERE 
IF("ALL"="' . $category . '",TRUE,B.VALUE="' . $category . '")
AND IF("ALL"="' . $costOfGoods . '",TRUE,C.VALUE="' . $costOfGoods . '")  AND A.id != ' . $productId . ' 
' . $vCondition . '
GROUP BY A.ID');
    }
예제 #5
0
 public function actionGetDataByProductCode($productcode)
 {
     $data = Costbook::getByProductCode($productcode);
     echo CJSON::encode($data[0]->productname . '$##$' . $data[0]->productcode . '$##$' . $data[0]->unitofmeasure);
 }
 public function renderContent()
 {
     $categories = Category::getAll();
     $data = Costbook::getById($_GET['id']);
     $vAssemblyDetails = '';
     $assembly_count = 0;
     if ($data->assemblydetail != '' && $data->assemblydetailsearch == '(None)') {
         $vAssemblyDetails = explode(';', $data->assemblydetail);
     } else {
         if ($data->assemblydetail == '' && $data->assemblydetailsearch != '(None)') {
             $vAssemblyDetails = explode(', ', $data->assemblydetailsearch);
         } else {
             if ($data->assemblydetail != '' && $data->assemblydetailsearch != '(None)') {
                 $assembly_details = explode(';', $data->assemblydetail);
                 $vAssemblySearchDetails = explode(', ', $data->assemblydetailsearch);
                 $vAssemblyDetails = array_unique(array_merge($assembly_details, $vAssemblySearchDetails));
             }
         }
     }
     $assembly_count = count($vAssemblyDetails);
     $url = Yii::app()->createUrl("costbook/default/getDataAssemblySearch");
     $content = '<div class="SecuredEditAndDetailsView EditAndDetailsView DetailsView ModelView ConfigurableMetadataView MetadataView" id="CostbookEditAndDetailsView">
                         <div class="wrapper">
                             <h1>
                                 <span class="truncated-title" threedots="Create Costbook"><span class="ellipsis-content">Step 2 of 3 - Assembly Detail</span></span>
                             </h1>
                             <div class="wide form">
                             <form method="post" action="/app/index.php/costbook/default/create?clearCache=1&amp;resolveCustomData=1" id="edit-form" onsubmit="js:return $(this).attachLoadingOnSubmit(&quot;edit-form&quot;)">
                                 <input type="hidden" id="hidModelId" name="hidModelId" value="' . $_GET['id'] . '" />
                                 <input type="hidden" name="hidUOM" id="hidUOM" value="' . $data->unitofmeasure . '" />
                                     <div class="attributesContainer">
                                         <div class="left-column" style="width:100%;">
                                             <div class="border_top_In_Assembly_Detail_Level">
                                                 <div class="costBookAssemblyStep2Header" >Detail Products</div>
                                                     <table width=100% class="items" id="detail_products">
                                                         <th width=15%>Product Code</th><th width=30%>Product Name</th><th width=15%>Ratio</th><th width=20%>Base Unit of Measure</th><th width=20%>Unit of Measure</th>';
     if ($vAssemblyDetails != '') {
         for ($i = 0; $i < $assembly_count; $i++) {
             $str = explode('|', $vAssemblyDetails[$i]);
             $dataProductCode = Costbook::getByProductCode($str[1]);
             $content .= '<tr>
                                                             <td >' . $str[1] . '<input type="hidden" id="hidProductCode' . $i . '" value="' . $str[1] . '" /></td>
                                                             <td >' . $dataProductCode[0]->productname . '</td>
                                                             <td ><input type="text" id="detail_ratio' . $i . '" name="detailRatio" value="' . $str[2] . '" style="width:120px;" /></td>
                                                             <td >' . $dataProductCode[0]->unitofmeasure . '</td>
                                                             <td >per ' . $data->unitofmeasure . '<input type="hidden" name="currAssemblyCnt" id="currAssemblyCnt" value="' . $assembly_count . '" /></td>
                                                         </tr>';
         }
     }
     $content .= '</table><br>
                                                 </div>
                                                 <div class="panel border_top_In_Assembly_Detail_Level">
                                                     <div class="costBookAssemblyStep2Header">Search</div>
                                                         <table class="form-fields items" id="costBookAssemblyStep2Headerid">
                                                             <colgroup><col class="col-0"><col class="col-1"></colgroup>
                                                             <tbody>
                                                                 <tr>
                                                                     <th><label for="Costbook_assemblycategory_value">Select Category</label></th>
                                                                     <td colspan="1">
                                                                         <div class="hasDropDown">
                                                                             <span class="select-arrow"></span>
                                                                                 <select id="Costbook_assemblycategory_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="Costbook_costofgoodssoldassembly_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></td>
                                                                     <td colspan="1">
                                                                         <a id="saveyt2" class="attachLoading cancel-button" name="Search" href="#"  style="margin-left:21.7%;">
                                                                             <span class="z-spinner"></span>
                                                                             <span class="z-icon"></span>
                                                                             <span class="z-label">Search</span>
                                                                         </a>
                                                                     </td>
                                                                 </tr>
                                                             </tbody>
                                                         </table>
                                                     </div>
                                                     <div id="result_div"></div>
                                                 </div>
                                                 <div class="float-bar">
                                                     <div class="view-toolbar-container clearfix dock">
                                                         <div class="form-toolbar">
                                                             <a href="#" class="cancel-button" id="GobackLinkActionElement2" onclick="window.location.href = \'/app/index.php/costbook/default/edit?id=' . $_GET['id'] . '\';"><span class="z-label">Go Back</span></a>
                                                             <a href="#" class="cancel-button" name="Cancel" id="CancelLinkActionElement2" ><span class="z-label">Cancel</span></a>
                                                             <a href="#" class="cancel-button" name="save" id="saveyt3" onClick="javascript:saveAssemblyStep2();"><span class="z-label">Next</span></a>
                                                         </div>
                                                     </div>
                                                 </div>
                                             </form>
                                         <div id="modalContainer-edit-form">
                                         </div>
                                     </div>
                                 </div>
                             </div>';
     $content .= $this->renderScripts();
     $this->registerCopyAssemblySearchDataScript();
     return $content;
 }
 public function renderContent()
 {
     $categories = Category::getAll();
     $data = Costbook::getById($_GET['id']);
     $vAssemblyDetails = '';
     $vCategories = '';
     $vAssemblyDetails = explode(';', $data->assemblydetail);
     $vCategories = explode(',', $data->category);
     $mHTotal = 0;
     $laborTotal = 0;
     $equipmentTotal = 0;
     $materailTotal = 0;
     $subcontractorTotal = 0;
     $othersTotal = 0;
     for ($i = 0; $i < count($vAssemblyDetails); $i++) {
         $str = explode('|', $vAssemblyDetails[$i]);
         $dataProductCode = Costbook::getByProductCode($str[1]);
         if ($dataProductCode[0]->costofgoodssold->value == 'Labor') {
             $laborCost = $dataProductCode[0]->laborCost + $dataProductCode[0]->burdenCost;
             $laborTotal += $laborCost;
             $mHTotal += $str[2];
         } else {
             $laborCost = 0;
         }
         if ($dataProductCode[0]->costofgoodssold->value == 'Equipment') {
             $equipmentCost = $dataProductCode[0]->costperunit;
             $equipmentTotal += $equipmentCost;
         } else {
             $equipmentCost = 0;
         }
         if ($dataProductCode[0]->costofgoodssold->value == 'Material') {
             $materailCost = $dataProductCode[0]->costperunit;
             $materailTotal += $materailCost;
         } else {
             $materailCost = 0;
         }
         if ($dataProductCode[0]->costofgoodssold->value == 'Subcontractor') {
             $subcontractorCost = $dataProductCode[0]->costperunit;
             $subcontractorTotal += $subcontractorCost;
         } else {
             $subcontractorCost = 0;
         }
         if ($dataProductCode[0]->costofgoodssold->value == 'Other') {
             $otherCost = $dataProductCode[0]->costperunit;
             $othersTotal += $otherCost;
         } else {
             $otherCost = 0;
         }
     }
     $url = Yii::app()->createUrl("costbook/default/getDataAssemblySearch");
     $content = '';
     $content .= '<div class="SecuredEditAndDetailsView EditAndDetailsView DetailsView ModelView ConfigurableMetadataView MetadataView" id="CostbookEditAndDetailsView">
                         <div class="wrapper">
                             <h1>
                                 <span class="truncated-title" threedots="Create Costbook">
                                     <span class="ellipsis-content">Step3 of 3 - Assembly Summary</span>
                                 </span>
                             </h1>
                             <div class="wide form">
                             <form method="post" action="/app/index.php/costbook/default/create?clearCache=1&amp;resolveCustomData=1" id="edit-form" onsubmit="js:return $(this).attachLoadingOnSubmit(&quot;edit-form&quot;)">
                                 <input type="hidden" id="hidModelId" name="hidModelId" value="' . $_GET['id'] . '" />
                                 <div class="attributesContainer">
                                     <div class="panel border_top_In_Assembly_Detail_Level">
                                         <div class="costBookAssemblyStep2Header">
                                                   Assembly Product (Master)        
                                         </div>    
                                         <table class="items">
                                             <tr>
                                                 <th >Product Code</th>
                                                 <th >Product Name</th>
                                                 <th >Unit of Messure</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>
                                             <tr>
                                                 <td >' . $data->productcode . '</td>
                                                 <td >' . $data->productname . '</td>
                                                 <td >' . $data->unitofmeasure . '</td>
                                                 <td >' . $mHTotal . '</td>
                                                 <td >$' . $laborTotal . '</td>
                                                 <td >$' . $materailTotal . '</td>
                                                 <td >$' . $equipmentTotal . '</td>
                                                 <td >$' . $subcontractorTotal . '</td>
                                                 <td >$' . $othersTotal . '</td>
                                                 <td>$' . $data->unitdirectcost . '</td>                     
                                             </tr>
                                         </table>
                                     </div>    
                                     <div class="panel border_top_In_Assembly_Detail_Level">
                                         <div class="costBookAssemblyStep2Header">    
                                             Assembly Product (Detail)        
                                         </div>    
                                         <table class="items">
                                             <tr>
                                                 <th >Product Code</th>
                                                 <th >Product Name</th>
                                                 <th >Ratio</th>
                                                 <th >Base Unit of Measure</th>
                                                 <th >Unit of Messure</th>
                                                 <th >MH</th>
                                                 <th >L+B</th>
                                                 <th >M</th>
                                                 <th >E</th>
                                                 <th >S</th>
                                                 <th >O</th>
                                             </tr>';
     for ($i = 0; $i < count($vAssemblyDetails); $i++) {
         $str = explode('|', $vAssemblyDetails[$i]);
         $productCode = $str[1];
         $ratio = $str[2];
         $dataProductCode = Costbook::getByProductCode($str[1]);
         if ($dataProductCode[0]->costofgoodssold->value == 'Labor') {
             $laborCost = $dataProductCode[0]->laborCost + $dataProductCode[0]->burdenCost;
             $MH = $str[2];
             $laborTotal += $laborCost;
         } else {
             $laborCost = 0;
             $MH = 0;
         }
         if ($dataProductCode[0]->costofgoodssold->value == 'Equipment') {
             $equipmentCost = $dataProductCode[0]->costperunit;
             $equipmentTotal += $equipmentCost;
         } else {
             $equipmentCost = 0;
         }
         if ($dataProductCode[0]->costofgoodssold->value == 'Material') {
             $materailCost = $dataProductCode[0]->costperunit;
             $materailTotal += $materailCost;
         } else {
             $materailCost = 0;
         }
         if ($dataProductCode[0]->costofgoodssold->value == 'Subcontractor') {
             $subcontractorCost = $dataProductCode[0]->costperunit;
             $subcontractorTotal += $subcontractorCost;
         } else {
             $subcontractorCost = 0;
         }
         if ($dataProductCode[0]->costofgoodssold->value == 'Other') {
             $otherCost = $dataProductCode[0]->costperunit;
             $othersTotal += $otherCost;
         } else {
             $otherCost = 0;
         }
         $content .= '<tr>
                                                             <td >' . $productCode . '</td>
                                                             <td >' . $dataProductCode[0]->productname . '</td>
                                                             <td >' . $ratio . '</td>
                                                             <td >' . $dataProductCode[0]->unitofmeasure . '</td>
                                                             <td >' . $dataProductCode[0]->unitofmeasure . '</td>
                                                             <td >' . $MH . '</td>
                                                             <td >$' . $laborCost . '</td>
                                                             <td >$' . $materailCost . '</td>
                                                             <td >$' . $equipmentCost . '</td>
                                                             <td >$' . $subcontractorCost . '</td>
                                                             <td >$' . $otherCost . '</td>                   
                                                         </tr>';
     }
     $content .= '</table>
                                                 </div>
                                        <div class="panel border_top_In_Assembly_Detail_Level">
                                             <div class="costBookAssemblyStep2Header">    
                                                 Assembly Information (Master)        
                                             </div>            
                                         <div class="panel border_top_In_Assembly_Detail_Level" style="width:90%; margin: 3% 0% 1% 5%;">
                                             <div class="costBookAssemblyStep2Header">
                                                 Categories
                                             </div>
                                             <div>
                                             <table class="items">
                                                 <tr>
                                                     <th>Category</th>
                                                 </tr>';
     for ($k = 0; $k < count($vCategories); $k++) {
         $content .= '<tr>
                                                                         <td>' . $vCategories[$k] . '</td>
                                                                     </tr>';
     }
     $content .= '</table>
                                                             </div>
                                                             </div>
                                                             <div>
                                                                 <table width="40%" class="items">
                                                                     <tr>
                                                                         <td style="width:50%; align="center">Description</td><td>' . $data->description . '</td>
                                                                     </tr>
                                                                     <tr>
                                                                         <td style="width:50%; align="center"">Scope of Work</td><td>' . $data->scopeofwork . '</td>
                                                                     </tr>
                                                                     <tr>
                                                                         <td style="width:50%; align="center"">Propodal Text</td><td>' . $data->proposaltext . '</td>
                                                                     </tr>
                                                                 </table>
                                                              </div>       
                                                 </div>
                                     <div class="float-bar">
                                         <div class="view-toolbar-container clearfix dock">
                                             <div class="form-toolbar">
                                                 <a href="#" class="cancel-button" id="GobackLinkActionElement2" onclick="window.location.href = \'/app/index.php/costbook/default/assemblyStep2?id=' . $_GET['id'] . '\';"><span class="z-label">Go Back</span></a>
                                                 <a href="#" class="cancel-button" name="Cancel" id="CancelLinkActionElement2" ><span class="z-label">Cancel</span></a>
                                                 <a href="#" class="attachLoading z-button" name="save" id="saveyt3" onClick="location.href = \'/app/index.php/costbook/default\';"><span class="z-spinner"></span><span class="z-icon"></span><span class="z-label">Finish</span></a>
                                             </div>
                                         </div>
                                     </div>
                                 </form>
                                 <div id="modalContainer-edit-form"></div>
                             </div>
                         </div>
                     </div>';
     $content .= $this->renderScripts();
     $this->registerCopyAssemblySearchDataScript();
     return $content;
 }
예제 #8
0
 public function actionAddOpportunityProducts($ids, $addJsonObj, $optId, $urlId)
 {
     if ($ids != null && $addJsonObj != null) {
         $costbookDatas = json_decode($addJsonObj, true);
         foreach ($costbookDatas as $costbookData) {
             $res = $costbookData['costBookId'];
             $costbook = Costbook::getById($res);
             $addProductRes = OpportunityProductUtils::addOpportunityProductsCalculation($costbook, $costbookData['add_Quantity'], $costbookData['add_Frequency'], $optId, $costbookData['add_Category']);
         }
         if ($addProductRes != 1) {
             echo "Failed";
         } else {
             echo json_encode($urlId);
         }
     }
 }
예제 #9
0
 public function actionAddAgreementProducts($ids, $data, $optId)
 {
     if ($ids != null && $data != null) {
         $costbookDatas = explode(',', $data);
         foreach ($costbookDatas as $costbookData) {
             list($id, $quantity, $frequency) = explode(':', $costbookData);
             $costbook = Costbook::getById($id);
             AgreementProductUtils::addAgreementProductsCalculation($costbook, $quantity, $frequency, $optId);
         }
     }
     $this->redirect(array('/agreements/default/details?id=' . $optId));
 }