Example #1
0
function duplicaterec($currentModule, $record_id, $bmapname)
{
    global $adb, $current_user;
    $focus = CRMEntity::getInstance($currentModule);
    $focus->retrieve_entity_info($record_id, $currentModule);
    // Retrieve relations map
    //$bmapname = 'BusinessMapping_'.$currentModule.'_DuplicateRelations';
    $cbMapid = GlobalVariable::getVariable('BusinessMapping_' . $bmapname, cbMap::getMapIdByName($bmapname));
    if ($cbMapid) {
        $cbMap = cbMap::getMapByID($cbMapid);
        $maped_relations = $cbMap->DuplicateRelations()->getRelatedModules();
    }
    // Duplicate Records that this Record is dependent of
    if ($cbMapid && $cbMap->DuplicateRelations()->DuplicateDirectRelations()) {
        $invmods = getInventoryModules();
        foreach ($focus->column_fields as $fieldname => $value) {
            $sql = 'SELECT * FROM vtiger_field WHERE columnname = ? AND uitype IN (10,50,51,57,58,59,73,68,76,75,81,78,80)';
            $result = $adb->pquery($sql, array($fieldname));
            if ($adb->num_rows($result) == 1 && !empty($value)) {
                $module = getSalesEntityType($value);
                if (in_array($module, $invmods)) {
                    continue;
                }
                // we can't duplicate these
                $handler = vtws_getModuleHandlerFromName($module, $current_user);
                $meta = $handler->getMeta();
                $entity = CRMEntity::getInstance($module);
                $entity->mode = '';
                $entity->retrieve_entity_info($value, $module);
                $entity->column_fields = DataTransform::sanitizeRetrieveEntityInfo($entity->column_fields, $meta);
                $entity->save($module);
                $focus->column_fields[$fieldname] = $entity->id;
            }
        }
    }
    $handler = vtws_getModuleHandlerFromName($currentModule, $current_user);
    $meta = $handler->getMeta();
    $focus->column_fields = DataTransform::sanitizeRetrieveEntityInfo($focus->column_fields, $meta);
    $focus->saveentity($currentModule);
    // no workflows for this one => so we don't reenter this process
    $new_record_id = $focus->id;
    $curr_tab_id = gettabid($currentModule);
    $related_list = get_related_lists($curr_tab_id, $maped_relations);
    dup_related_lists($new_record_id, $currentModule, $related_list, $record_id, $maped_relations);
    $dependents_list = get_dependent_lists($curr_tab_id);
    $dependent_tables = get_dependent_tables($dependents_list, $currentModule);
    dup_dependent_rec($record_id, $currentModule, $new_record_id, $dependent_tables, $maped_relations);
    return $new_record_id;
}
Example #2
0
            $OrgfieldName->appendChild($OrgfieldNameText);
            $Orgfield->appendChild($OrgfieldName);
            $OrgfieldID = $xml->createElement("OrgfieldID");
            $OrgfieldIDText = $xml->createTextNode($fld[4]);
            $OrgfieldID->appendChild($OrgfieldIDText);
            $Orgfield->appendChild($OrgfieldID);
            $Orgfields->appendChild($Orgfield);
        }
    }
    $del = $xml->createElement("delimiter");
    $delText = $xml->createTextNode($delimArr[$i]);
    $del->appendChild($delText);
    $Orgfields->appendChild($del);
    //    }
    $fields->appendChild($field);
    $strTarField = implode($delimArr[$i], $fldnamearr);
    $strTarFldId = implode(",", $fldidarr);
}
//$root->appendChild($name);
$root->appendChild($target);
$root->appendChild($origin);
$root->appendChild($fields);
$xml->formatOutput = true;
echo $xml->saveXML();
include_once 'modules/cbMap/cbMap.php';
$map_focus = new cbMap();
$map_focus->id = $mapid;
$map_focus->retrieve_entity_info($mapid, "cbMap");
$map_focus->column_fields['content'] = $xml->saveXML();
$map_focus->mode = "edit";
$map_focus->save("cbMap");
Example #3
0
    public static function createPotentialRelatedTo($relatedto, $campaignid)
    {
        global $adb, $current_user;
        $checkrs = $adb->pquery('select 1
			from vtiger_potential
			inner join vtiger_crmentity on crmid=potentialid
			where deleted=0 and related_to=? and campaignid=?', array($relatedto, $campaignid));
        if ($adb->num_rows($checkrs) == 0) {
            require_once 'modules/Potentials/Potentials.php';
            $entity = new Potentials();
            $entity->mode = '';
            $cname = getEntityName('Campaigns', $campaignid);
            $cname = $cname[$campaignid] . ' - ';
            $setype = getSalesEntityType($relatedto);
            $rname = getEntityName($setype, $relatedto);
            $rname = $rname[$relatedto];
            $cbMapid = GlobalVariable::getVariable('BusinessMapping_PotentialOnCampaignRelation', cbMap::getMapIdByName('PotentialOnCampaignRelation'));
            if ($cbMapid) {
                $cmp = CRMEntity::getInstance('Campaigns');
                $cmp->retrieve_entity_info($campaignid, 'Campaigns');
                if ($setype == 'Accounts') {
                    $cmp->column_fields['AccountName'] = $rname;
                    $cmp->column_fields['ContactName'] = '';
                } else {
                    $cmp->column_fields['AccountName'] = '';
                    $cmp->column_fields['ContactName'] = $rname;
                }
                $cbMap = cbMap::getMapByID($cbMapid);
                $entity->column_fields = $cbMap->Mapping($cmp->column_fields, array());
            }
            if (empty($entity->column_fields['assigned_user_id'])) {
                $entity->column_fields['assigned_user_id'] = $current_user->id;
            }
            $entity->column_fields['related_to'] = $relatedto;
            $entity->column_fields['campaignid'] = $campaignid;
            if (empty($entity->column_fields['closingdate'])) {
                $dt = new DateTimeField();
                $entity->column_fields['closingdate'] = $dt->getDisplayDate();
            }
            if (empty($entity->column_fields['potentialname'])) {
                $entity->column_fields['potentialname'] = $cname . $rname;
            }
            if (empty($entity->column_fields['sales_stage'])) {
                $entity->column_fields['sales_stage'] = 'Prospecting';
            }
            $_REQUEST['assigntype'] = 'U';
            $_REQUEST['assigned_user_id'] = $entity->column_fields['assigned_user_id'];
            $entity->save('Potentials');
        }
    }
Example #4
0
    $recordName = array_values(getEntityName($currentModule, $record));
    $recordName = $recordName[0];
    $smarty->assign('NAME', $recordName);
    $smarty->assign('UPDATEINFO', updateInfo($record));
}
if ($focus->mode == 'edit') {
    $smarty->assign('UPDATEINFO', updateInfo($focus->id));
    $associated_prod = getAssociatedProducts('Issuecards', $focus);
    $smarty->assign('ASSOCIATEDPRODUCTS', $associated_prod);
    $smarty->assign('MODE', $focus->mode);
} elseif (isset($_REQUEST['isDuplicate']) && $_REQUEST['isDuplicate'] == 'true') {
    $smarty->assign('ASSOCIATEDPRODUCTS', $associated_prod);
    $smarty->assign('AVAILABLE_PRODUCTS', 'true');
    $smarty->assign('MODE', $focus->mode);
}
$cbMap = cbMap::getMapByName($currentModule . 'InventoryDetails', 'MasterDetailLayout');
if ($cbMap != null) {
    $cbMapFields = $cbMap->MasterDetailLayout();
    $smarty->assign('moreinfofields', "'" . implode("','", $cbMapFields['detailview']['fieldnames']) . "'");
    if (empty($associated_prod)) {
        // creating
        $product_Detail = $col_fields = array();
        foreach ($cbMapFields['detailview']['fields'] as $mdfield) {
            $col_fields[$mdfield['fieldinfo']['name']] = '';
            $foutput = getOutputHtml($mdfield['fieldinfo']['uitype'], $mdfield['fieldinfo']['name'], $mdfield['fieldinfo']['label'], 100, $col_fields, 0, 'InventoryDetails', 'edit', $mdfield['fieldinfo']['typeofdata']);
            $product_Detail['moreinfo'][] = $foutput;
        }
        $associated_prod = $product_Detail;
    }
}
$smarty->assign("ASSOCIATEDPRODUCTS", $associated_prod);
Example #5
0
/** This function returns the detailed list of vtiger_products associated to a given entity or a record.
* Param $module - module name
* Param $focus - module object
* Param $seid - sales entity id
* Return type is an object array
*/
function getAssociatedProducts($module, $focus, $seid = '')
{
    global $log, $adb, $theme, $current_user;
    $log->debug("Entering getAssociatedProducts(" . $module . "," . get_class($focus) . "," . $seid . "='') method ...");
    $theme_path = "themes/" . $theme . "/";
    $image_path = $theme_path . "images/";
    $product_Detail = array();
    if ($module == 'Quotes' || $module == 'PurchaseOrder' || $module == 'SalesOrder' || $module == 'Invoice') {
        $query = "SELECT\n\t\t\tcase when vtiger_products.productid != '' then vtiger_products.productname else vtiger_service.servicename end as productname,\n\t\t\tcase when vtiger_products.productid != '' then vtiger_products.productcode else vtiger_service.service_no end as productcode,\n\t\t\tcase when vtiger_products.productid != '' then vtiger_products.unit_price else vtiger_service.unit_price end as unit_price,\n\t\t\tcase when vtiger_products.productid != '' then vtiger_products.qtyinstock else 'NA' end as qtyinstock,\n\t\t\tcase when vtiger_products.productid != '' then 'Products' else 'Services' end as entitytype,\n\t\t\tvtiger_inventoryproductrel.listprice,\n\t\t\tvtiger_inventoryproductrel.description AS product_description,\n\t\t\tvtiger_inventoryproductrel.*\n\t\t\tFROM vtiger_inventoryproductrel\n\t\t\tLEFT JOIN vtiger_products ON vtiger_products.productid=vtiger_inventoryproductrel.productid\n\t\t\tLEFT JOIN vtiger_service ON vtiger_service.serviceid=vtiger_inventoryproductrel.productid\n\t\t\tWHERE id=? ORDER BY sequence_no";
        $params = array($focus->id);
        if ($module != 'PurchaseOrder') {
            if (GlobalVariable::getVariable('B2B', '1') == '1') {
                $acvid = $focus->column_fields['account_id'];
            } else {
                $acvid = $focus->column_fields['contact_id'];
            }
        } else {
            $acvid = $focus->column_fields['vendor_id'];
        }
    } elseif ($module == 'Potentials') {
        $query = "SELECT vtiger_products.productid, vtiger_products.productname, vtiger_products.productcode,\n\t\t\tvtiger_products.unit_price, vtiger_products.qtyinstock, vtiger_crmentity.description AS product_description,\n\t\t\t'Products' AS entitytype\n\t\t\tFROM vtiger_products\n\t\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid=vtiger_products.productid\n\t\t\tINNER JOIN vtiger_seproductsrel ON vtiger_seproductsrel.productid=vtiger_products.productid\n\t\t\tWHERE vtiger_seproductsrel.crmid=?";
        $query .= " UNION SELECT vtiger_service.serviceid AS productid, vtiger_service.servicename AS productname,\n\t\t\t'NA' AS productcode, vtiger_service.unit_price AS unit_price, 'NA' AS qtyinstock,\n\t\t\tvtiger_crmentity.description AS product_description, 'Services' AS entitytype\n\t\t\tFROM vtiger_service\n\t\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid=vtiger_service.serviceid\n\t\t\tINNER JOIN vtiger_crmentityrel ON vtiger_crmentityrel.relcrmid=vtiger_service.serviceid\n\t\t\tWHERE vtiger_crmentityrel.crmid=?";
        $params = array($seid, $seid);
    } elseif ($module == 'Products') {
        $query = "SELECT vtiger_products.productid, vtiger_products.productcode, vtiger_products.productname,\n\t\t\tvtiger_products.unit_price, vtiger_products.qtyinstock, vtiger_crmentity.description AS product_description,\n\t\t\t'Products' AS entitytype\n\t\t\tFROM vtiger_products\n\t\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid=vtiger_products.productid\n\t\t\tWHERE vtiger_crmentity.deleted=0 AND productid=?";
        $params = array($seid);
    } elseif ($module == 'Services') {
        $query = "SELECT vtiger_service.serviceid AS productid, 'NA' AS productcode, vtiger_service.servicename AS productname,\n\t\t\tvtiger_service.unit_price AS unit_price, 'NA' AS qtyinstock, vtiger_crmentity.description AS product_description,\n\t\t\t'Services' AS entitytype\n\t\t\tFROM vtiger_service\n\t\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid=vtiger_service.serviceid\n\t\t\tWHERE vtiger_crmentity.deleted=0 AND serviceid=?";
        $params = array($seid);
    }
    $cbMap = cbMap::getMapByName($module . 'InventoryDetails', 'MasterDetailLayout');
    $MDMapFound = $cbMap != null;
    if ($MDMapFound) {
        $cbMapFields = $cbMap->MasterDetailLayout();
    }
    $result = $adb->pquery($query, $params);
    $num_rows = $adb->num_rows($result);
    for ($i = 1; $i <= $num_rows; $i++) {
        $hdnProductId = $adb->query_result($result, $i - 1, 'productid');
        $hdnProductcode = $adb->query_result($result, $i - 1, 'productcode');
        $productname = $adb->query_result($result, $i - 1, 'productname');
        $productdescription = $adb->query_result($result, $i - 1, 'product_description');
        $comment = $adb->query_result($result, $i - 1, 'comment');
        $qtyinstock = $adb->query_result($result, $i - 1, 'qtyinstock');
        $qty = $adb->query_result($result, $i - 1, 'quantity');
        $unitprice = $adb->query_result($result, $i - 1, 'unit_price');
        $listprice = $adb->query_result($result, $i - 1, 'listprice');
        $entitytype = $adb->query_result($result, $i - 1, 'entitytype');
        if (!empty($entitytype)) {
            $product_Detail[$i]['entityType' . $i] = $entitytype;
        }
        $product_Detail[$i]['lineitem_id' . $i] = $adb->query_result($result, $i - 1, 'lineitem_id');
        if ($listprice == '') {
            $listprice = $unitprice;
        }
        if ($qty == '') {
            $qty = 1;
        }
        //calculate productTotal
        $productTotal = $qty * $listprice;
        //Delete link in First column
        if ($i != 1) {
            $product_Detail[$i]['delRow' . $i] = "Del";
        }
        if (empty($focus->mode) && $seid != '') {
            $sub_prod_query = $adb->pquery("SELECT crmid as prod_id from vtiger_seproductsrel WHERE productid=? AND setype='Products'", array($seid));
        } else {
            $sub_prod_query = $adb->pquery("SELECT productid as prod_id from vtiger_inventorysubproductrel WHERE id=? AND sequence_no=?", array($focus->id, $i));
        }
        $subprodid_str = '';
        $subprodname_str = '';
        $subProductArray = array();
        if ($adb->num_rows($sub_prod_query) > 0) {
            for ($j = 0; $j < $adb->num_rows($sub_prod_query); $j++) {
                $sprod_id = $adb->query_result($sub_prod_query, $j, 'prod_id');
                $sprod_name = $subProductArray[] = getProductName($sprod_id);
                $str_sep = "";
                if ($j > 0) {
                    $str_sep = ":";
                }
                $subprodid_str .= $str_sep . $sprod_id;
                $subprodname_str .= $str_sep . " - " . $sprod_name;
            }
        }
        $subprodname_str = str_replace(":", "<br>", $subprodname_str);
        $product_Detail[$i]['subProductArray' . $i] = $subProductArray;
        $product_Detail[$i]['hdnProductId' . $i] = $hdnProductId;
        $product_Detail[$i]['productName' . $i] = from_html($productname);
        /* Added to fix the issue Product Pop-up name display*/
        if ($_REQUEST['action'] == 'CreateSOPDF' || $_REQUEST['action'] == 'CreatePDF' || $_REQUEST['action'] == 'SendPDFMail') {
            $product_Detail[$i]['productName' . $i] = htmlspecialchars($product_Detail[$i]['productName' . $i]);
        }
        $product_Detail[$i]['hdnProductcode' . $i] = $hdnProductcode;
        $product_Detail[$i]['productDescription' . $i] = from_html($productdescription);
        if ($module == 'Potentials' || $module == 'Products' || $module == 'Services') {
            $product_Detail[$i]['comment' . $i] = $productdescription;
        } else {
            $product_Detail[$i]['comment' . $i] = $comment;
        }
        if ($MDMapFound) {
            foreach ($cbMapFields['detailview']['fields'] as $mdfield) {
                $mdrs = $adb->pquery('select ' . $mdfield['fieldinfo']['name'] . ' from vtiger_inventorydetails
						inner join vtiger_crmentity on crmid=vtiger_inventorydetails.inventorydetailsid
						inner join vtiger_inventorydetailscf on vtiger_inventorydetailscf.inventorydetailsid=vtiger_inventorydetails.inventorydetailsid
						where deleted=0 and related_to=? and lineitem_id=?', array($focus->id, $adb->query_result($result, $i - 1, 'lineitem_id')));
                if ($mdrs) {
                    $col_fields = array();
                    $col_fields[$mdfield['fieldinfo']['name']] = $adb->query_result($mdrs, 0, 0);
                    $foutput = getOutputHtml($mdfield['fieldinfo']['uitype'], $mdfield['fieldinfo']['name'], $mdfield['fieldinfo']['label'], 100, $col_fields, 0, 'InventoryDetails', 'edit', $mdfield['fieldinfo']['typeofdata']);
                    $product_Detail[$i]['moreinfo' . $i][] = $foutput;
                }
            }
        }
        if ($module != 'PurchaseOrder' && $focus->object_name != 'Order') {
            $product_Detail[$i]['qtyInStock' . $i] = $qtyinstock;
        }
        $qty = number_format($qty, 2, '.', '');
        //Convert to 2 decimals
        $listprice = number_format($listprice, 2, '.', '');
        //Convert to 2 decimals
        $product_Detail[$i]['qty' . $i] = $qty;
        $product_Detail[$i]['listPrice' . $i] = $listprice;
        $product_Detail[$i]['unitPrice' . $i] = $unitprice;
        $product_Detail[$i]['productTotal' . $i] = $productTotal;
        $product_Detail[$i]['subproduct_ids' . $i] = $subprodid_str;
        $product_Detail[$i]['subprod_names' . $i] = $subprodname_str;
        $discount_percent = $adb->query_result($result, $i - 1, 'discount_percent');
        $discount_amount = $adb->query_result($result, $i - 1, 'discount_amount');
        $discount_amount = number_format(is_numeric($discount_amount) ? $discount_amount : 0, 2, '.', '');
        //Convert to 2 decimals
        $discountTotal = '0.00';
        //Based on the discount percent or amount we will show the discount details
        //To avoid NaN javascript error, here we assign 0 initially to' %of price' and 'Direct Price reduction'(for Each Product)
        $product_Detail[$i]['discount_percent' . $i] = 0;
        $product_Detail[$i]['discount_amount' . $i] = 0;
        if ($discount_percent != 'NULL' && $discount_percent != '') {
            $product_Detail[$i]['discount_type' . $i] = "percentage";
            $product_Detail[$i]['discount_percent' . $i] = $discount_percent;
            $product_Detail[$i]['checked_discount_percent' . $i] = ' checked';
            $product_Detail[$i]['style_discount_percent' . $i] = ' style="visibility:visible"';
            $product_Detail[$i]['style_discount_amount' . $i] = ' style="visibility:hidden"';
            $discountTotal = $productTotal * $discount_percent / 100;
        } elseif ($discount_amount != 'NULL' && $discount_amount != '') {
            $product_Detail[$i]['discount_type' . $i] = "amount";
            $product_Detail[$i]['discount_amount' . $i] = $discount_amount;
            $product_Detail[$i]['checked_discount_amount' . $i] = ' checked';
            $product_Detail[$i]['style_discount_amount' . $i] = ' style="visibility:visible"';
            $product_Detail[$i]['style_discount_percent' . $i] = ' style="visibility:hidden"';
            $discountTotal = $discount_amount;
        } else {
            $product_Detail[$i]['checked_discount_zero' . $i] = ' checked';
        }
        $totalAfterDiscount = $productTotal - $discountTotal;
        $product_Detail[$i]['discountTotal' . $i] = $discountTotal;
        $product_Detail[$i]['totalAfterDiscount' . $i] = $totalAfterDiscount;
        $taxTotal = '0.00';
        $product_Detail[$i]['taxTotal' . $i] = $taxTotal;
        //Calculate netprice
        $netPrice = $totalAfterDiscount + $taxTotal;
        //if condition is added to call this function when we create PO/SO/Quotes/Invoice from Product module
        if ($module == 'PurchaseOrder' || $module == 'SalesOrder' || $module == 'Quotes' || $module == 'Invoice') {
            $taxtype = getInventoryTaxType($module, $focus->id);
            if ($taxtype == 'individual') {
                //Add the tax with product total and assign to netprice
                $netPrice = $netPrice + $taxTotal;
            }
        }
        $product_Detail[$i]['netPrice' . $i] = $netPrice;
        //First we will get all associated taxes as array
        $tax_details = getTaxDetailsForProduct($hdnProductId, 'all', $acvid);
        //Now retrieve the tax values from the current query with the name
        for ($tax_count = 0; $tax_count < count($tax_details); $tax_count++) {
            $tax_name = $tax_details[$tax_count]['taxname'];
            $tax_label = $tax_details[$tax_count]['taxlabel'];
            $tax_value = '0.00';
            //condition to avoid this function call when create new PO/SO/Quotes/Invoice from Product module
            if ($focus->id != '') {
                if ($taxtype == 'individual') {
                    //if individual then show the entered tax percentage
                    $tax_value = getInventoryProductTaxValue($focus->id, $hdnProductId, $tax_name);
                } else {
                    //if group tax then we have to show the default value when change to individual tax
                    $tax_value = $tax_details[$tax_count]['percentage'];
                }
            } else {
                //if the above function not called then assign the default associated value of the product
                $tax_value = $tax_details[$tax_count]['percentage'];
            }
            $product_Detail[$i]['taxes'][$tax_count]['taxname'] = $tax_name;
            $product_Detail[$i]['taxes'][$tax_count]['taxlabel'] = $tax_label;
            $product_Detail[$i]['taxes'][$tax_count]['percentage'] = $tax_value;
        }
    }
    //set the taxtype
    $product_Detail[1]['final_details']['taxtype'] = $taxtype;
    //Get the Final Discount, S&H charge, Tax for S&H and Adjustment values
    //To set the Final Discount details
    $finalDiscount = '0.00';
    $product_Detail[1]['final_details']['discount_type_final'] = 'zero';
    $subTotal = $focus->column_fields['hdnSubTotal'] != '' ? $focus->column_fields['hdnSubTotal'] : '0.00';
    $subTotal = number_format($subTotal, 2, '.', '');
    //Convert to 2 decimals
    $product_Detail[1]['final_details']['hdnSubTotal'] = $subTotal;
    $discountPercent = $focus->column_fields['hdnDiscountPercent'] != '' ? $focus->column_fields['hdnDiscountPercent'] : '0.00';
    $discountAmount = $focus->column_fields['hdnDiscountAmount'] != '' ? $focus->column_fields['hdnDiscountAmount'] : '0.00';
    $discountAmount = number_format($discountAmount, 2, '.', '');
    //Convert to 2 decimals
    //To avoid NaN javascript error, here we assign 0 initially to' %of price' and 'Direct Price reduction'(For Final Discount)
    $product_Detail[1]['final_details']['discount_percentage_final'] = 0;
    $product_Detail[1]['final_details']['discount_amount_final'] = 0;
    if ($focus->column_fields['hdnDiscountPercent'] != '0') {
        $finalDiscount = $subTotal * $discountPercent / 100;
        $product_Detail[1]['final_details']['discount_type_final'] = 'percentage';
        $product_Detail[1]['final_details']['discount_percentage_final'] = $discountPercent;
        $product_Detail[1]['final_details']['checked_discount_percentage_final'] = ' checked';
        $product_Detail[1]['final_details']['style_discount_percentage_final'] = ' style="visibility:visible"';
        $product_Detail[1]['final_details']['style_discount_amount_final'] = ' style="visibility:hidden"';
    } elseif ($focus->column_fields['hdnDiscountAmount'] != '0') {
        $finalDiscount = $focus->column_fields['hdnDiscountAmount'];
        $product_Detail[1]['final_details']['discount_type_final'] = 'amount';
        $product_Detail[1]['final_details']['discount_amount_final'] = $discountAmount;
        $product_Detail[1]['final_details']['checked_discount_amount_final'] = ' checked';
        $product_Detail[1]['final_details']['style_discount_amount_final'] = ' style="visibility:visible"';
        $product_Detail[1]['final_details']['style_discount_percentage_final'] = ' style="visibility:hidden"';
    }
    $finalDiscount = number_format($finalDiscount, 2, '.', '');
    //Convert to 2 decimals
    $product_Detail[1]['final_details']['discountTotal_final'] = $finalDiscount;
    //To set the Final Tax values
    //we will get all taxes. if individual then show the product related taxes only else show all taxes
    //suppose user want to change individual to group or vice versa in edit time the we have to show all taxes. so that here we will store all the taxes and based on need we will show the corresponding taxes
    $taxtotal = '0.00';
    //First we should get all available taxes and then retrieve the corresponding tax values
    $tax_details = getAllTaxes('available', '', 'edit', $focus->id);
    $ipr_cols = $adb->getColumnNames('vtiger_inventoryproductrel');
    for ($tax_count = 0; $tax_count < count($tax_details); $tax_count++) {
        $tax_name = $tax_details[$tax_count]['taxname'];
        $tax_label = $tax_details[$tax_count]['taxlabel'];
        //if taxtype is individual and want to change to group during edit time then we have to show the all available taxes and their default values
        //Also taxtype is group and want to change to individual during edit time then we have to provide the asspciated taxes and their default tax values for individual products
        if ($taxtype == 'group') {
            if (in_array($tax_name, $ipr_cols)) {
                $tax_percent = $adb->query_result($result, 0, $tax_name);
            } else {
                $tax_percent = $tax_details[$tax_count]['percentage'];
            }
        } else {
            $tax_percent = $tax_details[$tax_count]['percentage'];
        }
        //$adb->query_result($result,0,$tax_name);
        if ($tax_percent == '' || $tax_percent == 'NULL') {
            $tax_percent = '0.00';
        }
        $taxamount = ($subTotal - $finalDiscount) * $tax_percent / 100;
        $taxamount = number_format($taxamount, 2, '.', '');
        //Convert to 2 decimals
        $taxtotal = $taxtotal + $taxamount;
        $product_Detail[1]['final_details']['taxes'][$tax_count]['taxname'] = $tax_name;
        $product_Detail[1]['final_details']['taxes'][$tax_count]['taxlabel'] = $tax_label;
        $product_Detail[1]['final_details']['taxes'][$tax_count]['percentage'] = $tax_percent;
        $product_Detail[1]['final_details']['taxes'][$tax_count]['amount'] = $taxamount;
    }
    $product_Detail[1]['final_details']['tax_totalamount'] = $taxtotal;
    //To set the Shipping & Handling charge
    $shCharge = $focus->column_fields['hdnS_H_Amount'] != '' ? $focus->column_fields['hdnS_H_Amount'] : '0.00';
    $shCharge = number_format($shCharge, 2, '.', '');
    //Convert to 2 decimals
    $product_Detail[1]['final_details']['shipping_handling_charge'] = $shCharge;
    //To set the Shipping & Handling tax values
    //calculate S&H tax
    $shtaxtotal = '0.00';
    //First we should get all available taxes and then retrieve the corresponding tax values
    $shtax_details = getAllTaxes('available', 'sh', 'edit', $focus->id);
    //if taxtype is group then the tax should be same for all products in vtiger_inventoryproductrel table
    for ($shtax_count = 0; $shtax_count < count($shtax_details); $shtax_count++) {
        $shtax_name = $shtax_details[$shtax_count]['taxname'];
        $shtax_label = $shtax_details[$shtax_count]['taxlabel'];
        $shtax_percent = '0.00';
        //if condition is added to call this function when we create PO/SO/Quotes/Invoice from Product module
        if ($module == 'PurchaseOrder' || $module == 'SalesOrder' || $module == 'Quotes' || $module == 'Invoice') {
            $shtax_percent = getInventorySHTaxPercent($focus->id, $shtax_name);
        }
        $shtaxamount = $shCharge * $shtax_percent / 100;
        $shtaxtotal = $shtaxtotal + $shtaxamount;
        $product_Detail[1]['final_details']['sh_taxes'][$shtax_count]['taxname'] = $shtax_name;
        $product_Detail[1]['final_details']['sh_taxes'][$shtax_count]['taxlabel'] = $shtax_label;
        $product_Detail[1]['final_details']['sh_taxes'][$shtax_count]['percentage'] = $shtax_percent;
        $product_Detail[1]['final_details']['sh_taxes'][$shtax_count]['amount'] = $shtaxamount;
    }
    $product_Detail[1]['final_details']['shtax_totalamount'] = $shtaxtotal;
    //To set the Adjustment value
    $adjustment = $focus->column_fields['txtAdjustment'] != '' ? $focus->column_fields['txtAdjustment'] : '0.00';
    $adjustment = number_format($adjustment, 2, '.', '');
    //Convert to 2 decimals
    $product_Detail[1]['final_details']['adjustment'] = $adjustment;
    //To set the grand total
    $grandTotal = $focus->column_fields['hdnGrandTotal'] != '' ? $focus->column_fields['hdnGrandTotal'] : '0.00';
    $grandTotal = number_format($grandTotal, 2, '.', '');
    //Convert to 2 decimals
    $product_Detail[1]['final_details']['grandTotal'] = $grandTotal;
    $log->debug("Exiting getAssociatedProducts method ...");
    return $product_Detail;
}
Example #6
0
/** This function returns a HTML output of associated vtiger_products for a given entity (Quotes,Invoice,Sales order or Purchase order)
 * Param $module - module name
 * Param $focus - module object
 * Return type string
 */
function getDetailAssociatedProducts($module, $focus)
{
    global $log, $adb, $mod_strings, $theme, $log, $app_strings, $current_user;
    $log->debug("Entering getDetailAssociatedProducts(" . $module . "," . get_class($focus) . ") method ...");
    $theme_path = "themes/" . $theme . "/";
    $image_path = $theme_path . "images/";
    if (vtlib_isModuleActive("Products")) {
        $hide_stock = 'no';
    } else {
        $hide_stock = 'yes';
    }
    $tabid = getTabid($module);
    if ($module != 'PurchaseOrder') {
        if (GlobalVariable::getVariable('B2B', '1') == '1') {
            $acvid = $focus->column_fields['account_id'];
        } else {
            $acvid = $focus->column_fields['contact_id'];
        }
    } else {
        $acvid = $focus->column_fields['vendor_id'];
    }
    $cbMap = cbMap::getMapByName($module . 'InventoryDetails', 'MasterDetailLayout');
    $MDMapFound = $cbMap != null;
    if ($MDMapFound) {
        $cbMapFields = $cbMap->MasterDetailLayout();
    }
    //Get the taxtype of this entity
    $taxtype = getInventoryTaxType($module, $focus->id);
    $currencytype = getInventoryCurrencyInfo($module, $focus->id);
    $output = '';
    //Header Rows
    $output .= '
	<table width="100%" border="0" align="center" cellpadding="5" cellspacing="0" class="crmTable detailview_inventory_table" id="proTab">
	<tr valign="top" class="detailview_inventory_header">
		<td colspan="2" class="dvInnerHeader"><b>' . $app_strings['LBL_ITEM_DETAILS'] . '</b></td>
		<td class="dvInnerHeader" align="center" colspan="2"><b>' . $app_strings['LBL_CURRENCY'] . ' : </b>' . getTranslatedCurrencyString($currencytype['currency_name']) . ' (' . $currencytype['currency_symbol'] . ')
		</td>
		<td class="dvInnerHeader" align="center" colspan="2"><b>' . $app_strings['LBL_TAX_MODE'] . ' : </b>' . $app_strings[$taxtype] . '
		</td>
	</tr>
	<tr valign="top" class="detailview_inventory_subheader">
		<td width=40% class="lvtCol"><font color="red">*</font>
			<b>' . $app_strings['LBL_ITEM_NAME'] . '</b>
		</td>';
    //Additional information column
    $output .= '<td width=20% class="lvtCol"><b>' . $app_strings['LBL_INFORMATION'] . '</b></td>';
    $output .= '
		<td width=10% class="lvtCol"><b>' . $app_strings['LBL_QTY'] . '</b></td>
		<td width=10% class="lvtCol" align="right"><b>' . $app_strings['LBL_LIST_PRICE'] . '</b></td>
		<td width=10% nowrap class="lvtCol" align="right"><b>' . $app_strings['LBL_TOTAL'] . '</b></td>
		<td width=10% valign="top" class="lvtCol" align="right"><b>' . $app_strings['LBL_NET_PRICE'] . '</b></td>
	</tr>';
    if ($module == 'Quotes' || $module == 'PurchaseOrder' || $module == 'SalesOrder' || $module == 'Invoice') {
        $query = "select case when vtiger_products.productid != '' then vtiger_products.productname else vtiger_service.servicename end as productname," . " case when vtiger_products.productid != '' then 'Products' else 'Services' end as entitytype," . " case when vtiger_products.productid != '' then vtiger_products.unit_price else vtiger_service.unit_price end as unit_price," . " case when vtiger_products.productid != '' then vtiger_products.qtyinstock else 'NA' end as qtyinstock, vtiger_inventoryproductrel.* " . " from vtiger_inventoryproductrel" . " left join vtiger_products on vtiger_products.productid=vtiger_inventoryproductrel.productid " . " left join vtiger_service on vtiger_service.serviceid=vtiger_inventoryproductrel.productid " . " where id=? ORDER BY sequence_no";
    }
    $result = $adb->pquery($query, array($focus->id));
    $num_rows = $adb->num_rows($result);
    $netTotal = '0.00';
    for ($i = 1; $i <= $num_rows; $i++) {
        $sub_prod_query = $adb->pquery("SELECT productid from vtiger_inventorysubproductrel WHERE id=? AND sequence_no=?", array($focus->id, $i));
        $subprodname_str = '';
        if ($adb->num_rows($sub_prod_query) > 0) {
            for ($j = 0; $j < $adb->num_rows($sub_prod_query); $j++) {
                $sprod_id = $adb->query_result($sub_prod_query, $j, 'productid');
                $sprod_name = getProductName($sprod_id);
                $str_sep = "";
                if ($j > 0) {
                    $str_sep = ":";
                }
                $subprodname_str .= $str_sep . " - " . $sprod_name;
            }
        }
        $subprodname_str = str_replace(":", "<br>", $subprodname_str);
        $productid = $adb->query_result($result, $i - 1, 'productid');
        $entitytype = $adb->query_result($result, $i - 1, 'entitytype');
        $productname = $adb->query_result($result, $i - 1, 'productname');
        $productname = '<a href="index.php?action=DetailView&record=' . $productid . '&module=' . $entitytype . '">' . $productname . '</a>';
        if ($subprodname_str != '') {
            $productname .= "<br/><span style='color:#C0C0C0;font-style:italic;'>" . $subprodname_str . "</span>";
        }
        $comment = $adb->query_result($result, $i - 1, 'comment');
        $qtyinstock = $adb->query_result($result, $i - 1, 'qtyinstock');
        $qty = $adb->query_result($result, $i - 1, 'quantity');
        $qty = number_format($qty, 2, '.', '');
        //Convert to 2 decimals
        $unitprice = $adb->query_result($result, $i - 1, 'unit_price');
        $listprice = $adb->query_result($result, $i - 1, 'listprice');
        $total = $qty * $listprice;
        $listprice = number_format($listprice, 2, '.', '');
        //Convert to 2 decimals
        //Product wise Discount calculation - starts
        $discount_percent = $adb->query_result($result, $i - 1, 'discount_percent');
        $discount_amount = $adb->query_result($result, $i - 1, 'discount_amount');
        $totalAfterDiscount = $total;
        $productDiscount = '0.00';
        if ($discount_percent != 'NULL' && $discount_percent != '') {
            $productDiscount = $total * $discount_percent / 100;
            $productDiscount = number_format($productDiscount, 2, '.', '');
            $totalAfterDiscount = $total - $productDiscount;
            //if discount is percent then show the percentage
            $discount_info_message = "{$discount_percent} % of " . CurrencyField::convertToUserFormat($total, null, true) . " = " . CurrencyField::convertToUserFormat($productDiscount, null, true);
        } elseif ($discount_amount != 'NULL' && $discount_amount != '') {
            $productDiscount = $discount_amount;
            $productDiscount = number_format($productDiscount, 2, '.', '');
            $totalAfterDiscount = $total - $productDiscount;
            $discount_info_message = $app_strings['LBL_DIRECT_AMOUNT_DISCOUNT'] . " = " . CurrencyField::convertToUserFormat($productDiscount, null, true);
        } else {
            $discount_info_message = $app_strings['LBL_NO_DISCOUNT_FOR_THIS_LINE_ITEM'];
        }
        //Product wise Discount calculation - ends
        $totalAfterDiscount = number_format($totalAfterDiscount, 2, '.', '');
        //Convert to 2 decimals
        $netprice = $totalAfterDiscount;
        //Calculate the individual tax if taxtype is individual
        if ($taxtype == 'individual') {
            $taxtotal = '0.00';
            $tax_info_message = $app_strings['LBL_TOTAL_AFTER_DISCOUNT'] . " = " . CurrencyField::convertToUserFormat($totalAfterDiscount, null, true) . " \\n";
            $tax_details = getTaxDetailsForProduct($productid, 'all', $acvid);
            for ($tax_count = 0; $tax_count < count($tax_details); $tax_count++) {
                $tax_name = $tax_details[$tax_count]['taxname'];
                $tax_label = $tax_details[$tax_count]['taxlabel'];
                $tax_value = getInventoryProductTaxValue($focus->id, $productid, $tax_name);
                $individual_taxamount = $totalAfterDiscount * $tax_value / 100;
                $individual_taxamount = number_format($individual_taxamount, 2, '.', '');
                //Convert to 2 decimals
                $taxtotal = $taxtotal + $individual_taxamount;
                $taxtotal = number_format($taxtotal, 2, '.', '');
                //Convert to 2 decimals
                $tax_info_message .= "{$tax_label} : {$tax_value} % = " . CurrencyField::convertToUserFormat($individual_taxamount, null, true) . " \\n";
            }
            $tax_info_message .= "\\n " . $app_strings['LBL_TOTAL_TAX_AMOUNT'] . " = " . CurrencyField::convertToUserFormat($taxtotal, null, true);
            $netprice = $netprice + $taxtotal;
            $netprice = number_format($netprice, 2, '.', '');
            //Convert to 2 decimals
        }
        $sc_image_tag = '';
        if ($module == 'Invoice') {
            switch ($entitytype) {
                case 'Services':
                    if (vtlib_isModuleActive('ServiceContracts')) {
                        $sc_image_tag = '<a href="index.php?module=ServiceContracts&action=EditView&service_id=' . $productid . '&sc_related_to=' . $focus->column_fields['account_id'] . '&start_date=' . DateTimeField::convertToUserFormat($focus->column_fields['invoicedate']) . '&return_module=' . $module . '&return_id=' . $focus->id . '">' . '<img border="0" src="' . vtiger_imageurl('handshake.gif', $theme) . '" title="' . getTranslatedString('LBL_ADD_NEW', $module) . " " . getTranslatedString('ServiceContracts', 'ServiceContracts') . '" style="cursor: pointer;" align="absmiddle" />' . '</a>';
                    }
                    break;
                case 'Products':
                    if (vtlib_isModuleActive('Assets')) {
                        $sc_image_tag = '<a onclick="return window.open(\'index.php?module=Assets&return_module=Invoice&action=Popup&popuptype=detailview&select=enable&form=EditView&form_submit=false&return_action=DetailView&productid=' . $productid . '&invoiceid=' . $focus->id . '&return_id=' . $focus->id . '&recordid=' . $focus->id . '\',\'test\',\'width=640,height=602,resizable=0,scrollbars=0\')" onmouseout="vtlib_listview.trigger(\'invoiceasset.onmouseout\', this)" onmouseover="vtlib_listview.trigger(\'cell.onmouseover\', this)">' . '<img border="0" src="' . vtiger_imageurl('barcode.png', $theme) . '" title="' . getTranslatedString('LBL_ADD_NEW', $module) . " " . getTranslatedString('Assets', 'Assets') . '" style="cursor: pointer;" align="absmiddle" />' . '<span style="display:none;" vtmodule="Assets" vtfieldname="invoice_product" vtrecordid="' . $focus->id . '::' . $productid . '::' . $i . '" type="vtlib_metainfo"></span>' . '</a>';
                    }
                    break;
                default:
                    $sc_image_tag = '';
            }
        }
        //For Product Name
        $output .= '
			<tr valign="top" class="detailview_inventory_row">
				<td class="crmTableRow small lineOnTop detailview_inventory_namecell">
					' . $productname . '&nbsp;' . $sc_image_tag . '
					<br>' . $comment . '
				</td>';
        //Upto this added to display the Product name and comment
        $output .= '<td class="crmTableRow small lineOnTop detailview_inventory_stockcell">';
        if ($module != 'PurchaseOrder' && $hide_stock == 'no') {
            $output .= '<b>' . $app_strings['LBL_QTY_IN_STOCK'] . ':</b>&nbsp;' . $qtyinstock;
        }
        if ($MDMapFound) {
            foreach ($cbMapFields['detailview']['fields'] as $mdfield) {
                $output .= '<br>';
                $output .= '<b>' . $mdfield['fieldinfo']['label'] . '</b>:&nbsp;';
                $mdrs = $adb->pquery('select ' . $mdfield['fieldinfo']['name'] . ' from vtiger_inventorydetails
						inner join vtiger_crmentity on crmid=vtiger_inventorydetails.inventorydetailsid
						inner join vtiger_inventorydetailscf on vtiger_inventorydetailscf.inventorydetailsid=vtiger_inventorydetails.inventorydetailsid
						where deleted=0 and related_to=? and lineitem_id=?', array($focus->id, $adb->query_result($result, $i - 1, 'lineitem_id')));
                if ($mdrs) {
                    $col_fields = array();
                    $col_fields[$mdfield['fieldinfo']['name']] = $adb->query_result($mdrs, 0, 0);
                    $foutput = getDetailViewOutputHtml($mdfield['fieldinfo']['uitype'], $mdfield['fieldinfo']['name'], $mdfield['fieldinfo']['label'], $col_fields, 0, $tabid, $module);
                    $output .= $foutput[1];
                }
            }
        }
        $output .= '</td>';
        $output .= '<td class="crmTableRow small lineOnTop detailview_inventory_qtycell">' . $qty . '</td>';
        $output .= '
			<td class="crmTableRow small lineOnTop detailview_inventory_lpricecell" align="right">
				<table width="100%" border="0" cellpadding="5" cellspacing="0">
				   <tr>
				    <td align="right">' . CurrencyField::convertToUserFormat($listprice, null, true) . '</td>
				   </tr>
				   <tr>
					   <td align="right">(-)&nbsp;<b><a href="javascript:;" onclick="alert(\'' . $discount_info_message . '\'); ">' . $app_strings['LBL_DISCOUNT'] . ' : </a></b></td>
				   </tr>
				   <tr>
				    <td align="right" nowrap>' . $app_strings['LBL_TOTAL_AFTER_DISCOUNT'] . ' : </td>
				   </tr>';
        if ($taxtype == 'individual') {
            $output .= '
				   <tr>
					   <td align="right" nowrap>(+)&nbsp;<b><a href="javascript:;" onclick="alert(\'' . $tax_info_message . '\');">' . $app_strings['LBL_TAX'] . ' : </a></b></td>
				   </tr>';
        }
        $output .= '
				</table>
			</td>';
        $output .= '
			<td class="crmTableRow small lineOnTop detailview_inventory_totalscell" align="right">
				<table width="100%" border="0" cellpadding="5" cellspacing="0">
				   <tr><td align="right">' . CurrencyField::convertToUserFormat($total, null, true) . '</td></tr>
				   <tr><td align="right">' . CurrencyField::convertToUserFormat($productDiscount, null, true) . '</td></tr>
				   <tr><td align="right" nowrap>' . CurrencyField::convertToUserFormat($totalAfterDiscount, null, true) . '</td></tr>';
        if ($taxtype == 'individual') {
            $output .= '<tr><td align="right" nowrap>' . CurrencyField::convertToUserFormat($taxtotal, null, true) . '</td></tr>';
        }
        $output .= '
				</table>
			</td>';
        $output .= '<td class="crmTableRow small lineOnTop detailview_inventory_npricecell" valign="bottom" align="right">' . CurrencyField::convertToUserFormat($netprice, null, true) . '</td>';
        $output .= '</tr>';
        $netTotal = $netTotal + $netprice;
    }
    $output .= '</table>';
    //$netTotal should be equal to $focus->column_fields['hdnSubTotal']
    $netTotal = $focus->column_fields['hdnSubTotal'];
    $netTotal = number_format($netTotal, 2, '.', '');
    //Convert to 2 decimals
    //Display the total, adjustment, S&H details
    $output .= '<table width="100%" border="0" cellspacing="0" cellpadding="5" class="crmTable detailview_inventory_totals">';
    $output .= '<tr id="detailview_inventory_subtotalrow">';
    $output .= '<td width="88%" class="crmTableRow small" align="right"><b>' . $app_strings['LBL_NET_TOTAL'] . '</td>';
    $output .= '<td width="12%" class="crmTableRow small" align="right"><b>' . CurrencyField::convertToUserFormat($netTotal, null, true) . '</b></td>';
    $output .= '</tr>';
    //Decide discount
    $finalDiscount = '0.00';
    $final_discount_info = '0';
    //if($focus->column_fields['hdnDiscountPercent'] != '') - previously (before changing to prepared statement) the selected option (either percent or amount) will have value and the other remains empty. So we can find the non selected item by empty check. But now with prepared statement, the non selected option stored as 0
    if ($focus->column_fields['hdnDiscountPercent'] != '0') {
        $finalDiscount = $netTotal * $focus->column_fields['hdnDiscountPercent'] / 100;
        $finalDiscount = number_format($finalDiscount, 2, '.', '');
        $final_discount_info = $focus->column_fields['hdnDiscountPercent'] . " % of " . CurrencyField::convertToUserFormat($netTotal, null, true) . " = " . CurrencyField::convertToUserFormat($finalDiscount, null, true);
    } elseif ($focus->column_fields['hdnDiscountAmount'] != '0') {
        $finalDiscount = $focus->column_fields['hdnDiscountAmount'];
        $finalDiscount = number_format($finalDiscount, 2, '.', '');
        $final_discount_info = CurrencyField::convertToUserFormat($finalDiscount, null, true);
    }
    //Alert the Final Discount amount even it is zero
    $final_discount_info = $app_strings['LBL_FINAL_DISCOUNT_AMOUNT'] . " = {$final_discount_info}";
    $final_discount_info = 'onclick="alert(\'' . $final_discount_info . '\');"';
    $output .= '<tr id="detailview_inventory_totaldiscrow">';
    $output .= '<td align="right" class="crmTableRow small lineOnTop">(-)&nbsp;<b><a href="javascript:;" ' . $final_discount_info . '>' . $app_strings['LBL_DISCOUNT'] . '</a></b></td>';
    $output .= '<td align="right" class="crmTableRow small lineOnTop">' . CurrencyField::convertToUserFormat($finalDiscount, null, true) . '</td>';
    $output .= '</tr>';
    if ($taxtype == 'group') {
        $taxtotal = '0.00';
        $final_totalAfterDiscount = $netTotal - $finalDiscount;
        $tax_info_message = $app_strings['LBL_TOTAL_AFTER_DISCOUNT'] . " = " . CurrencyField::convertToUserFormat($final_totalAfterDiscount, null, true) . " \\n";
        //First we should get all available taxes and then retrieve the corresponding tax values
        $tax_details = getAllTaxes('available', '', 'edit', $focus->id);
        $ipr_cols = $adb->getColumnNames('vtiger_inventoryproductrel');
        //if taxtype is group then the tax should be same for all products in vtiger_inventoryproductrel table
        for ($tax_count = 0; $tax_count < count($tax_details); $tax_count++) {
            $tax_name = $tax_details[$tax_count]['taxname'];
            $tax_label = $tax_details[$tax_count]['taxlabel'];
            if (in_array($tax_name, $ipr_cols)) {
                $tax_value = $adb->query_result($result, 0, $tax_name);
            } else {
                $tax_value = $tax_details[$tax_count]['percentage'];
            }
            if ($tax_value == '' || $tax_value == 'NULL') {
                $tax_value = '0.00';
            }
            $taxamount = ($netTotal - $finalDiscount) * $tax_value / 100;
            $taxtotal = $taxtotal + $taxamount;
            $tax_info_message .= "{$tax_label} : {$tax_value} % = " . CurrencyField::convertToUserFormat($taxamount, null, true) . " \\n";
        }
        $tax_info_message .= "\\n " . $app_strings['LBL_TOTAL_TAX_AMOUNT'] . " = " . CurrencyField::convertToUserFormat($taxtotal, null, true);
        $output .= '<tr id="detailview_inventory_taxtotalrow">';
        $output .= '<td align="right" class="crmTableRow small">(+)&nbsp;<b><a href="javascript:;" onclick="alert(\'' . $tax_info_message . '\');">' . $app_strings['LBL_TAX'] . '</a></b></td>';
        $output .= '<td align="right" class="crmTableRow small">' . CurrencyField::convertToUserFormat($taxtotal, null, true) . '</td>';
        $output .= '</tr>';
    }
    $shAmount = $focus->column_fields['hdnS_H_Amount'] != '' ? $focus->column_fields['hdnS_H_Amount'] : '0.00';
    $shAmount = number_format($shAmount, 2, '.', '');
    //Convert to 2 decimals
    $output .= '<tr id="detailview_inventory_shippingrow">';
    $output .= '<td align="right" class="crmTableRow small">(+)&nbsp;<b>' . $app_strings['LBL_SHIPPING_AND_HANDLING_CHARGES'] . '</b></td>';
    $output .= '<td align="right" class="crmTableRow small">' . CurrencyField::convertToUserFormat($shAmount, null, true) . '</td>';
    $output .= '</tr>';
    //calculate S&H tax
    $shtaxtotal = '0.00';
    //First we should get all available taxes and then retrieve the corresponding tax values
    $shtax_details = getAllTaxes('available', 'sh', 'edit', $focus->id);
    //if taxtype is group then the tax should be same for all products in vtiger_inventoryproductrel table
    $shtax_info_message = $app_strings['LBL_SHIPPING_AND_HANDLING_CHARGE'] . " = " . CurrencyField::convertToUserFormat($shAmount, null, true) . "\\n";
    for ($shtax_count = 0; $shtax_count < count($shtax_details); $shtax_count++) {
        $shtax_name = $shtax_details[$shtax_count]['taxname'];
        $shtax_label = $shtax_details[$shtax_count]['taxlabel'];
        $shtax_percent = getInventorySHTaxPercent($focus->id, $shtax_name);
        $shtaxamount = $shAmount * $shtax_percent / 100;
        $shtaxamount = number_format($shtaxamount, 2, '.', '');
        $shtaxtotal = $shtaxtotal + $shtaxamount;
        $shtax_info_message .= "{$shtax_label} : {$shtax_percent} % = " . CurrencyField::convertToUserFormat($shtaxamount, null, true) . " \\n";
    }
    $shtax_info_message .= "\\n " . $app_strings['LBL_TOTAL_TAX_AMOUNT'] . " = " . CurrencyField::convertToUserFormat($shtaxtotal, null, true);
    $output .= '<tr id="detailview_inventory_shiptaxrow">';
    $output .= '<td align="right" class="crmTableRow small">(+)&nbsp;<b><a href="javascript:;" onclick="alert(\'' . $shtax_info_message . '\')">' . $app_strings['LBL_TAX_FOR_SHIPPING_AND_HANDLING'] . '</a></b></td>';
    $output .= '<td align="right" class="crmTableRow small">' . CurrencyField::convertToUserFormat($shtaxtotal, null, true) . '</td>';
    $output .= '</tr>';
    $adjustment = $focus->column_fields['txtAdjustment'] != '' ? $focus->column_fields['txtAdjustment'] : '0.00';
    $adjustment = number_format($adjustment, 2, '.', '');
    //Convert to 2 decimals
    $output .= '<tr id="detailview_inventory_adjustrow">';
    $output .= '<td align="right" class="crmTableRow small">&nbsp;<b>' . $app_strings['LBL_ADJUSTMENT'] . '</b></td>';
    $output .= '<td align="right" class="crmTableRow small">' . CurrencyField::convertToUserFormat($adjustment, null, true) . '</td>';
    $output .= '</tr>';
    $grandTotal = $focus->column_fields['hdnGrandTotal'] != '' ? $focus->column_fields['hdnGrandTotal'] : '0.00';
    $grandTotal = number_format($grandTotal, 2, '.', '');
    //Convert to 2 decimals
    $output .= '<tr id="detailview_inventory_grandtotrow">';
    $output .= '<td align="right" class="crmTableRow small lineOnTop"><b>' . $app_strings['LBL_GRAND_TOTAL'] . '</b></td>';
    $output .= '<td align="right" class="crmTableRow small lineOnTop">' . CurrencyField::convertToUserFormat($grandTotal, null, true) . '</td>';
    $output .= '</tr>';
    $output .= '</table>';
    $log->debug("Exiting getDetailAssociatedProducts method ...");
    return $output;
}
Example #7
0
 function getMap2Use($map2use)
 {
     if (!empty($map2use['condition']['cmapid'])) {
         $focus = new cbMap();
         $focus->id = $map2use['condition']['cmapid'];
         $focus->mode = '';
         $focus->retrieve_entity_info($focus->id, 'cbMap');
         $contentok = processcbMap::isXML(htmlspecialchars_decode($focus->column_fields['content']));
         if ($contentok) {
             if ($focus->column_fields['maptype'] == 'Condition Query') {
                 $condition = $focus->ConditionQuery($this->relatedid);
             } elseif ($focus->column_fields['maptype'] == 'Condition Expression') {
                 global $adb;
                 $setype = getSalesEntityType($this->relatedid);
                 $wsrs = $adb->pquery('select id from vtiger_ws_entity where name=?', array($setype));
                 if ($wsrs and $adb->num_rows($wsrs) == 1) {
                     $eid = $adb->query_result($wsrs, 0, 0) . 'x' . $this->relatedid;
                 } else {
                     return $map2use;
                 }
                 $condition = $focus->ConditionExpression($eid);
             } else {
                 $condition = false;
             }
             if ($condition === true or strtolower($condition) == 'true' or strtolower($condition) == 'yes' or is_numeric($condition) and $condition > 0) {
                 return $map2use['condition'];
             } else {
                 return $map2use;
             }
         } else {
             return $map2use;
         }
     } else {
         return $map2use;
     }
 }
Example #8
0
$smarty = new vtigerCRM_Smarty();
$smarty->assign('APP', $app_strings);
$smarty->assign('MOD', $mod_strings);
$smarty->assign('MODULE', $currentModule);
// TODO: Update Single Module Instance name here.
$smarty->assign('SINGLE_MOD', 'SINGLE_' . $currentModule);
$smarty->assign('CATEGORY', $category);
$smarty->assign('IMAGE_PATH', "themes/{$theme}/images/");
$smarty->assign('THEME', $theme);
if (empty($_REQUEST['record'])) {
    $smarty->assign('ERROR_MESSAGE', 'Missing Map ID (record)');
    $smarty->display('modules/cbMap/testMap.tpl');
    die;
}
$mapid = vtlib_purify($_REQUEST['record']);
$focus = new cbMap();
$focus->id = $mapid;
$focus->mode = '';
$focus->retrieve_entity_info($mapid, $currentModule);
$contentok = processcbMap::isXML(htmlspecialchars_decode($focus->column_fields['content']));
if ($contentok !== true) {
    $smarty->assign('ERROR_MESSAGE', '<b>Incorrect Content</b><br>' . $contentok);
    $smarty->display('modules/cbMap/testMap.tpl');
    die;
}
$smarty->assign('ID', $focus->id);
$smarty->assign('MODE', $focus->mode);
$recordName = array_values(getEntityName($currentModule, $focus->id));
$recordName = $recordName[0];
$smarty->assign('NAME', $recordName);
$smarty->assign('UPDATEINFO', updateInfo($focus->id));
Example #9
0
    public static function getMapByName($name, $type = '')
    {
        global $adb;
        $sql = 'select cbmapid
			from vtiger_cbmap
			inner join vtiger_crmentity on crmid=cbmapid
			where deleted=0 and mapname=?';
        $prm = array($name);
        if ($type != '') {
            $sql .= ' and maptype=?';
            $prm[] = $type;
        }
        $mrs = $adb->pquery($sql, $prm);
        if ($mrs and $adb->num_rows($mrs) > 0) {
            $cbmapid = $adb->query_result($mrs, 0, 0);
            $cbmap = new cbMap();
            $cbmap->retrieve_entity_info($cbmapid, 'cbMap');
            return $cbmap;
        } else {
            return null;
        }
    }
Example #10
0
function getSearchListViewEntries($focus, $module, $list_result, $navigation_array, $form = '')
{
    global $log, $adb, $app_strings, $theme, $current_user, $list_max_entries_per_page;
    $log->debug("Entering getSearchListViewEntries(" . get_class($focus) . "," . $module . "," . $list_result . ") method ...");
    $noofrows = $adb->num_rows($list_result);
    $list_header = '';
    $theme_path = "themes/" . $theme . "/";
    $image_path = $theme_path . "images/";
    $list_block = array();
    //getting the vtiger_fieldtable entries from database
    $tabid = getTabid($module);
    require 'user_privileges/user_privileges_' . $current_user->id . '.php';
    $bmapname = $module . '_ListColumns';
    $cbMapid = GlobalVariable::getVariable('BusinessMapping_' . $bmapname, cbMap::getMapIdByName($bmapname));
    if ($cbMapid) {
        $cbMap = cbMap::getMapByID($cbMapid);
        $focus->search_fields = $cbMap->ListColumns()->getSearchFields();
        $focus->search_fields_name = $cbMap->ListColumns()->getSearchFieldsName();
        $focus->popup_fields = array($cbMap->ListColumns()->getSearchLinkField());
        $focus->list_link_field = $cbMap->ListColumns()->getSearchLinkField();
    }
    //Added to reduce the no. of queries logging for non-admin user -- by Minnie-start
    $field_list = array_values($focus->search_fields_name);
    $field = array();
    if ($is_admin == false && $module != 'Users') {
        if ($module == 'Emails') {
            $query = "SELECT fieldname FROM vtiger_field WHERE tabid = ? and vtiger_field.presence in (0,2)";
            $params = array($tabid);
        } else {
            $profileList = getCurrentUserProfileList();
            $query = "SELECT DISTINCT vtiger_field.fieldname\n\t\t\t\tFROM vtiger_field\n\t\t\t\tINNER JOIN vtiger_profile2field\n\t\t\t\t\tON vtiger_profile2field.fieldid = vtiger_field.fieldid\n\t\t\t\tINNER JOIN vtiger_def_org_field\n\t\t\t\t\tON vtiger_def_org_field.fieldid = vtiger_field.fieldid\n\t\t\t\tWHERE vtiger_field.tabid = ?\n\t\t\t\tAND vtiger_profile2field.visible = 0\n\t\t\t\tAND vtiger_def_org_field.visible = 0\n\t\t\t\tAND vtiger_profile2field.profileid IN (" . generateQuestionMarks($profileList) . ")\n\t\t\t\tAND vtiger_field.fieldname IN (" . generateQuestionMarks($field_list) . ") and vtiger_field.presence in (0,2)";
            $params = array($tabid, $profileList, $field_list);
        }
        $result = $adb->pquery($query, $params);
        for ($k = 0; $k < $adb->num_rows($result); $k++) {
            $field[] = $adb->query_result($result, $k, "fieldname");
        }
    }
    //constructing the uitype and columnname array
    $ui_col_array = array();
    $query = "SELECT uitype, columnname, fieldname\n\t\tFROM vtiger_field\n\t\tWHERE tabid=?\n\t\tAND fieldname IN (" . generateQuestionMarks($field_list) . ") and vtiger_field.presence in (0,2)";
    $result = $adb->pquery($query, array($tabid, $field_list));
    $num_rows = $adb->num_rows($result);
    for ($i = 0; $i < $num_rows; $i++) {
        $tempArr = array();
        $uitype = $adb->query_result($result, $i, 'uitype');
        $columnname = $adb->query_result($result, $i, 'columnname');
        $field_name = $adb->query_result($result, $i, 'fieldname');
        $tempArr[$uitype] = $columnname;
        $ui_col_array[$field_name] = $tempArr;
    }
    if ($navigation_array['end_val'] > 0) {
        for ($i = 1; $i <= $noofrows; $i++) {
            //Getting the entityid
            if ($module != 'Users') {
                $entity_id = $adb->query_result($list_result, $i - 1, "crmid");
            } else {
                $entity_id = $adb->query_result($list_result, $i - 1, "id");
            }
            $list_header = array();
            foreach ($focus->search_fields as $name => $tableinfo) {
                $fieldname = $focus->search_fields_name[$name];
                if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0 || in_array($fieldname, $field) || $module == 'Users') {
                    if ($fieldname == '') {
                        $table_name = '';
                        $column_name = '';
                        foreach ($tableinfo as $tablename => $colname) {
                            $table_name = $tablename;
                            $column_name = $colname;
                        }
                        $value = $adb->query_result($list_result, $i - 1, $colname);
                    } else {
                        if (($module == 'Calls' || $module == 'Tasks' || $module == 'Meetings' || $module == 'Emails') && ($name == 'Related to' || $name == 'Contact Name' || $name == 'Vendor Name')) {
                            if ($name == 'Related to') {
                                $value = getRelatedTo($module, $list_result, $i - 1);
                            }
                            if ($name == 'Contact Name') {
                                $contact_id = $adb->query_result($list_result, $i - 1, "contactid");
                                $contact_name = getFullNameFromQResult($list_result, $i - 1, "Contacts");
                                $value = "";
                                if ($contact_name != "" && $contact_id != 'NULL') {
                                    $value = "<a href='index.php?module=Contacts&action=DetailView&record=" . $contact_id . "'>" . $contact_name . "</a>";
                                }
                            }
                        } elseif (($module == 'Faq' || $module == 'Documents') && $name == 'Related to') {
                            $value = getRelatedToEntity($module, $list_result, $i - 1);
                        } elseif ($name == 'Account Name' && ($module == 'Potentials' || $module == 'SalesOrder' || $module == 'Quotes' || $module == 'Invoice')) {
                            $account_id = $adb->query_result($list_result, $i - 1, "accountid");
                            $account_name = getAccountName($account_id);
                            $value = textlength_check($account_name);
                        } elseif ($name == 'Quote Name' && $module == 'SalesOrder') {
                            $quote_id = $adb->query_result($list_result, $i - 1, "quoteid");
                            $quotename = getQuoteName($quote_id);
                            $value = textlength_check($quotename);
                        } elseif ($name == 'Account Name' && $module == 'Contacts') {
                            $account_id = $adb->query_result($list_result, $i - 1, "accountid");
                            $account_name = getAccountName($account_id);
                            $value = textlength_check($account_name);
                        } elseif (isset($focus->popup_fields) && in_array($fieldname, $focus->popup_fields)) {
                            global $default_charset;
                            $forfield = isset($_REQUEST['forfield']) ? vtlib_purify($_REQUEST['forfield']) : '';
                            $forfield = htmlspecialchars($forfield, ENT_QUOTES, $default_charset);
                            $forform = isset($_REQUEST['form']) ? vtlib_purify($_REQUEST['form']) : '';
                            $forform = htmlspecialchars($forform, ENT_QUOTES, $default_charset);
                            $list_result_count = $i - 1;
                            $value = getValue($ui_col_array, $list_result, $fieldname, $focus, $module, $entity_id, $list_result_count, "search", $focus->popup_type);
                            if (isset($forfield) && $forfield != '' && $focus->popup_type != 'detailview') {
                                $value1 = strip_tags($value);
                                $value = htmlspecialchars(addslashes(html_entity_decode(strip_tags($value), ENT_QUOTES, $default_charset)), ENT_QUOTES, $default_charset);
                                // Remove any previous html conversion
                                $value = str_replace(array("\r", "\n"), '', $value);
                                $count = counterValue();
                                if (property_exists($focus, 'popup_function') and !empty($focus->popup_function)) {
                                    $value = "<a href='javascript:void(0);' onclick='return " . $focus->popup_function . "({$entity_id}, \"{$value}\", \"{$forfield}\"" . (empty($forform) ? '' : ',"' . $forform . '"') . ")' id ={$count} >{$value1}</a>";
                                } else {
                                    $value = "<a href='javascript:if (document.getElementById(\"closewindow\").value==\"true\") {window.close();}' onclick='return vtlib_setvalue_from_popup({$entity_id}, \"{$value}\", \"{$forfield}\"" . (empty($forform) ? '' : ',"' . $forform . '"') . ")' id ={$count} >{$value1}</a>";
                                }
                            }
                        } else {
                            $list_result_count = $i - 1;
                            $value = getValue($ui_col_array, $list_result, $fieldname, $focus, $module, $entity_id, $list_result_count, "search", $focus->popup_type, $form);
                        }
                    }
                    $list_header[] = $value;
                }
            }
            if ($module == 'Products' && ($focus->popup_type == 'inventory_prod' || $focus->popup_type == 'inventory_prod_po')) {
                global $default_charset;
                require 'user_privileges/user_privileges_' . $current_user->id . '.php';
                $row_id = $_REQUEST['curr_row'];
                //To get all the tax types and values and pass it to product details
                $tax_str = '';
                $tax_details = getAllTaxes();
                for ($tax_count = 0; $tax_count < count($tax_details); $tax_count++) {
                    $tax_str .= $tax_details[$tax_count]['taxname'] . '=' . $tax_details[$tax_count]['percentage'] . ',';
                }
                $tax_str = trim($tax_str, ',');
                $rate = $user_info['conv_rate'];
                if (getFieldVisibilityPermission($module, $current_user->id, 'unit_price') == '0') {
                    $unitprice = $adb->query_result($list_result, $list_result_count, 'unit_price');
                    if ($_REQUEST['currencyid'] != null) {
                        $prod_prices = getPricesForProducts($_REQUEST['currencyid'], array($entity_id));
                        $unitprice = $prod_prices[$entity_id];
                    }
                } else {
                    $unitprice = '';
                }
                $sub_products = '';
                $sub_prod = '';
                $sub_prod_query = $adb->pquery("SELECT vtiger_products.productid,vtiger_products.productname from vtiger_products INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid=vtiger_products.productid INNER JOIN vtiger_seproductsrel on vtiger_seproductsrel.crmid=vtiger_products.productid WHERE vtiger_seproductsrel.productid=? and vtiger_seproductsrel.setype='Products'", array($entity_id));
                for ($k = 0; $k < $adb->num_rows($sub_prod_query); $k++) {
                    //$sub_prod=array();
                    $id = $adb->query_result($sub_prod_query, $k, "productid");
                    $str_sep = '';
                    if ($k > 0) {
                        $str_sep = ":";
                    }
                    $sub_products .= $str_sep . $id;
                    $sub_prod .= $str_sep . " - " . $adb->query_result($sub_prod_query, $k, "productname");
                }
                $sub_det = $sub_products . "::" . str_replace(":", "<br>", $sub_prod);
                $qty_stock = $adb->query_result($list_result, $list_result_count, 'qtyinstock');
                $slashes_temp_val = popup_from_html(getProductName($entity_id));
                $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
                $description = $adb->query_result($list_result, $list_result_count, 'description');
                $slashes_desc = htmlspecialchars($description, ENT_QUOTES, $default_charset);
                $sub_products_link = '<a href="index.php?module=Products&action=Popup&html=Popup_picker&return_module=' . vtlib_purify($_REQUEST['return_module']) . '&record_id=' . vtlib_purify($entity_id) . '&form=HelpDeskEditView&select=enable&popuptype=' . $focus->popup_type . '&curr_row=' . vtlib_purify($row_id) . '&currencyid=' . vtlib_purify($_REQUEST['currencyid']) . '" > ' . getTranslatedString('Sub Products') . '</a>';
                $SubProductBeParent = GlobalVariable::getVariable('Product_Permit_Subproduct_Be_Parent', 'no');
                if (!isset($_REQUEST['record_id']) || $SubProductBeParent == 'yes') {
                    $sub_products_query = $adb->pquery("SELECT * from vtiger_seproductsrel WHERE productid=? AND setype='Products'", array($entity_id));
                    if ($adb->num_rows($sub_products_query) > 0) {
                        $list_header[] = $sub_products_link;
                    } else {
                        $list_header[] = $app_strings['LBL_NO_SUB_PRODUCTS'];
                    }
                }
            }
            if ($module == 'Services' && $focus->popup_type == 'inventory_service') {
                global $default_charset;
                require 'user_privileges/user_privileges_' . $current_user->id . '.php';
                $row_id = $_REQUEST['curr_row'];
                //To get all the tax types and values and pass it to product details
                $tax_str = '';
                $tax_details = getAllTaxes();
                for ($tax_count = 0; $tax_count < count($tax_details); $tax_count++) {
                    $tax_str .= $tax_details[$tax_count]['taxname'] . '=' . $tax_details[$tax_count]['percentage'] . ',';
                }
                $tax_str = trim($tax_str, ',');
                $rate = $user_info['conv_rate'];
                if (getFieldVisibilityPermission($module, $current_user->id, 'unit_price') == '0') {
                    $unitprice = $adb->query_result($list_result, $list_result_count, 'unit_price');
                    if ($_REQUEST['currencyid'] != null) {
                        $prod_prices = getPricesForProducts($_REQUEST['currencyid'], array($entity_id), $module);
                        $unitprice = $prod_prices[$entity_id];
                    }
                } else {
                    $unitprice = '';
                }
                $slashes_temp_val = popup_from_html($adb->query_result($list_result, $list_result_count, 'servicename'));
                $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
                $description = $adb->query_result($list_result, $list_result_count, 'description');
                $slashes_desc = htmlspecialchars($description, ENT_QUOTES, $default_charset);
            }
            $list_block[$entity_id] = $list_header;
        }
    }
    $list = $list_block;
    $log->debug("Exiting getSearchListViewEntries method ...");
    return $list;
}
Example #11
0
    $update_field_operator_node->appendChild($update_text_operator);
    $update_expectedvalue_node = $xml->createElement('expectedvalue');
    $update_field_node->appendChild($update_expectedvalue_node);
    $update_expectedvalue = $update_data[$i]->expectedvalue;
    if (stristr($update_expectedvalue, ':') != '') {
        $update_expectedvalue_arr = explode(':', $update_expectedvalue);
        $update_value = $update_expectedvalue_arr[0] . '.' . $update_expectedvalue_arr[1];
    } else {
        $update_value = $update_data[$i]->expectedvalue;
    }
    $update_text_expectedvalue = $xml->createTextNode($update_value);
    $update_expectedvalue_node->appendChild($update_text_expectedvalue);
}
include_once 'modules/cbMap/cbMap.php';
echo 'teszt';
$map_focus = new cbMap();
$xml->formatOutput = true;
echo $xml->saveXML();
$map_focus->id = $mapid;
$map_focus->retrieve_entity_info($mapid, 'cbMap');
$map_focus->column_fields['content'] = $xml->saveXML();
$map_focus->mode = "edit";
$map_focus->save('cbMap');
/*
//Default parameters
$defaultDelimiter = $_POST['delimiterVal'];
$rec = $_POST['accid'];
if(isset($_POST['orgmodH']))
     $orgmod = explode("$$",$_POST['orgmodH']);
else $orgmod = explode("$$",$_POST['orgmod']);
Example #12
0
/**
 * This function is used to set the Object values from the REQUEST values.
 * @param  object reference $focus - reference of the object
 */
