Пример #1
0
 function getAssociatedProducts()
 {
     global $log;
     $log->debug("Entering getAssociatedProducts() method ...");
     $product_Detail = array();
     $query = "select ec_products.*,ec_inventoryproductrel.*,ec_products.productid as crmid,ec_catalog.catalogname,ec_vendor.vendorname from ec_inventoryproductrel inner join ec_products on ec_products.productid=ec_inventoryproductrel.productid left join ec_catalog on ec_catalog.catalogid=ec_products.catalogid left join ec_vendor on ec_vendor.vendorid=ec_products.vendor_id where ec_inventoryproductrel.id=" . $this->id . " ORDER BY sequence_no";
     $fieldlist = getProductFieldList("Relsettings");
     $result = $this->db->query($query);
     $num_rows = $this->db->num_rows($result);
     for ($i = 1; $i <= $num_rows; $i++) {
         $productid = $this->db->query_result($result, $i - 1, 'crmid');
         $product_Detail[$i]['delRow' . $i] = "Del";
         $product_Detail[$i]['hdnProductId' . $i] = $productid;
         foreach ($fieldlist as $fieldname) {
             if ($fieldname != "imagename") {
                 $fieldvalue = $this->db->query_result($result, $i - 1, $fieldname);
                 if (strpos($fieldname, "price")) {
                     $fieldvalue = convertFromDollar($fieldvalue, 1);
                 }
             } else {
                 $image_query = 'select ec_attachments.path, ec_attachments.attachmentsid, ec_attachments.name from ec_products left join ec_seattachmentsrel on ec_seattachmentsrel.crmid=ec_products.productid inner join ec_attachments on ec_attachments.attachmentsid=ec_seattachmentsrel.attachmentsid where productid=' . $productid;
                 $result_image = $this->db->query($image_query);
                 $nums = $this->db->num_rows($result_image);
                 if ($nums > 0) {
                     $image_id = $this->db->query_result($result_image, 0, 'attachmentsid');
                     $image_name = $this->db->query_result($result_image, 0, 'name');
                     $image_path = $this->db->query_result($result_image, 0, 'path');
                     $imagename = $image_path . $image_id . "_" . base64_encode_filename($image_name);
                 } else {
                     $imagename = "";
                 }
             }
             $product_Detail[$i][$fieldname . $i] = $fieldvalue;
         }
         $comment = $this->db->query_result($result, $i - 1, 'comment');
         $qty = $this->db->query_result($result, $i - 1, 'quantity');
         $listprice = $this->db->query_result($result, $i - 1, 'listprice');
         $discountPercent = $this->db->query_result($result, $i - 1, 'discount_percent');
         $discountAmount = $this->db->query_result($result, $i - 1, 'discount_amount');
         if (is_numeric($discountPercent)) {
             $discountPercent = $discountPercent * 100;
         }
         //calculate productTotal
         if (is_numeric($discountAmount)) {
             $productTotal = $qty * $discountAmount;
         } else {
             $productTotal = $qty * $listprice;
         }
         $listprice = getConvertedPriceFromDollar($listprice);
         $productTotal = getConvertedPriceFromDollar($productTotal);
         $qty = convertFromDollar($qty, 1);
         $product_Detail[$i]['qty' . $i] = $qty;
         $product_Detail[$i]['listPrice' . $i] = $listprice;
         $product_Detail[$i]['comment' . $i] = $comment;
         $product_Detail[$i]['productTotal' . $i] = $productTotal;
         $product_Detail[$i]['netPrice' . $i] = $productTotal;
     }
     $log->debug("Exiting getAssociatedProducts method ...");
     return $product_Detail;
 }
Пример #2
0
 function getAssociatedProductsFromQuote($quoteid)
 {
     global $log;
     $log->debug("Entering getAssociatedProductsFromQuote() method ...");
     $output = '';
     global $current_user;
     $product_Detail = array();
     $query = "select ec_products.*,ec_inventoryproductrel.*,ec_products.productid as crmid from ec_inventoryproductrel inner join ec_products on ec_products.productid=ec_inventoryproductrel.productid   where ec_inventoryproductrel.id=" . $quoteid . " ORDER BY sequence_no";
     $fieldlist = getProductFieldList("SalesOrder");
     $result = $this->db->query($query);
     $num_rows = $this->db->num_rows($result);
     for ($i = 1; $i <= $num_rows; $i++) {
         $productid = $this->db->query_result($result, $i - 1, 'crmid');
         $product_Detail[$i]['delRow' . $i] = "Del";
         $product_Detail[$i]['hdnProductId' . $i] = $productid;
         foreach ($fieldlist as $fieldname) {
             if ($fieldname == "productname") {
                 $output .= '<td class="crmTableRow small lineOnTop" nowrap>&nbsp;<a href="index.php?action=DetailView&module=Products&record=' . $productid . '" target="_blank">' . $fieldvalue . '</a></td>';
             } elseif (strpos($fieldname, "price")) {
                 $fieldvalue = convertFromDollar($fieldvalue, 1);
                 $output .= '<td class="crmTableRow small lineOnTop" nowrap>&nbsp;' . $fieldvalue . '</td>';
             } else {
                 $output .= '<td class="crmTableRow small lineOnTop" nowrap>&nbsp;' . $fieldvalue . '</td>';
             }
             if ($fieldname != "imagename") {
                 $fieldvalue = $this->db->query_result($result, $i - 1, $fieldname);
                 if (strpos($fieldname, "price")) {
                     $fieldvalue = convertFromDollar($fieldvalue, 1);
                 }
             } else {
                 $image_query = 'select ec_attachments.path, ec_attachments.attachmentsid, ec_attachments.name from ec_products left join ec_seattachmentsrel on ec_seattachmentsrel.crmid=ec_products.productid inner join ec_attachments on ec_attachments.attachmentsid=ec_seattachmentsrel.attachmentsid where productid=' . $productid;
                 $result_image = $this->db->query($image_query);
                 $nums = $this->db->num_rows($result_image);
                 if ($nums > 0) {
                     $image_id = $this->db->query_result($result_image, 0, 'attachmentsid');
                     $image_name = $this->db->query_result($result_image, 0, 'name');
                     $image_path = $this->db->query_result($result_image, 0, 'path');
                     $imagename = $image_path . $image_id . "_" . base64_encode_filename($image_name);
                 } else {
                     $imagename = "";
                 }
             }
             $product_Detail[$i][$fieldname . $i] = $fieldvalue;
         }
         $comment = $this->db->query_result($result, $i - 1, 'comment');
         $qty = $this->db->query_result($result, $i - 1, 'quantity');
         $listprice = $this->db->query_result($result, $i - 1, 'listprice');
         $discountPercent = $this->db->query_result($result, $i - 1, 'discount_percent');
         $discountAmount = $this->db->query_result($result, $i - 1, 'discount_amount');
         if (is_numeric($discountPercent)) {
             $discountPercent = $discountPercent * 100;
         }
         //calculate productTotal
         if (is_numeric($discountAmount)) {
             $productTotal = $qty * $discountAmount;
         } else {
             $productTotal = $qty * $listprice;
         }
         $listprice = getConvertedPriceFromDollar($listprice);
         $productTotal = getConvertedPriceFromDollar($productTotal);
         $qty = convertFromDollar($qty, 1);
         $product_Detail[$i]['qty' . $i] = $qty;
         $product_Detail[$i]['listPrice' . $i] = $discountAmount;
         $product_Detail[$i]['comment' . $i] = $comment;
         $product_Detail[$i]['productTotal' . $i] = $productTotal;
         $product_Detail[$i]['netPrice' . $i] = $productTotal;
     }
     //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 = $this->column_fields['hdnSubTotal'] != '' ? $this->column_fields['hdnSubTotal'] : '0.00';
     $subTotal = getConvertedPriceFromDollar($subTotal);
     $discountPercent = $this->column_fields['hdnDiscountPercent'] != '' ? $this->column_fields['hdnDiscountPercent'] : '0.00';
     $discountAmount = $this->column_fields['hdnDiscountAmount'] != '' ? $this->column_fields['hdnDiscountAmount'] : '0.00';
     if ($this->column_fields['hdnDiscountPercent'] != '' && $this->column_fields['hdnDiscountPercent'] != '0.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 ($this->column_fields['hdnDiscountAmount'] != '') {
         $finalDiscount = $this->column_fields['hdnDiscountAmount'];
         $finalDiscount = getConvertedPriceFromDollar($finalDiscount);
         $discountAmount = getConvertedPriceFromDollar($discountAmount);
         $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"';
     }
     $product_Detail[1]['final_details']['discountTotal_final'] = $finalDiscount;
     //To set the Shipping & Handling charge
     $shCharge = $this->column_fields['hdnS_H_Amount'] != '' ? $this->column_fields['hdnS_H_Amount'] : '0.00';
     $shCharge = getConvertedPriceFromDollar($shCharge);
     $product_Detail[1]['final_details']['shipping_handling_charge'] = $shCharge;
     //To set the Adjustment value
     $adjustment = $this->column_fields['txtAdjustment'] != '' ? $this->column_fields['txtAdjustment'] : '0.00';
     $adjustment = getConvertedPriceFromDollar($adjustment);
     $product_Detail[1]['final_details']['adjustment'] = $adjustment;
     //To set the grand total
     $grandTotal = $this->column_fields['hdnGrandTotal'] != '' ? $this->column_fields['hdnGrandTotal'] : '0.00';
     $grandTotal = getConvertedPriceFromDollar($grandTotal);
     $product_Detail[1]['final_details']['grandTotal'] = $grandTotal;
     $log->debug("Exiting getAssociatedProductsFromQuote method ...");
     return $product_Detail;
 }