function setObjectValuesFromRequest($focus)
{
    global $log;
    $moduleName = get_class($focus);
    $log->debug("Entering setObjectValuesFromRequest({$moduleName}) method ...");
    if (isset($_REQUEST['record'])) {
        $focus->id = $_REQUEST['record'];
    }
    if (isset($_REQUEST['mode'])) {
        $focus->mode = $_REQUEST['mode'];
    }
    foreach ($focus->column_fields as $fieldname => $val) {
        if (isset($_REQUEST[$fieldname])) {
            if (is_array($_REQUEST[$fieldname])) {
                $value = $_REQUEST[$fieldname];
            } else {
                $value = trim($_REQUEST[$fieldname]);
            }
            $focus->column_fields[$fieldname] = $value;
        } elseif (isset($_REQUEST[$fieldname . '_hidden'])) {
            $value = trim($_REQUEST[$fieldname . '_hidden']);
            $focus->column_fields[$fieldname] = $value;
        }
    }
    $cbfrommodule = $moduleName;
    $cbfrom = CRMEntity::getInstance($cbfrommodule);
    $bmapname = $moduleName . '2' . $moduleName;
    $cbMapid = GlobalVariable::getVariable('BusinessMapping_' . $bmapname, cbMap::getMapIdByName($bmapname));
    if (!empty($_REQUEST['cbfromid'])) {
        $cbfromid = vtlib_purify($_REQUEST['cbfromid']);
        $cbfrommodule = getSalesEntityType($cbfromid);
        $bmapname = $cbfrommodule . '2' . $moduleName;
        $cbfrom = CRMEntity::getInstance($cbfrommodule);
        $cbfrom->retrieve_entity_info($cbfromid, $cbfrommodule);
        $cbMapidFromid = GlobalVariable::getVariable('BusinessMapping_' . $bmapname, cbMap::getMapIdByName($bmapname));
        if ($cbMapidFromid) {
            $cbMapid = $cbMapidFromid;
        }
    }
    if ($cbMapid) {
        $cbMap = cbMap::getMapByID($cbMapid);
        $focus->column_fields = $cbMap->Mapping($cbfrom->column_fields, $focus->column_fields);
    }
    $focus = cbEventHandler::do_filter('corebos.filter.editview.setObjectValues', $focus);
    $log->debug("Exiting setObjectValuesFromRequest method ...");
}
Example #13
0
function vtws_createEntity($recordid, $originMod, $targetMod)
{
    global $adb, $current_user, $log;
    $return = 0;
    $newEntityInfo = CRMEntity::getInstance($targetMod);
    $mapfound = false;
    foreach ($originMod as $modName) {
        if ($recordid[$modName]) {
            $oldEntityInfo = CRMEntity::getInstance($modName);
            $oldEntityInfo->retrieve_entity_info(vtws_getIdComponents($recordid[$modName])[1], $modName);
            $map_name = $modName . '2' . $targetMod;
            $cbMapid = GlobalVariable::getVariable('BusinessMapping_' . $map_name, cbMap::getMapIdByName($map_name));
            if ($cbMapid) {
                $mapfound = true;
                $cbMap = cbMap::getMapByID($cbMapid);
                $newEntityInfo->column_fields = $cbMap->Mapping($oldEntityInfo->column_fields, $newEntityInfo->column_fields);
            }
        }
    }
    if ($mapfound) {
        try {
            $webserviceObject = VtigerWebserviceObject::fromName($adb, $targetMod);
            $handlerPath = $webserviceObject->getHandlerPath();
            $handlerClass = $webserviceObject->getHandlerClass();
            require_once $handlerPath;
            $handler = new $handlerClass($webserviceObject, $current_user, $adb, $log);
            $meta = $handler->getMeta();
            $values = DataTransform::sanitizeReferences($newEntityInfo->column_fields, $meta);
            $values = DataTransform::sanitizeOwnerFields($values, $meta);
            $return = vtws_create($targetMod, $values, $current_user);
        } catch (Exception $e) {
            throw new WebServiceException(WebServiceErrorCode::$UNKNOWNOPERATION, $e->getMessage() . ' : ' . $targetMod);
        }
    }
    return $return;
}
Example #14
0
/** This function returns the vtiger_invoice object populated with the details from sales order object.
* Param $focus - Invoice object
* Param $so_focus - Sales order focus
* Param $soid - sales order id
* Return type is an object array
*/
function getConvertSoToInvoice($focus, $so_focus, $soid)
{
    global $log, $current_user;
    $log->debug("Entering getConvertSoToInvoice(" . get_class($focus) . "," . get_class($so_focus) . "," . $soid . ") method ...");
    $cbMapid = GlobalVariable::getVariable('BusinessMapping_SalesOrder2Invoice', cbMap::getMapIdByName('SalesOrder2Invoice'));
    if ($cbMapid) {
        $cbMap = cbMap::getMapByID($cbMapid);
        $focus->column_fields = $cbMap->Mapping($so_focus->column_fields, $focus->column_fields);
    } else {
        $xyz = array('bill_street', 'bill_city', 'bill_code', 'bill_pobox', 'bill_country', 'bill_state', 'ship_street', 'ship_city', 'ship_code', 'ship_pobox', 'ship_country', 'ship_state');
        for ($i = 0; $i < count($xyz); $i++) {
            if (getFieldVisibilityPermission('SalesOrder', $current_user->id, $xyz[$i]) == '0') {
                $so_focus->column_fields[$xyz[$i]] = $so_focus->column_fields[$xyz[$i]];
            } else {
                $so_focus->column_fields[$xyz[$i]] = '';
            }
        }
        $focus->column_fields['salesorder_id'] = $soid;
        $focus->column_fields['subject'] = $so_focus->column_fields['subject'];
        $focus->column_fields['customerno'] = $so_focus->column_fields['customerno'];
        $focus->column_fields['duedate'] = $so_focus->column_fields['duedate'];
        $focus->column_fields['contact_id'] = $so_focus->column_fields['contact_id'];
        //to include contact name in Invoice
        $focus->column_fields['account_id'] = $so_focus->column_fields['account_id'];
        $focus->column_fields['exciseduty'] = $so_focus->column_fields['exciseduty'];
        $focus->column_fields['salescommission'] = $so_focus->column_fields['salescommission'];
        $focus->column_fields['purchaseorder'] = $so_focus->column_fields['vtiger_purchaseorder'];
        $focus->column_fields['bill_street'] = $so_focus->column_fields['bill_street'];
        $focus->column_fields['ship_street'] = $so_focus->column_fields['ship_street'];
        $focus->column_fields['bill_city'] = $so_focus->column_fields['bill_city'];
        $focus->column_fields['ship_city'] = $so_focus->column_fields['ship_city'];
        $focus->column_fields['bill_state'] = $so_focus->column_fields['bill_state'];
        $focus->column_fields['ship_state'] = $so_focus->column_fields['ship_state'];
        $focus->column_fields['bill_code'] = $so_focus->column_fields['bill_code'];
        $focus->column_fields['ship_code'] = $so_focus->column_fields['ship_code'];
        $focus->column_fields['bill_country'] = $so_focus->column_fields['bill_country'];
        $focus->column_fields['ship_country'] = $so_focus->column_fields['ship_country'];
        $focus->column_fields['bill_pobox'] = $so_focus->column_fields['bill_pobox'];
        $focus->column_fields['ship_pobox'] = $so_focus->column_fields['ship_pobox'];
        $focus->column_fields['description'] = $so_focus->column_fields['description'];
        $focus->column_fields['terms_conditions'] = $so_focus->column_fields['terms_conditions'];
        $focus->column_fields['currency_id'] = $so_focus->column_fields['currency_id'];
        $focus->column_fields['conversion_rate'] = $so_focus->column_fields['conversion_rate'];
    }
    $log->debug("Exiting getConvertSoToInvoice method ...");
    return $focus;
}