public function store($data)
 {
     $extra_field = new extra_field();
     $quotationHelper = new quotationHelper();
     $producthelper = new producthelper();
     $rsCarthelper = new rsCarthelper();
     $stockroomhelper = new rsstockroomhelper();
     $extra_field->extra_field_save($data, 16, $data['user_info_id'], $data['user_email']);
     $row = $this->getTable('quotation_detail');
     if ($data['quotation_discount'] > 0) {
         $data['order_total'] = $data['order_total'] - $data['quotation_discount'] - $data['order_total'] * $data['quotation_special_discount'] / 100;
     }
     $data['quotation_number'] = $quotationHelper->generateQuotationNumber();
     $data['quotation_encrkey'] = $quotationHelper->randomQuotationEncrkey();
     $data['quotation_cdate'] = time();
     $data['quotation_mdate'] = time();
     $data['quotation_total'] = $data['order_total'];
     $data['quotation_subtotal'] = $data['order_subtotal'];
     $data['quotation_tax'] = $data['order_tax'];
     $data['quotation_ipaddress'] = !empty($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'unknown';
     if (!$row->bind($data)) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     $row->quotation_status = 2;
     if (!$row->store()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     $quotation_item = array();
     $user_id = $row->user_id;
     $item = $data['order_item'];
     for ($i = 0; $i < count($item); $i++) {
         $product_id = $item[$i]->product_id;
         $quantity = $item[$i]->quantity;
         $product_excl_price = $item[$i]->prdexclprice;
         $product_price = $item[$i]->productprice;
         // Attribute price added
         $generateAttributeCart = $rsCarthelper->generateAttributeArray((array) $item[$i], $user_id);
         $retAttArr = $producthelper->makeAttributeCart($generateAttributeCart, $product_id, $user_id, 0, $quantity);
         $product_attribute = $retAttArr[0];
         // Accessory price
         $generateAccessoryCart = $rsCarthelper->generateAccessoryArray((array) $item[$i], $user_id);
         $retAccArr = $producthelper->makeAccessoryCart($generateAccessoryCart, $product_id, $user_id);
         $product_accessory = $retAccArr[0];
         $wrapper_price = 0;
         $wrapper_vat = 0;
         $wrapper = $producthelper->getWrapper($product_id, $item[$i]->wrapper_data);
         if (count($wrapper) > 0) {
             if ($wrapper[0]->wrapper_price > 0) {
                 $wrapper_vat = $producthelper->getProducttax($product_id, $wrapper[0]->wrapper_price, $user_id);
             }
             $wrapper_price = $wrapper[0]->wrapper_price + $wrapper_vat;
         }
         $rowitem =& $this->getTable('quotation_item_detail');
         $product = $producthelper->getProductById($product_id);
         $quotation_item[$i]->quotation_id = $row->quotation_id;
         $quotation_item[$i]->product_id = $product_id;
         $quotation_item[$i]->is_giftcard = 0;
         $quotation_item[$i]->product_name = $product->product_name;
         $quotation_item[$i]->actualitem_price = $product_price;
         $quotation_item[$i]->product_price = $product_price;
         $quotation_item[$i]->product_excl_price = $product_excl_price;
         $quotation_item[$i]->product_final_price = $product_price * $quantity;
         $quotation_item[$i]->product_attribute = $product_attribute;
         $quotation_item[$i]->product_accessory = $product_accessory;
         $quotation_item[$i]->product_wrapperid = $item[$i]->wrapper_data;
         $quotation_item[$i]->wrapper_price = $wrapper_price;
         $quotation_item[$i]->product_quantity = $quantity;
         if (!$rowitem->bind($quotation_item[$i])) {
             $this->setError($this->_db->getErrorMsg());
             return false;
         }
         if (!$rowitem->store()) {
             $this->setError($this->_db->getErrorMsg());
             return false;
         }
         // Store userfields
         $userfields = JRequest::getVar('extrafields' . $product_id);
         $userfields_id = JRequest::getVar('extrafields_id_' . $product_id);
         for ($ui = 0; $ui < count($userfields); $ui++) {
             $quotationHelper->insertQuotationUserfield($userfields_id[$ui], $rowitem->quotation_item_id, 12, $userfields[$ui]);
         }
         /** my accessory save in table start */
         if (count($generateAccessoryCart) > 0) {
             $attArr = $generateAccessoryCart;
             for ($a = 0; $a < count($attArr); $a++) {
                 $accessory_vat_price = 0;
                 $accessory_attribute = "";
                 $accessory_id = $attArr[$a]['accessory_id'];
                 $accessory_name = $attArr[$a]['accessory_name'];
                 $accessory_price = $attArr[$a]['accessory_price'];
                 $accessory_org_price = $accessory_price;
                 if ($accessory_price > 0) {
                     $accessory_vat_price = $producthelper->getProductTax($rowitem->product_id, $accessory_price, $user_id);
                 }
                 $attchildArr = $attArr[$a]['accessory_childs'];
                 for ($j = 0; $j < count($attchildArr); $j++) {
                     $attribute_id = $attchildArr[$j]['attribute_id'];
                     $accessory_attribute .= urldecode($attchildArr[$j]['attribute_name']) . ":<br/>";
                     $rowattitem =& $this->getTable('quotation_attribute_item');
                     $rowattitem->quotation_att_item_id = 0;
                     $rowattitem->quotation_item_id = $rowitem->quotation_item_id;
                     $rowattitem->section_id = $attribute_id;
                     $rowattitem->section = "attribute";
                     $rowattitem->parent_section_id = $accessory_id;
                     $rowattitem->section_name = $attchildArr[$j]['attribute_name'];
                     $rowattitem->is_accessory_att = 1;
                     if ($attribute_id > 0) {
                         if (!$rowattitem->store()) {
                             $this->setError($this->_db->getErrorMsg());
                             return false;
                         }
                     }
                     $propArr = $attchildArr[$j]['attribute_childs'];
                     for ($k = 0; $k < count($propArr); $k++) {
                         $section_vat = 0;
                         if ($propArr[$k]['property_price'] > 0) {
                             $section_vat = $producthelper->getProducttax($rowitem->product_id, $propArr[$k]['property_price'], $user_id);
                         }
                         $property_id = $propArr[$k]['property_id'];
                         $accessory_attribute .= urldecode($propArr[$k]['property_name']) . " (" . $propArr[$k]['property_oprand'] . $producthelper->getProductFormattedPrice($propArr[$k]['property_price'] + $section_vat) . ")<br/>";
                         $subpropArr = $propArr[$k]['property_childs'];
                         $rowattitem =& $this->getTable('quotation_attribute_item');
                         $rowattitem->quotation_att_item_id = 0;
                         $rowattitem->quotation_item_id = $rowitem->quotation_item_id;
                         $rowattitem->section_id = $property_id;
                         $rowattitem->section = "property";
                         $rowattitem->parent_section_id = $attribute_id;
                         $rowattitem->section_name = $propArr[$k]['property_name'];
                         $rowattitem->section_price = $propArr[$k]['property_price'];
                         $rowattitem->section_vat = $section_vat;
                         $rowattitem->section_oprand = $propArr[$k]['property_oprand'];
                         $rowattitem->is_accessory_att = 1;
                         if ($property_id > 0) {
                             if (!$rowattitem->store()) {
                                 $this->setError($this->_db->getErrorMsg());
                                 return false;
                             }
                         }
                         for ($l = 0; $l < count($subpropArr); $l++) {
                             $section_vat = 0;
                             if ($subpropArr[$l]['subproperty_price'] > 0) {
                                 $section_vat = $producthelper->getProducttax($rowitem->product_id, $subpropArr[$l]['subproperty_price'], $user_id);
                             }
                             $subproperty_id = $subpropArr[$l]['subproperty_id'];
                             $accessory_attribute .= urldecode($subpropArr[$l]['subproperty_name']) . " (" . $subpropArr[$l]['subproperty_oprand'] . $producthelper->getProductFormattedPrice($subpropArr[$l]['subproperty_price'] + $section_vat) . ")<br/>";
                             $rowattitem =& $this->getTable('quotation_attribute_item');
                             $rowattitem->quotation_att_item_id = 0;
                             $rowattitem->quotation_item_id = $rowitem->quotation_item_id;
                             $rowattitem->section_id = $subproperty_id;
                             $rowattitem->section = "subproperty";
                             $rowattitem->parent_section_id = $property_id;
                             $rowattitem->section_name = $subpropArr[$l]['subproperty_name'];
                             $rowattitem->section_price = $subpropArr[$l]['subproperty_price'];
                             $rowattitem->section_vat = $section_vat;
                             $rowattitem->section_oprand = $subpropArr[$l]['subproperty_oprand'];
                             $rowattitem->is_accessory_att = 1;
                             if ($subproperty_id > 0) {
                                 if (!$rowattitem->store()) {
                                     $this->setError($this->_db->getErrorMsg());
                                     return false;
                                 }
                             }
                         }
                     }
                 }
                 $accdata =& $this->getTable('accessory_detail');
                 if ($accessory_id > 0) {
                     $accdata->load($accessory_id);
                 }
                 $accProductinfo = $producthelper->getProductById($accdata->child_product_id);
                 $rowaccitem =& $this->getTable('quotation_accessory_item');
                 $rowaccitem->quotation_item_acc_id = 0;
                 $rowaccitem->quotation_item_id = $rowitem->quotation_item_id;
                 $rowaccitem->accessory_id = $accessory_id;
                 $rowaccitem->accessory_item_sku = $accProductinfo->product_number;
                 $rowaccitem->accessory_item_name = $accessory_name;
                 $rowaccitem->accessory_price = $accessory_org_price;
                 $rowaccitem->accessory_vat = $accessory_vat_price;
                 $rowaccitem->accessory_quantity = $rowitem->product_quantity;
                 $rowaccitem->accessory_item_price = $accessory_price;
                 $rowaccitem->accessory_final_price = $accessory_price * $rowitem->product_quantity;
                 $rowaccitem->accessory_attribute = $accessory_attribute;
                 if ($accessory_id > 0) {
                     if (!$rowaccitem->store()) {
                         $this->setError($this->_db->getErrorMsg());
                         return false;
                     }
                 }
             }
         }
         /** my attribute save in table start */
         if (count($generateAttributeCart) > 0) {
             $attArr = $generateAttributeCart;
             for ($j = 0; $j < count($attArr); $j++) {
                 $attribute_id = $attArr[$j]['attribute_id'];
                 $rowattitem =& $this->getTable('quotation_attribute_item');
                 $rowattitem->quotation_att_item_id = 0;
                 $rowattitem->quotation_item_id = $rowitem->quotation_item_id;
                 $rowattitem->section_id = $attribute_id;
                 $rowattitem->section = "attribute";
                 $rowattitem->parent_section_id = $rowitem->product_id;
                 $rowattitem->section_name = $attArr[$j]['attribute_name'];
                 $rowattitem->is_accessory_att = 0;
                 if ($attribute_id > 0) {
                     if (!$rowattitem->store()) {
                         $this->setError($this->_db->getErrorMsg());
                         return false;
                     }
                 }
                 $propArr = $attArr[$j]['attribute_childs'];
                 for ($k = 0; $k < count($propArr); $k++) {
                     $section_vat = 0;
                     if ($propArr[$k]['property_price'] > 0) {
                         $section_vat = $producthelper->getProducttax($rowitem->product_id, $propArr[$k]['property_price'], $user_id);
                     }
                     $property_id = $propArr[$k]['property_id'];
                     /** product property STOCKROOM update start */
                     $stockroomhelper->updateStockroomQuantity($property_id, $rowitem->product_quantity, "property");
                     $rowattitem =& $this->getTable('quotation_attribute_item');
                     $rowattitem->quotation_att_item_id = 0;
                     $rowattitem->quotation_item_id = $rowitem->quotation_item_id;
                     $rowattitem->section_id = $property_id;
                     $rowattitem->section = "property";
                     $rowattitem->parent_section_id = $attribute_id;
                     $rowattitem->section_name = $propArr[$k]['property_name'];
                     $rowattitem->section_price = $propArr[$k]['property_price'];
                     $rowattitem->section_vat = $section_vat;
                     $rowattitem->section_oprand = $propArr[$k]['property_oprand'];
                     $rowattitem->is_accessory_att = 0;
                     if ($property_id > 0) {
                         if (!$rowattitem->store()) {
                             $this->setError($this->_db->getErrorMsg());
                             return false;
                         }
                     }
                     $subpropArr = $propArr[$k]['property_childs'];
                     for ($l = 0; $l < count($subpropArr); $l++) {
                         $section_vat = 0;
                         if ($subpropArr[$l]['subproperty_price'] > 0) {
                             $section_vat = $producthelper->getProducttax($rowitem->product_id, $subpropArr[$l]['subproperty_price'], $user_id);
                         }
                         $subproperty_id = $subpropArr[$l]['subproperty_id'];
                         /** product subproperty STOCKROOM update start */
                         $stockroomhelper->updateStockroomQuantity($subproperty_id, $rowitem->product_quantity, "subproperty");
                         $rowattitem = $this->getTable('quotation_attribute_item');
                         $rowattitem->quotation_att_item_id = 0;
                         $rowattitem->quotation_item_id = $rowitem->quotation_item_id;
                         $rowattitem->section_id = $subproperty_id;
                         $rowattitem->section = "subproperty";
                         $rowattitem->parent_section_id = $property_id;
                         $rowattitem->section_name = $subpropArr[$l]['subproperty_name'];
                         $rowattitem->section_price = $subpropArr[$l]['subproperty_price'];
                         $rowattitem->section_vat = $section_vat;
                         $rowattitem->section_oprand = $subpropArr[$l]['subproperty_oprand'];
                         $rowattitem->is_accessory_att = 0;
                         if ($subproperty_id > 0) {
                             if (!$rowattitem->store()) {
                                 $this->setError($this->_db->getErrorMsg());
                                 return false;
                             }
                         }
                     }
                 }
             }
         }
     }
     return $row;
 }
Beispiel #2
0
 public function getProductItemInfo($product_id = 0, $quantity = 1, $unique_id = "", $user_id = 0, $newproduct_price = 0)
 {
     $producthelper = new producthelper();
     $wrapperlist = "";
     $accessorylist = "";
     $attributelist = "";
     $productuserfield = "";
     $product_price = 0;
     $product_price_excl_vat = 0;
     $producttax = 0;
     if ($product_id) {
         $productInfo = $producthelper->getProductById($product_id);
         if ($newproduct_price != 0) {
             $product_price_excl_vat = $newproduct_price;
             $producttax = $producthelper->getProductTax($product_id, $newproduct_price, $user_id);
         } else {
             $productArr = $producthelper->getProductNetPrice($product_id, $user_id, $quantity);
             $product_price_excl_vat = $productArr['productPrice'];
             $producttax = $productArr['productVat'];
             // Attribute start
             $attributes_set = array();
             if ($productInfo->attribute_set_id > 0) {
                 $attributes_set = $producthelper->getProductAttribute(0, $productInfo->attribute_set_id, 0, 1);
             }
             $attributes = $producthelper->getProductAttribute($product_id);
             $attributes = array_merge($attributes, $attributes_set);
             $attributelist = $this->replaceAttributeData($product_id, 0, $attributes, $user_id, $unique_id);
             // Accessory start
             $accessory = $producthelper->getProductAccessory(0, $product_id);
             $accessorylist = $this->replaceAccessoryData($product_id, $accessory, $user_id, $unique_id);
             // Wrapper selection box generate
             $wrapperlist = $this->replaceWrapperData($product_id, $user_id, $unique_id);
             $productuserfield = $this->replaceUserfield($product_id, $productInfo->product_template, $unique_id);
         }
     }
     $product_price = $product_price_excl_vat + $producttax;
     $total_price = $product_price * $quantity;
     $totaltax = $producttax * $quantity;
     $displayrespoce = "";
     $displayrespoce .= "<div id='product_price_excl_vat'>" . $product_price_excl_vat . "</div>";
     $displayrespoce .= "<div id='product_tax'>" . $producttax . "</div>";
     $displayrespoce .= "<div id='product_price'>" . $product_price . "</div>";
     $displayrespoce .= "<div id='total_price'>" . $total_price . "</div>";
     $displayrespoce .= "<div id='total_tax'>" . $totaltax . "</div>";
     $displayrespoce .= "<div id='attblock'><table>" . $attributelist . "</table></div>";
     $displayrespoce .= "<div id='productuserfield'><table>" . $productuserfield . "</table></div>";
     $displayrespoce .= "<div id='accessoryblock'><table>" . $accessorylist . "</table></div>";
     $displayrespoce .= "<div id='noteblock'>" . $wrapperlist . "</div>";
     return $displayrespoce;
 }
Beispiel #3
0
 public function addtocart($data = array())
 {
     $app = JFactory::getApplication();
     $Itemid = JRequest::getVar("Itemid");
     $session = JFactory::getSession();
     $db = JFactory::getDbo();
     $carthelper = new rsCarthelper();
     $producthelper = new producthelper();
     $quotationHelper = new quotationHelper();
     $cart = $session->get('cart');
     $idx = (int) $cart['idx'];
     $row_data = $quotationHelper->getQuotationUserfield($data->quotation_item_id);
     $quotation_acc_data = $quotationHelper->getQuotationItemAccessoryDetail($data->quotation_item_id);
     $quotation_att_data = $quotationHelper->getQuotationItemAttributeDetail($data->quotation_item_id, 0, "attribute", $data->product_id);
     // Set session for giftcard
     if ($data->is_giftcard == 1) {
         if ($carthelper->rs_recursiveArraySearch($cart, $data->product_id)) {
             $cart[$idx]['quantity'] += 1;
             $session->set('cart', $cart);
             return;
         } else {
             $cart[$idx]['quantity'] = 1;
         }
         $cart[$idx]['quantity'] = $data->product_quantity;
         $cart[$idx]['giftcard_id'] = $data->product_id;
         $cart[$idx]['product_price'] = $data->product_price;
         $cart[$idx]['product_vat'] = 0;
         $cart[$idx]['product_id'] = '';
         $cart['discount_type'] = 0;
         $cart['discount'] = 0;
         $cart['discount2'] = 0;
         $cart['reciver_email'] = '';
         $cart['reciver_name'] = '';
         for ($i = 0; $i < count($row_data); $i++) {
             $field_name = $row_data[$i]->field_name;
             $cart[$idx][$field_name] = $row_data[$i]->data_txt;
         }
         $cart['idx'] = $idx + 1;
         $session->set('cart', $cart);
         return;
     }
     $cart[$idx]['product_id'] = $data->product_id;
     $cart[$idx]['product_price'] = $data->product_price;
     $cart[$idx]['quantity'] = $data->product_quantity;
     if ($data->product_excl_price) {
         $getprotax = $producthelper->getProductTax($cart[$idx]['product_id'], $data->product_excl_price);
         $cart[$idx]['product_price'] = $data->product_excl_price + $getprotax;
         $cart[$idx]['product_price'] += $data->wrapper_price;
         $cart[$idx]['product_subtotal'] = $cart[$idx]['quantity'] * $cart[$idx]['product_price'];
     }
     $generateAccessoryCart = array();
     for ($i = 0; $i < count($quotation_acc_data); $i++) {
         $generateAccessoryCart[$i]['accessory_id'] = $quotation_acc_data[$i]->accessory_id;
         $generateAccessoryCart[$i]['accessory_name'] = $quotation_acc_data[$i]->accessory_item_name;
         $generateAccessoryCart[$i]['accessory_oprand'] = "+";
         $generateAccessoryCart[$i]['accessory_price'] = $quotation_acc_data[$i]->accessory_price;
         $acc_att_data = $quotationHelper->getQuotationItemAttributeDetail($data->quotation_item_id, 1, "attribute", $quotation_acc_data[$i]->accessory_id);
         $accAttributeCart = array();
         for ($ia = 0; $ia < count($acc_att_data); $ia++) {
             $accPropertyCart = array();
             $accAttributeCart[$ia]['attribute_id'] = $acc_att_data[$ia]->section_id;
             $accAttributeCart[$ia]['attribute_name'] = $acc_att_data[$ia]->section_name;
             $acc_prop_data = $quotationHelper->getQuotationItemAttributeDetail($data->quotation_item_id, 1, "property", $acc_att_data[$ia]->section_id);
             for ($ip = 0; $ip < count($acc_prop_data); $ip++) {
                 $accSubpropertyCart = array();
                 $accPropertyCart[$ip]['property_id'] = $acc_prop_data[$ip]->section_id;
                 $accPropertyCart[$ip]['property_name'] = $acc_prop_data[$ip]->section_name;
                 $accPropertyCart[$ip]['property_oprand'] = $acc_prop_data[$ip]->section_oprand;
                 $acc_subpro_data = $quotationHelper->getQuotationItemAttributeDetail($data->quotation_item_id, 1, "subproperty", $acc_prop_data[$ip]->section_id);
                 for ($isp = 0; $isp < count($acc_subpro_data); $isp++) {
                     $accSubpropertyCart[$isp]['subproperty_id'] = $acc_subpro_data[$isp]->section_id;
                     $accSubpropertyCart[$isp]['subproperty_name'] = $acc_subpro_data[$isp]->section_name;
                     $accSubpropertyCart[$isp]['subproperty_oprand'] = $acc_subpro_data[$isp]->section_oprand;
                 }
                 $accPropertyCart[$ip]['property_childs'] = $accSubpropertyCart;
             }
             $accAttributeCart[$ia]['attribute_childs'] = $accPropertyCart;
         }
         $generateAccessoryCart[$i]['accessory_childs'] = $accAttributeCart;
     }
     $generateAttributeCart = array();
     for ($ia = 0; $ia < count($quotation_att_data); $ia++) {
         $accPropertyCart = array();
         $generateAttributeCart[$ia]['attribute_id'] = $quotation_att_data[$ia]->section_id;
         $generateAttributeCart[$ia]['attribute_name'] = $quotation_att_data[$ia]->section_name;
         $acc_prop_data = $quotationHelper->getQuotationItemAttributeDetail($data->quotation_item_id, 0, "property", $quotation_att_data[$ia]->section_id);
         for ($ip = 0; $ip < count($acc_prop_data); $ip++) {
             $accSubpropertyCart = array();
             $accPropertyCart[$ip]['property_id'] = $acc_prop_data[$ip]->section_id;
             $accPropertyCart[$ip]['property_name'] = $acc_prop_data[$ip]->section_name;
             $accPropertyCart[$ip]['property_oprand'] = $acc_prop_data[$ip]->section_oprand;
             $acc_subpro_data = $quotationHelper->getQuotationItemAttributeDetail($data->quotation_item_id, 0, "subproperty", $acc_prop_data[$ip]->section_id);
             for ($isp = 0; $isp < count($acc_subpro_data); $isp++) {
                 $accSubpropertyCart[$isp]['subproperty_id'] = $acc_subpro_data[$isp]->section_id;
                 $accSubpropertyCart[$isp]['subproperty_name'] = $acc_subpro_data[$isp]->section_name;
                 $accSubpropertyCart[$isp]['subproperty_oprand'] = $acc_subpro_data[$isp]->section_oprand;
             }
             $accPropertyCart[$ip]['property_childs'] = $accSubpropertyCart;
         }
         $generateAttributeCart[$ia]['attribute_childs'] = $accPropertyCart;
     }
     $cart[$idx]['cart_attribute'] = $generateAttributeCart;
     $cart[$idx]['cart_accessory'] = $generateAccessoryCart;
     $cart[$idx]['wrapper_id'] = $data->product_wrapperid;
     $cart[$idx]['wrapper_price'] = $data->wrapper_price;
     $cart[$idx]['product_price_excl_vat'] = $data->product_excl_price;
     $cart['idx'] = $idx + 1;
     for ($i = 0; $i < count($row_data); $i++) {
         $field_name = $row_data[$i]->field_name;
         $cart[$idx][$field_name] = $row_data[$i]->data_txt;
     }
     $session->set('cart', $cart);
 }
 public function getQuotationPriceTax()
 {
     $producthelper = new producthelper();
     $get = JRequest::get('get');
     $product_id = $get['product_id'];
     $user_id = $get['user_id'];
     $newprice = $get['newprice'];
     $vatprice = 0;
     if ($newprice > 0) {
         $vatprice = $producthelper->getProductTax($product_id, $newprice, $user_id);
     }
     echo "<div id='newtax'>" . $vatprice . "</div>";
     exit;
 }
 public function store($postdata)
 {
     $redshopMail = new redshopMail();
     $order_functions = new order_functions();
     $helper = new redhelper();
     $producthelper = new producthelper();
     $rsCarthelper = new rsCarthelper();
     $shippinghelper = new shipping();
     $adminproducthelper = new adminproducthelper();
     $stockroomhelper = new rsstockroomhelper();
     // For barcode generation
     $barcode_code = $order_functions->barcode_randon_number(12, 0);
     $postdata['barcode'] = $barcode_code;
     $row = $this->getTable('order_detail');
     if (!$row->bind($postdata)) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     if (!$row->store()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     $iscrm = $helper->isredCRM();
     if ($iscrm) {
         $postdata['order_id'] = $row->order_id;
         $postdata['debitor_id'] = $postdata['user_info_id'];
         JTable::addIncludePath(REDCRM_ADMIN . '/tables');
         $crmorder =& $this->getTable('crm_order');
         if (!$crmorder->bind($postdata)) {
             $this->setError($this->_db->getErrorMsg());
             return false;
         }
         if (!$crmorder->store()) {
             $this->setError($this->_db->getErrorMsg());
             return false;
         }
         // Update rma table entry
         if (ENABLE_RMA && isset($postdata['rmanotes'])) {
             $rmaInfo = $this->getTable('rma_orders');
             $rmaInfo->rma_number = $postdata['rma_number'];
             $rmaInfo->original_order_id = $postdata['main_order_id'];
             $rmaInfo->credit_note_order_id = $row->order_id;
             $rmaInfo->rma_note = $postdata['rmanotes'];
             $rmaInfo->store();
         }
         JTable::addIncludePath(REDSHOP_ADMIN . '/tables');
     }
     $order_shipping = explode("|", $shippinghelper->decryptShipping(str_replace(" ", "+", $row->ship_method_id)));
     $rowOrderStatus =& $this->getTable('order_status_log');
     $rowOrderStatus->order_id = $row->order_id;
     $rowOrderStatus->order_status = $row->order_status;
     $rowOrderStatus->date_changed = time();
     $rowOrderStatus->customer_note = $row->customer_note;
     $rowOrderStatus->store();
     $billingaddresses = $order_functions->getBillingAddress($row->user_id);
     if (isset($postdata['billisship']) && $postdata['billisship'] == 1) {
         $shippingaddresses = $billingaddresses;
     } else {
         $key = 0;
         $shippingaddresses = $order_functions->getShippingAddress($row->user_id);
         $shipp_users_info_id = isset($postdata['shipp_users_info_id']) && $postdata['shipp_users_info_id'] != 0 ? $postdata['shipp_users_info_id'] : 0;
         if ($shipp_users_info_id != 0) {
             for ($o = 0; $o < count($shippingaddresses); $o++) {
                 if ($shippingaddresses[$o]->users_info_id == $shipp_users_info_id) {
                     $key = $o;
                     break;
                 }
             }
         }
         $shippingaddresses = $shippingaddresses[$key];
     }
     // ORDER DELIVERY TIME IS REMAINING
     $user_id = $row->user_id;
     $item = $postdata['order_item'];
     for ($i = 0; $i < count($item); $i++) {
         $product_id = $item[$i]->product_id;
         $quantity = $item[$i]->quantity;
         $product_excl_price = $item[$i]->prdexclprice;
         $product_price = $item[$i]->productprice;
         // Attribute price added
         $generateAttributeCart = $rsCarthelper->generateAttributeArray((array) $item[$i], $user_id);
         $retAttArr = $producthelper->makeAttributeCart($generateAttributeCart, $product_id, $user_id, 0, $quantity);
         $product_attribute = $retAttArr[0];
         // Accessory price
         $generateAccessoryCart = $rsCarthelper->generateAccessoryArray((array) $item[$i], $user_id);
         $retAccArr = $producthelper->makeAccessoryCart($generateAccessoryCart, $product_id, $user_id);
         $product_accessory = $retAccArr[0];
         $accessory_total_price = $retAccArr[1];
         $accessory_vat_price = $retAccArr[2];
         $wrapper_price = 0;
         $wrapper_vat = 0;
         if ($item[$i]->wrapper_data != 0 && $item[$i]->wrapper_data != '') {
             $wrapper = $producthelper->getWrapper($product_id, $item[$i]->wrapper_data);
             if (count($wrapper) > 0) {
                 if ($wrapper[0]->wrapper_price > 0) {
                     $wrapper_vat = $producthelper->getProducttax($product_id, $wrapper[0]->wrapper_price, $user_id);
                 }
                 $wrapper_price = $wrapper[0]->wrapper_price + $wrapper_vat;
             }
         }
         $product = $producthelper->getProductById($product_id);
         $rowitem =& $this->getTable('order_item_detail');
         if (!$rowitem->bind($postdata)) {
             $this->setError($this->_db->getErrorMsg());
             return false;
         }
         // STOCKROOM update
         $updatestock = $stockroomhelper->updateStockroomQuantity($product_id, $quantity);
         $stockroom_id_list = $updatestock['stockroom_list'];
         $stockroom_quantity_list = $updatestock['stockroom_quantity_list'];
         $rowitem->stockroom_id = $stockroom_id_list;
         $rowitem->stockroom_quantity = $stockroom_quantity_list;
         $rowitem->order_item_id = 0;
         $rowitem->order_id = $row->order_id;
         $rowitem->user_info_id = $row->user_info_id;
         $rowitem->supplier_id = $product->manufacturer_id;
         $rowitem->product_id = $product_id;
         $rowitem->order_item_sku = $product->product_number;
         $rowitem->order_item_name = $product->product_name;
         $rowitem->product_quantity = $quantity;
         $rowitem->product_item_price = $product_price;
         $rowitem->product_item_price_excl_vat = $product_excl_price;
         $rowitem->product_final_price = $product_price * $quantity;
         $rowitem->order_item_currency = REDCURRENCY_SYMBOL;
         $rowitem->order_status = $row->order_status;
         $rowitem->cdate = $row->cdate;
         $rowitem->mdate = $row->cdate;
         $rowitem->product_attribute = $product_attribute;
         $rowitem->product_accessory = $product_accessory;
         $rowitem->wrapper_id = $item[$i]->wrapper_data;
         $rowitem->wrapper_price = $wrapper_price;
         $rowitem->is_giftcard = 0;
         // RedCRM product purchase price
         if ($iscrm) {
             $crmProductHelper = new crmProductHelper();
             $crmproduct = $crmProductHelper->getProductById($product_id);
             $rowitem->product_purchase_price = $crmproduct->product_purchase_price > 0 ? $crmproduct->product_purchase_price : $crmproduct->product_price;
         }
         if ($producthelper->checkProductDownload($product_id)) {
             $medianame = $producthelper->getProductMediaName($product_id);
             for ($j = 0; $j < count($medianame); $j++) {
                 $product_serial_number = $producthelper->getProdcutSerialNumber($product_id);
                 $producthelper->insertProductDownload($product_id, $user_id, $rowitem->order_id, $medianame[$j]->media_name, $product_serial_number->serial_number);
             }
         }
         if (!$rowitem->store()) {
             $this->setError($this->_db->getErrorMsg());
             return false;
         }
         /** my accessory save in table start */
         if (count($generateAccessoryCart) > 0) {
             $attArr = $generateAccessoryCart;
             for ($a = 0; $a < count($attArr); $a++) {
                 $accessory_vat_price = 0;
                 $accessory_attribute = "";
                 $accessory_id = $attArr[$a]['accessory_id'];
                 $accessory_name = $attArr[$a]['accessory_name'];
                 $accessory_price = $attArr[$a]['accessory_price'];
                 $accessory_org_price = $accessory_price;
                 if ($accessory_price > 0) {
                     $accessory_vat_price = $producthelper->getProductTax($product_id, $accessory_price, $user_id);
                 }
                 $attchildArr = $attArr[$a]['accessory_childs'];
                 for ($j = 0; $j < count($attchildArr); $j++) {
                     $attribute_id = $attchildArr[$j]['attribute_id'];
                     $accessory_attribute .= urldecode($attchildArr[$j]['attribute_name']) . ":<br/>";
                     $rowattitem =& $this->getTable('order_attribute_item');
                     $rowattitem->order_att_item_id = 0;
                     $rowattitem->order_item_id = $rowitem->order_item_id;
                     $rowattitem->section_id = $attribute_id;
                     $rowattitem->section = "attribute";
                     $rowattitem->parent_section_id = $accessory_id;
                     $rowattitem->section_name = $attchildArr[$j]['attribute_name'];
                     $rowattitem->is_accessory_att = 1;
                     if ($attribute_id > 0) {
                         if (!$rowattitem->store()) {
                             $this->setError($this->_db->getErrorMsg());
                             return false;
                         }
                     }
                     $propArr = $attchildArr[$j]['attribute_childs'];
                     for ($k = 0; $k < count($propArr); $k++) {
                         $section_vat = 0;
                         if ($propArr[$k]['property_price'] > 0) {
                             $section_vat = $producthelper->getProducttax($product_id, $propArr[$k]['property_price'], $user_id);
                         }
                         $property_id = $propArr[$k]['property_id'];
                         $accessory_attribute .= urldecode($propArr[$k]['property_name']) . " (" . $propArr[$k]['property_oprand'] . $producthelper->getProductFormattedPrice($propArr[$k]['property_price'] + $section_vat) . ")<br/>";
                         $subpropArr = $propArr[$k]['property_childs'];
                         $rowattitem =& $this->getTable('order_attribute_item');
                         $rowattitem->order_att_item_id = 0;
                         $rowattitem->order_item_id = $rowitem->order_item_id;
                         $rowattitem->section_id = $property_id;
                         $rowattitem->section = "property";
                         $rowattitem->parent_section_id = $attribute_id;
                         $rowattitem->section_name = $propArr[$k]['property_name'];
                         $rowattitem->section_price = $propArr[$k]['property_price'];
                         $rowattitem->section_vat = $section_vat;
                         $rowattitem->section_oprand = $propArr[$k]['property_oprand'];
                         $rowattitem->is_accessory_att = 1;
                         if ($property_id > 0) {
                             if (!$rowattitem->store()) {
                                 $this->setError($this->_db->getErrorMsg());
                                 return false;
                             }
                         }
                         for ($l = 0; $l < count($subpropArr); $l++) {
                             $section_vat = 0;
                             if ($subpropArr[$l]['subproperty_price'] > 0) {
                                 $section_vat = $producthelper->getProducttax($rowitem->product_id, $subpropArr[$l]['subproperty_price'], $user_id);
                             }
                             $subproperty_id = $subpropArr[$l]['subproperty_id'];
                             $accessory_attribute .= urldecode($subpropArr[$l]['subproperty_name']) . " (" . $subpropArr[$l]['subproperty_oprand'] . $producthelper->getProductFormattedPrice($subpropArr[$l]['subproperty_price'] + $section_vat) . ")<br/>";
                             $rowattitem =& $this->getTable('order_attribute_item');
                             $rowattitem->order_att_item_id = 0;
                             $rowattitem->order_item_id = $rowitem->order_item_id;
                             $rowattitem->section_id = $subproperty_id;
                             $rowattitem->section = "subproperty";
                             $rowattitem->parent_section_id = $property_id;
                             $rowattitem->section_name = $subpropArr[$l]['subproperty_name'];
                             $rowattitem->section_price = $subpropArr[$l]['subproperty_price'];
                             $rowattitem->section_vat = $section_vat;
                             $rowattitem->section_oprand = $subpropArr[$l]['subproperty_oprand'];
                             $rowattitem->is_accessory_att = 1;
                             if ($subproperty_id > 0) {
                                 if (!$rowattitem->store()) {
                                     $this->setError($this->_db->getErrorMsg());
                                     return false;
                                 }
                             }
                         }
                     }
                 }
                 $accdata =& $this->getTable('accessory_detail');
                 if ($accessory_id > 0) {
                     $accdata->load($accessory_id);
                 }
                 $accProductinfo = $producthelper->getProductById($accdata->child_product_id);
                 $rowaccitem =& $this->getTable('order_acc_item');
                 $rowaccitem->order_item_acc_id = 0;
                 $rowaccitem->order_item_id = $rowitem->order_item_id;
                 $rowaccitem->product_id = $accessory_id;
                 $rowaccitem->order_acc_item_sku = $accProductinfo->product_number;
                 $rowaccitem->order_acc_item_name = $accessory_name;
                 $rowaccitem->order_acc_price = $accessory_org_price;
                 $rowaccitem->order_acc_vat = $accessory_vat_price;
                 $rowaccitem->product_quantity = $quantity;
                 $rowaccitem->product_acc_item_price = $accessory_price;
                 $rowaccitem->product_acc_final_price = $accessory_price * $quantity;
                 $rowaccitem->product_attribute = $accessory_attribute;
                 if ($accessory_id > 0) {
                     if (!$rowaccitem->store()) {
                         $this->setError($this->_db->getErrorMsg());
                         return false;
                     }
                 }
             }
         }
         /** my attribute save in table start */
         if (count($generateAttributeCart) > 0) {
             $attArr = $generateAttributeCart;
             for ($j = 0; $j < count($attArr); $j++) {
                 $attribute_id = $attArr[$j]['attribute_id'];
                 $rowattitem =& $this->getTable('order_attribute_item');
                 $rowattitem->order_att_item_id = 0;
                 $rowattitem->order_item_id = $rowitem->order_item_id;
                 $rowattitem->section_id = $attribute_id;
                 $rowattitem->section = "attribute";
                 $rowattitem->parent_section_id = $rowitem->product_id;
                 $rowattitem->section_name = $attArr[$j]['attribute_name'];
                 $rowattitem->is_accessory_att = 0;
                 if ($attribute_id > 0) {
                     if (!$rowattitem->store()) {
                         $this->setError($this->_db->getErrorMsg());
                         return false;
                     }
                 }
                 $propArr = $attArr[$j]['attribute_childs'];
                 for ($k = 0; $k < count($propArr); $k++) {
                     $section_vat = 0;
                     if ($propArr[$k]['property_price'] > 0) {
                         $section_vat = $producthelper->getProducttax($rowitem->product_id, $propArr[$k]['property_price'], $user_id);
                     }
                     $property_id = $propArr[$k]['property_id'];
                     /** product property STOCKROOM update start */
                     $updatestock = $stockroomhelper->updateStockroomQuantity($property_id, $quantity, "property");
                     $rowattitem =& $this->getTable('order_attribute_item');
                     $rowattitem->order_att_item_id = 0;
                     $rowattitem->order_item_id = $rowitem->order_item_id;
                     $rowattitem->section_id = $property_id;
                     $rowattitem->section = "property";
                     $rowattitem->parent_section_id = $attribute_id;
                     $rowattitem->section_name = $propArr[$k]['property_name'];
                     $rowattitem->section_price = $propArr[$k]['property_price'];
                     $rowattitem->section_vat = $section_vat;
                     $rowattitem->section_oprand = $propArr[$k]['property_oprand'];
                     $rowattitem->is_accessory_att = 0;
                     if ($property_id > 0) {
                         if (!$rowattitem->store()) {
                             $this->setError($this->_db->getErrorMsg());
                             return false;
                         }
                     }
                     $subpropArr = $propArr[$k]['property_childs'];
                     for ($l = 0; $l < count($subpropArr); $l++) {
                         $section_vat = 0;
                         if ($subpropArr[$l]['subproperty_price'] > 0) {
                             $section_vat = $producthelper->getProducttax($product_id, $subpropArr[$l]['subproperty_price'], $user_id);
                         }
                         $subproperty_id = $subpropArr[$l]['subproperty_id'];
                         /** product subproperty STOCKROOM update start */
                         $updatestock = $stockroomhelper->updateStockroomQuantity($subproperty_id, $quantity, "subproperty");
                         $rowattitem =& $this->getTable('order_attribute_item');
                         $rowattitem->order_att_item_id = 0;
                         $rowattitem->order_item_id = $rowitem->order_item_id;
                         $rowattitem->section_id = $subproperty_id;
                         $rowattitem->section = "subproperty";
                         $rowattitem->parent_section_id = $property_id;
                         $rowattitem->section_name = $subpropArr[$l]['subproperty_name'];
                         $rowattitem->section_price = $subpropArr[$l]['subproperty_price'];
                         $rowattitem->section_vat = $section_vat;
                         $rowattitem->section_oprand = $subpropArr[$l]['subproperty_oprand'];
                         $rowattitem->is_accessory_att = 0;
                         if ($subproperty_id > 0) {
                             if (!$rowattitem->store()) {
                                 $this->setError($this->_db->getErrorMsg());
                                 return false;
                             }
                         }
                     }
                 }
             }
         }
         //			$producthelper->insertProdcutUserfield($i,$item,$rowitem->order_item_id,12);
         if (USE_CONTAINER) {
             $producthelper->updateContainerStock($product_id, $quantity, $rowitem->container_id);
         }
         // Store userfields
         $userfields = $item[$i]->extrafieldname;
         $userfields_id = $item[$i]->extrafieldId;
         for ($ui = 0; $ui < count($userfields); $ui++) {
             $adminproducthelper->admin_insertProdcutUserfield($userfields_id[$ui], $rowitem->order_item_id, 12, $userfields[$ui]);
         }
         // redCRM RMA Transaction Entry
         if ($iscrm) {
             if (ENABLE_RMA && $rowitem->product_final_price < 0) {
                 // RMA transation log
                 if (isset($item[$i]->reason)) {
                     $rmaTrans =& $this->getTable('rma_transaction');
                     $rmaTrans->rma_transaction_id = 0;
                     $rmaTrans->rma_number = $postdata['rma_number'];
                     $rmaTrans->order_item_return_id = $rowitem->order_item_id;
                     $rmaTrans->order_item_return_reason = $item[$i]->reason;
                     $rmaTrans->order_item_return_status = $item[$i]->deposition;
                     $rmaTrans->order_item_return_action = $item[$i]->action;
                     $rmaTrans->cdate = time();
                     $rmaTrans->store();
                     if (ENABLE_ITEM_TRACKING_SYSTEM) {
                         // Manage supplier order stock
                         $crmSupplierOrderHelper = new crmSupplierOrderHelper();
                         $senddata['main_order_number'] = $postdata['main_order_number'];
                         $senddata['order_status'] = $row->order_status;
                         $senddata['product_id'] = $rowitem->product_id;
                         $senddata['property_id'] = $property_id;
                         $senddata['subproperty_id'] = $subproperty_id;
                         $senddata['deposition'] = $item[$i]->deposition;
                         $itemqty = $rowitem->product_quantity;
                         for ($r = 0; $r < $itemqty; $r++) {
                             $crmSupplierOrderHelper->manageStockAffectedRMA($senddata);
                         }
                     }
                 }
             }
         }
     }
     $rowpayment =& $this->getTable('order_payment');
     if (!$rowpayment->bind($postdata)) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     $rowpayment->order_id = $row->order_id;
     $rowpayment->payment_method_id = $postdata['payment_method_class'];
     $rowpayment->order_payment_amount = $row->order_total;
     $rowpayment->order_payment_name = $postdata['order_payment_name'];
     $rowpayment->payment_method_class = $postdata['payment_method_class'];
     if (!$rowpayment->store()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     // Add billing Info
     $userrow =& $this->getTable('user_detail');
     $userrow->load($billingaddresses->users_info_id);
     $orderuserrow =& $this->getTable('order_user_detail');
     if (!$orderuserrow->bind($userrow)) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     $orderuserrow->order_id = $row->order_id;
     $orderuserrow->address_type = 'BT';
     if (!$orderuserrow->store()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     // Add shipping Info
     $userrow =& $this->getTable('user_detail');
     if (isset($shippingaddresses->users_info_id)) {
         $userrow->load($shippingaddresses->users_info_id);
     }
     $orderuserrow =& $this->getTable('order_user_detail');
     if (!$orderuserrow->bind($userrow)) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     $orderuserrow->order_id = $row->order_id;
     $orderuserrow->address_type = 'ST';
     if (!$orderuserrow->store()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     if ($row->order_status == CLICKATELL_ORDER_STATUS) {
         $helper->clickatellSMS($row->order_id);
     }
     // Maintan supplier order stck when item tracking system is enabled
     if ($helper->isredCRM()) {
         if (ENABLE_ITEM_TRACKING_SYSTEM) {
             // Supplier order helper object
             $crmSupplierOrderHelper = new crmSupplierOrderHelper();
             $getStatus = array();
             $getStatus['orderstatus'] = $row->order_status;
             $getStatus['paymentstatus'] = $row->order_payment_status;
             $crmSupplierOrderHelper->redSHOPOrderUpdate($row->order_id, $getStatus);
             unset($getStatus);
         }
     }
     $checkOrderStatus = 1;
     if ($postdata['payment_method_class'] == "rs_payment_banktransfer" || $postdata['payment_method_class'] == "rs_payment_banktransfer_discount" || $postdata['payment_method_class'] == "rs_payment_banktransfer2" || $postdata['payment_method_class'] == "rs_payment_banktransfer3" || $postdata['payment_method_class'] == "rs_payment_banktransfer4" || $postdata['payment_method_class'] == "rs_payment_banktransfer5") {
         $checkOrderStatus = 0;
     }
     // Economic Integration start for invoice generate and book current invoice
     if (ECONOMIC_INTEGRATION == 1 && ECONOMIC_INVOICE_DRAFT != 2) {
         $issplit = 0;
         $economic = new economic();
         if (isset($postdata['issplit']) && $postdata['issplit'] == 1) {
             $issplit = 1;
         }
         $economicdata['split_payment'] = $issplit;
         $economicdata['economic_payment_terms_id'] = $postdata['economic_payment_terms_id'];
         $economicdata['economic_design_layout'] = $postdata['economic_design_layout'];
         $economicdata['economic_is_creditcard'] = $postdata['economic_is_creditcard'];
         $payment_name = $postdata['payment_method_class'];
         $paymentArr = explode("rs_payment_", $postdata['payment_method_class']);
         if (count($paymentArr) > 0) {
             $payment_name = $paymentArr[1];
         }
         $economicdata['economic_payment_method'] = $payment_name;
         $invoiceHandle = $economic->createInvoiceInEconomic($row->order_id, $economicdata);
         if (ECONOMIC_INVOICE_DRAFT == 0) {
             $bookinvoicepdf = $economic->bookInvoiceInEconomic($row->order_id, $checkOrderStatus);
             if (is_file($bookinvoicepdf)) {
                 $ret = $redshopMail->sendEconomicBookInvoiceMail($row->order_id, $bookinvoicepdf);
             }
         }
     }
     // ORDER MAIL SEND
     if ($postdata['task'] != "save_without_sendmail") {
         $redshopMail->sendOrderMail($row->order_id);
     }
     return $row;
 }
 public function updateItem($data)
 {
     $producthelper = new producthelper();
     $order_functions = new order_functions();
     $stockroomhelper = new rsstockroomhelper();
     $order_item_id = $data['order_item_id'];
     $orderitemdata = $this->getTable('order_item_detail');
     $orderitemdata->load($order_item_id);
     $orderdata = $this->getTable('order_detail');
     $orderdata->load($this->_id);
     $order_id = $this->_id;
     $product_id = $orderitemdata->product_id;
     $currentStock = $stockroomhelper->getStockroomTotalAmount($product_id);
     $user_id = $orderdata->user_id;
     $productPrice = $data['update_price'];
     $productPrice_new = 0;
     if ($productPrice < 0) {
         $productPrice_new = $productPrice;
         $productPrice = $productPrice * -1;
     }
     $customer_note = $data['customer_note'];
     $product_tax = $producthelper->getProductTax($product_id, $productPrice, $user_id);
     if ($productPrice_new < 0) {
         $product_tax = $product_tax * -1;
         $productPrice = $productPrice_new;
     }
     $new_added_qty = $data['quantity'] - $orderitemdata->product_quantity;
     if ($currentStock >= $new_added_qty || USE_STOCKROOM == 0) {
         $quantity = (int) $data['quantity'];
     } else {
         $quantity = (int) $orderitemdata->product_quantity;
     }
     $product_item_price = $productPrice + $product_tax;
     $product_item_price_excl_vat = $productPrice;
     $product_final_price = $product_item_price * $quantity;
     $productTotalTax = $product_tax * $quantity;
     $subtotal = $product_item_price * $quantity;
     $OrderItems = $order_functions->getOrderItemDetail($order_id);
     $totalTax = $product_tax * $quantity;
     for ($i = 0; $i < count($OrderItems); $i++) {
         if ($order_item_id != $OrderItems[$i]->order_item_id) {
             $itemtax = $OrderItems[$i]->product_item_price - $OrderItems[$i]->product_item_price_excl_vat;
             $totalTax = $totalTax + $itemtax * $OrderItems[$i]->product_quantity;
             $subtotal = $subtotal + $OrderItems[$i]->product_item_price * $OrderItems[$i]->product_quantity;
         }
         if ($order_item_id == $OrderItems[$i]->order_item_id) {
             $newquantity = $OrderItems[$i]->product_quantity - $quantity;
             if ($newquantity > 0) {
                 $stockroomhelper->manageStockAmount($product_id, $newquantity, $orderitemdata->stockroom_id);
             } elseif ($newquantity < 0) {
                 $updatestock = $stockroomhelper->updateStockroomQuantity($product_id, -$newquantity);
                 $stockroom_id_list = $updatestock['stockroom_list'];
                 $stockroom_quantity_list = $updatestock['stockroom_quantity_list'];
                 $orderitemdata->stockroom_id = $stockroom_id_list;
                 $orderitemdata->stockroom_quantity = $stockroom_quantity_list;
             }
             $this->updateAttributeItem($order_item_id, $newquantity, $orderitemdata->stockroom_id);
         }
     }
     $total = $subtotal + $orderdata->order_shipping - abs($orderdata->order_discount);
     $orderitemdata->product_item_price = $product_item_price;
     $orderitemdata->product_item_price_excl_vat = $product_item_price_excl_vat;
     $orderitemdata->product_final_price = $product_final_price;
     $orderitemdata->product_quantity = $quantity;
     $orderitemdata->customer_note = $customer_note;
     $orderdata->order_tax = $totalTax;
     $orderdata->order_total = $total;
     $orderdata->order_subtotal = $subtotal;
     if ($orderitemdata->store()) {
         if (!$orderdata->store()) {
             return false;
         }
         $tmpArr['special_discount'] = $orderdata->special_discount;
         $this->special_discount($tmpArr, true);
     } else {
         return false;
     }
     $order_functions->update_status();
     return true;
 }
Beispiel #7
0
 public function store($data, $post)
 {
     $this->_loadData();
     $quotationHelper = new quotationHelper();
     $producthelper = new producthelper();
     $extra_field = new extra_field();
     $user = JFactory::getUser();
     $user_id = 0;
     $user_info_id = 0;
     $user_email = $post['user_email'];
     if ($user->id) {
         $user_id = $user->id;
         $user_info_id = $this->_data->user_info_id;
         $user_email = $user->email;
     }
     $res = $this->getUserIdByEmail($user_email);
     if (count($res) > 0) {
         $user_id = $res->user_id;
         $user_info_id = $res->users_info_id;
     }
     $list_field = $extra_field->extra_field_save($post, 16, $user_info_id, $user_email);
     $data['quotation_number'] = $quotationHelper->generateQuotationNumber();
     $data['user_id'] = $user_id;
     $data['user_info_id'] = $user_info_id;
     $data['user_email'] = $user_email;
     $data['quotation_total'] = $data['total'];
     $data['quotation_subtotal'] = $data['subtotal'];
     $data['quotation_tax'] = $data['tax'];
     $data['quotation_status'] = 1;
     $data['quotation_cdate'] = time();
     $data['quotation_mdate'] = time();
     $data['quotation_note'] = $data['quotation_note'];
     $data['quotation_ipaddress'] = $_SERVER['REMOTE_ADDR'];
     $data['quotation_encrkey'] = $quotationHelper->randomQuotationEncrkey();
     $data['quotation_discount'] = isset($data['discount2']) ? $data['discount2'] : 0;
     $totalitem = $data['idx'];
     $quotation_item = array();
     $row = $this->getTable('quotation_detail');
     if (!$row->bind($data)) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     if (!$row->store()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     for ($i = 0; $i < $totalitem; $i++) {
         $rowitem = $this->getTable('quotation_item_detail');
         $quotation_item[$i] = new stdClass();
         $quotation_item[$i]->quotation_id = $row->quotation_id;
         if (isset($data[$i]['giftcard_id']) && $data[$i]['giftcard_id'] != 0) {
             $quotation_item[$i]->product_id = $data[$i]['giftcard_id'];
             $giftcardData = $producthelper->getGiftcardData($data[$i]['giftcard_id']);
             $quotation_item[$i]->is_giftcard = 1;
             $quotation_item[$i]->product_name = $giftcardData->giftcard_name;
             $section = 13;
         } else {
             $product = $producthelper->getProductById($data[$i]['product_id']);
             $retAttArr = $producthelper->makeAttributeCart($data[$i]['cart_attribute'], $data[$i]['product_id'], 0, 0, $data[$i]['quantity']);
             $cart_attribute = $retAttArr[0];
             $retAccArr = $producthelper->makeAccessoryCart($data[$i]['cart_accessory'], $data[$i]['product_id']);
             $cart_accessory = $retAccArr[0];
             $quotation_item[$i]->product_id = $data[$i]['product_id'];
             $quotation_item[$i]->is_giftcard = 0;
             $quotation_item[$i]->product_name = $product->product_name;
             $quotation_item[$i]->actualitem_price = $data[$i]['product_price'];
             $quotation_item[$i]->product_price = $data[$i]['product_price'];
             $quotation_item[$i]->product_excl_price = $data[$i]['product_price_excl_vat'];
             $quotation_item[$i]->product_final_price = $data[$i]['product_price'] * $data[$i]['quantity'];
             $quotation_item[$i]->product_attribute = $cart_attribute;
             $quotation_item[$i]->product_accessory = $cart_accessory;
             $quotation_item[$i]->product_wrapperid = $data[$i]['wrapper_id'];
             $quotation_item[$i]->wrapper_price = $data[$i]['wrapper_price'];
             $section = 12;
         }
         $quotation_item[$i]->product_quantity = $data[$i]['quantity'];
         if (!$rowitem->bind($quotation_item[$i])) {
             $this->setError($this->_db->getErrorMsg());
             return false;
         }
         if (!$rowitem->store()) {
             $this->setError($this->_db->getErrorMsg());
             return false;
         }
         /** my accessory save in table start */
         if (count($data[$i]['cart_accessory']) > 0) {
             $attArr = $data[$i]['cart_accessory'];
             for ($a = 0; $a < count($attArr); $a++) {
                 $accessory_vat_price = 0;
                 $accessory_attribute = "";
                 $accessory_id = $attArr[$a]['accessory_id'];
                 $accessory_name = $attArr[$a]['accessory_name'];
                 $accessory_price = $attArr[$a]['accessory_price'];
                 $accessory_org_price = $accessory_price;
                 if ($accessory_price > 0) {
                     $accessory_vat_price = $producthelper->getProductTax($rowitem->product_id, $accessory_price);
                 }
                 $attchildArr = $attArr[$a]['accessory_childs'];
                 for ($j = 0; $j < count($attchildArr); $j++) {
                     $attribute_id = $attchildArr[$j]['attribute_id'];
                     $accessory_attribute .= urldecode($attchildArr[$j]['attribute_name']) . ":<br/>";
                     $rowattitem = $this->getTable('quotation_attribute_item');
                     $rowattitem->quotation_att_item_id = 0;
                     $rowattitem->quotation_item_id = $rowitem->quotation_item_id;
                     $rowattitem->section_id = $attribute_id;
                     $rowattitem->section = "attribute";
                     $rowattitem->parent_section_id = $accessory_id;
                     $rowattitem->section_name = $attchildArr[$j]['attribute_name'];
                     $rowattitem->is_accessory_att = 1;
                     if ($attribute_id > 0) {
                         if (!$rowattitem->store()) {
                             $this->setError($this->_db->getErrorMsg());
                             return false;
                         }
                     }
                     $propArr = $attchildArr[$j]['attribute_childs'];
                     for ($k = 0; $k < count($propArr); $k++) {
                         $section_vat = $producthelper->getProducttax($rowitem->product_id, $propArr[$k]['property_price']);
                         $property_id = $propArr[$k]['property_id'];
                         $accessory_attribute .= urldecode($propArr[$k]['property_name']) . " (" . $propArr[$k]['property_oprand'] . $producthelper->getProductFormattedPrice($propArr[$k]['property_price'] + $section_vat) . ")<br/>";
                         $subpropArr = $propArr[$k]['property_childs'];
                         $rowattitem = $this->getTable('quotation_attribute_item');
                         $rowattitem->quotation_att_item_id = 0;
                         $rowattitem->quotation_item_id = $rowitem->quotation_item_id;
                         $rowattitem->section_id = $property_id;
                         $rowattitem->section = "property";
                         $rowattitem->parent_section_id = $attribute_id;
                         $rowattitem->section_name = $propArr[$k]['property_name'];
                         $rowattitem->section_price = $propArr[$k]['property_price'];
                         $rowattitem->section_vat = $section_vat;
                         $rowattitem->section_oprand = $propArr[$k]['property_oprand'];
                         $rowattitem->is_accessory_att = 1;
                         if ($property_id > 0) {
                             if (!$rowattitem->store()) {
                                 $this->setError($this->_db->getErrorMsg());
                                 return false;
                             }
                         }
                         for ($l = 0; $l < count($subpropArr); $l++) {
                             $section_vat = $producthelper->getProducttax($rowitem->product_id, $subpropArr[$l]['subproperty_price']);
                             $subproperty_id = $subpropArr[$l]['subproperty_id'];
                             $accessory_attribute .= urldecode($subpropArr[$l]['subproperty_name']) . " (" . $subpropArr[$l]['subproperty_oprand'] . $producthelper->getProductFormattedPrice($subpropArr[$l]['subproperty_price'] + $section_vat) . ")<br/>";
                             $rowattitem = $this->getTable('quotation_attribute_item');
                             $rowattitem->quotation_att_item_id = 0;
                             $rowattitem->quotation_item_id = $rowitem->quotation_item_id;
                             $rowattitem->section_id = $subproperty_id;
                             $rowattitem->section = "subproperty";
                             $rowattitem->parent_section_id = $property_id;
                             $rowattitem->section_name = $subpropArr[$l]['subproperty_name'];
                             $rowattitem->section_price = $subpropArr[$l]['subproperty_price'];
                             $rowattitem->section_vat = $section_vat;
                             $rowattitem->section_oprand = $subpropArr[$l]['subproperty_oprand'];
                             $rowattitem->is_accessory_att = 1;
                             if ($subproperty_id > 0) {
                                 if (!$rowattitem->store()) {
                                     $this->setError($this->_db->getErrorMsg());
                                     return false;
                                 }
                             }
                         }
                     }
                 }
                 $accdata = $this->getTable('accessory_detail');
                 if ($accessory_id > 0) {
                     $accdata->load($accessory_id);
                 }
                 $accProductinfo = $producthelper->getProductById($accdata->child_product_id);
                 $rowaccitem = $this->getTable('quotation_accessory_item');
                 $rowaccitem->quotation_item_acc_id = 0;
                 $rowaccitem->quotation_item_id = $rowitem->quotation_item_id;
                 $rowaccitem->accessory_id = $accessory_id;
                 $rowaccitem->accessory_item_sku = $accProductinfo->product_number;
                 $rowaccitem->accessory_item_name = $accessory_name;
                 $rowaccitem->accessory_price = $accessory_org_price;
                 $rowaccitem->accessory_vat = $accessory_vat_price;
                 $rowaccitem->accessory_quantity = $rowitem->product_quantity;
                 $rowaccitem->accessory_item_price = $accessory_price;
                 $rowaccitem->accessory_final_price = $accessory_price * $rowitem->product_quantity;
                 $rowaccitem->accessory_attribute = $accessory_attribute;
                 if ($accessory_id > 0) {
                     if (!$rowaccitem->store()) {
                         $this->setError($this->_db->getErrorMsg());
                         return false;
                     }
                 }
             }
         }
         // My attribute save in table start
         if (count($data[$i]['cart_attribute']) > 0) {
             $attArr = $data[$i]['cart_attribute'];
             for ($j = 0; $j < count($attArr); $j++) {
                 $attribute_id = $attArr[$j]['attribute_id'];
                 $rowattitem = $this->getTable('quotation_attribute_item');
                 $rowattitem->quotation_att_item_id = 0;
                 $rowattitem->quotation_item_id = $rowitem->quotation_item_id;
                 $rowattitem->section_id = $attribute_id;
                 $rowattitem->section = "attribute";
                 $rowattitem->parent_section_id = $rowitem->product_id;
                 $rowattitem->section_name = $attArr[$j]['attribute_name'];
                 $rowattitem->is_accessory_att = 0;
                 if ($attribute_id > 0) {
                     if (!$rowattitem->store()) {
                         $this->setError($this->_db->getErrorMsg());
                         return false;
                     }
                 }
                 $propArr = $attArr[$j]['attribute_childs'];
                 for ($k = 0; $k < count($propArr); $k++) {
                     $section_vat = $producthelper->getProducttax($rowitem->product_id, $propArr[$k]['property_price']);
                     $property_id = $propArr[$k]['property_id'];
                     $rowattitem = $this->getTable('quotation_attribute_item');
                     $rowattitem->quotation_att_item_id = 0;
                     $rowattitem->quotation_item_id = $rowitem->quotation_item_id;
                     $rowattitem->section_id = $property_id;
                     $rowattitem->section = "property";
                     $rowattitem->parent_section_id = $attribute_id;
                     $rowattitem->section_name = $propArr[$k]['property_name'];
                     $rowattitem->section_price = $propArr[$k]['property_price'];
                     $rowattitem->section_vat = $section_vat;
                     $rowattitem->section_oprand = $propArr[$k]['property_oprand'];
                     $rowattitem->is_accessory_att = 0;
                     if ($property_id > 0) {
                         if (!$rowattitem->store()) {
                             $this->setError($this->_db->getErrorMsg());
                             return false;
                         }
                     }
                     $subpropArr = $propArr[$k]['property_childs'];
                     for ($l = 0; $l < count($subpropArr); $l++) {
                         $section_vat = $producthelper->getProducttax($rowitem->product_id, $subpropArr[$l]['subproperty_price']);
                         $subproperty_id = $subpropArr[$l]['subproperty_id'];
                         $rowattitem = $this->getTable('quotation_attribute_item');
                         $rowattitem->quotation_att_item_id = 0;
                         $rowattitem->quotation_item_id = $rowitem->quotation_item_id;
                         $rowattitem->section_id = $subproperty_id;
                         $rowattitem->section = "subproperty";
                         $rowattitem->parent_section_id = $property_id;
                         $rowattitem->section_name = $subpropArr[$l]['subproperty_name'];
                         $rowattitem->section_price = $subpropArr[$l]['subproperty_price'];
                         $rowattitem->section_vat = $section_vat;
                         $rowattitem->section_oprand = $subpropArr[$l]['subproperty_oprand'];
                         $rowattitem->is_accessory_att = 0;
                         if ($subproperty_id > 0) {
                             if (!$rowattitem->store()) {
                                 $this->setError($this->_db->getErrorMsg());
                                 return false;
                             }
                         }
                     }
                 }
             }
         }
         $quotationHelper->manageQuotationUserfield($data[$i], $rowitem->quotation_item_id, $section);
     }
     return $row;
 }
Beispiel #8
0
 if (count($MyTags) > 0) {
     foreach ($MyTags as $row) {
         $data_add = '<div style="float:left;width:' . (THUMB_WIDTH + 50) . 'px;height:' . (THUMB_HEIGHT + 70) . 'px;text-align:center;">';
         $thum_image = "";
         $pname = $row->product_name;
         $link = JRoute::_('index.php?option=com_redshop&view=product&pid=' . $row->product_id . '&Itemid=' . $Itemid);
         if ($row->product_full_image) {
             $thumbUrl = RedShopHelperImages::getImagePath($row->product_full_image, '', 'thumb', 'product', THUMB_WIDTH, THUMB_HEIGHT, USE_IMAGE_SIZE_SWAPPING);
             $thum_image = "<div style='width:" . THUMB_WIDTH . "px;height:" . THUMB_HEIGHT . "px;margin-left:20px;' ><a href='" . $link . "' title=''><img src='" . $thumbUrl . "'></a></div>";
             $data_add .= $thum_image;
         }
         $pname = "<div ><a href='" . $link . "' >" . $pname . "</a></div>";
         $data_add .= $pname;
         // For attribute price count
         $price_add = '<span id="pr_price">' . $extra_data->getProductFormattedPrice($row->product_price) . '</span>';
         $tax_amount = $extra_data->getProductTax($row->product_id);
         if ($tax_amount == 0) {
             $data_add .= '<div>' . $price_add . '</div>';
         } else {
             $data_add .= '<div>' . $extra_data->getProductFormattedPrice($tax_amount) . '</div>';
         }
         // Start cart
         $tax_amount == 0 ? $product_price = $row->product_price : ($product_price = $tax_amount);
         $data_add .= "<div><form name='addtocartscroll" . $i . "' id='addtocartscroll" . $i . "' action='' method='post' >\n\t\t\t\t\t\t\t\t\t\t<input type='hidden'   value='" . $row->product_id . "' name='product_id'>\n\t\t\t\t\t\t\t\t\t\t<input type='hidden'   value='cart' name='view'>\n\t\t\t\t\t\t\t\t\t\t<input type='hidden'   value='add' name='task'>\n\t\t\t\t\t\t\t\t\t\t<input type='hidden'   name='product_price' value='" . $product_price . "'>\n\t\t\t\t\t\t\t\t\t\t<input type='hidden' name='quantity' id='quantity" . $row->product_id . "'  value='1'>\n\t\t\t\t\t\t\t\t\t\t<span onclick='document.addtocartscroll" . $i . ".submit();' align='center' style='background-image:url(" . REDSHOP_FRONT_IMAGES_ABSPATH . ADDTOCART_BACKGROUND . ");border:1px solid #183a5c;background-position:bottom;background-repeat:no-repeat;cursor:pointer;'><span style='cursor: pointer;' >" . JText::_('COM_REDSHOP_ADD_TO_CART') . "</span></span>\n\t\t\t\t\t\t\t\t\t\t</form>\n\t\t\t\t\t\t\t\t\t\t</div>";
         $i++;
         $data_add .= '</div>';
         echo $data_add;
     }
 } else {
     echo "<div>" . JText::_('COM_REDSHOP_NO_PRODUCTS_IN_TAGS') . "</div>";
 }
Beispiel #9
0
$unq = 1;
for ($i = 0; $i < count($quotation_item); $i++) {
    $quo =& $quotation_item[$i];
    if ($quo->is_giftcard == 1) {
        $giftcardData = $producthelper->getGiftcardData($quo->product_id);
        $actual_price = $giftcardData->giftcard_price;
        $product_number = "";
        $section = 13;
    } else {
        $product = $producthelper->getProductById($quo->product_id);
        $actual_price = $product->product_price;
        $product_number = "<br/>" . JText::_('COM_REDSHOP_PRODUCT_NUMBER') . ": ( " . $product->product_number . " ) ";
        $section = 12;
        $vat = 0;
        if ($quo->product_excl_price > 0) {
            $vat = $producthelper->getProductTax($quo->product_id, $quo->product_excl_price, $quotation->user_id);
        }
        $quo->product_price = $quo->product_excl_price + $vat;
    }
    $product_userfield = $quotationHelper->displayQuotationUserfield($quo->quotation_item_id, $section);
    $product_attribute = "<br/>" . $producthelper->makeAttributeQuotation($quo->quotation_item_id, 0, $quo->product_id);
    $product_accessory = "<br/>" . $producthelper->makeAccessoryQuotation($quo->quotation_item_id);
    $wrapper_name = "";
    if ($quo->product_wrapperid) {
        $wrapper = $producthelper->getWrapper($quo->product_id, $quo->product_wrapperid);
        if (count($wrapper) > 0) {
            $wrapper_name = $wrapper[0]->wrapper_name . " (" . $producthelper->getProductFormattedPrice($quo->wrapper_price) . ")";
        }
    }
    $product_title = $quo->product_name . $product_number . $product_attribute . $product_accessory . $product_userfield;
    $product_total = $quo->product_price * $quo->product_quantity;
 public function newQuotationItem($data)
 {
     $quotationHelper = new quotationHelper();
     $rsCarthelper = new rsCarthelper();
     $producthelper = new producthelper();
     $stockroomhelper = new rsstockroomhelper();
     $item = $data['quotation_item'];
     // Get Order Info
     $quotationdata = $this->getTable('quotation_detail');
     $quotationdata->load($this->_id);
     $user_id = $quotationdata->user_id;
     // Set Order Item Info
     $qitemdata = $this->getTable('quotation_item_detail');
     for ($i = 0; $i < count($item); $i++) {
         $product_id = $item[$i]->product_id;
         $quantity = $item[$i]->quantity;
         $product_excl_price = $item[$i]->prdexclprice;
         $product_price = $item[$i]->productprice;
         $product = $producthelper->getProductById($product_id);
         $generateAttributeCart = $rsCarthelper->generateAttributeArray((array) $item[$i], $user_id);
         $retAttArr = $producthelper->makeAttributeCart($generateAttributeCart, $product_id, $user_id, 0, $quantity);
         $product_attribute = $retAttArr[0];
         $generateAccessoryCart = $rsCarthelper->generateAccessoryArray((array) $item[$i], $user_id);
         $retAccArr = $producthelper->makeAccessoryCart($generateAccessoryCart, $product_id, $user_id);
         $product_accessory = $retAccArr[0];
         $wrapper_price = 0;
         $wrapper_vat = 0;
         $wrapper = $producthelper->getWrapper($product_id, $item[$i]->wrapper_data);
         if (count($wrapper) > 0) {
             if ($wrapper[0]->wrapper_price > 0) {
                 $wrapper_vat = $producthelper->getProducttax($product_id, $wrapper[0]->wrapper_price, $user_id);
             }
             $wrapper_price = $wrapper[0]->wrapper_price + $wrapper_vat;
         }
         $qitemdata =& $this->getTable('quotation_item_detail');
         $qitemdata->quotation_item_id = 0;
         $qitemdata->quotation_id = $this->_id;
         $qitemdata->product_id = $product_id;
         $qitemdata->is_giftcard = 0;
         $qitemdata->product_name = $product->product_name;
         $qitemdata->actualitem_price = $product_price;
         $qitemdata->product_price = $product_price;
         $qitemdata->product_excl_price = $product_excl_price;
         $qitemdata->product_final_price = $product_price * $quantity;
         $qitemdata->product_attribute = $product_attribute;
         $qitemdata->product_accessory = $product_accessory;
         $qitemdata->product_wrapperid = $item[$i]->wrapper_data;
         $qitemdata->wrapper_price = $wrapper_price;
         $qitemdata->product_quantity = $quantity;
         if (!$qitemdata->store()) {
             $this->setError($this->_db->getErrorMsg());
             return false;
         }
         /** my accessory save in table start */
         if (count($generateAccessoryCart) > 0) {
             $attArr = $generateAccessoryCart;
             for ($a = 0; $a < count($attArr); $a++) {
                 $accessory_vat_price = 0;
                 $accessory_attribute = "";
                 $accessory_id = $attArr[$a]['accessory_id'];
                 $accessory_name = $attArr[$a]['accessory_name'];
                 $accessory_price = $attArr[$a]['accessory_price'];
                 $accessory_org_price = $accessory_price;
                 if ($accessory_price > 0) {
                     $accessory_vat_price = $producthelper->getProductTax($qitemdata->product_id, $accessory_price, $user_id);
                 }
                 $attchildArr = $attArr[$a]['accessory_childs'];
                 for ($j = 0; $j < count($attchildArr); $j++) {
                     $attribute_id = $attchildArr[$j]['attribute_id'];
                     $accessory_attribute .= urldecode($attchildArr[$j]['attribute_name']) . ":<br/>";
                     $rowattitem =& $this->getTable('quotation_attribute_item');
                     $rowattitem->quotation_att_item_id = 0;
                     $rowattitem->quotation_item_id = $qitemdata->quotation_item_id;
                     $rowattitem->section_id = $attribute_id;
                     $rowattitem->section = "attribute";
                     $rowattitem->parent_section_id = $accessory_id;
                     $rowattitem->section_name = $attchildArr[$j]['attribute_name'];
                     $rowattitem->is_accessory_att = 1;
                     if ($attribute_id > 0) {
                         if (!$rowattitem->store()) {
                             $this->setError($this->_db->getErrorMsg());
                             return false;
                         }
                     }
                     $propArr = $attchildArr[$j]['attribute_childs'];
                     for ($k = 0; $k < count($propArr); $k++) {
                         $section_vat = 0;
                         if ($propArr[$k]['property_price'] > 0) {
                             $section_vat = $producthelper->getProducttax($qitemdata->product_id, $propArr[$k]['property_price'], $user_id);
                         }
                         $property_id = $propArr[$k]['property_id'];
                         $accessory_attribute .= urldecode($propArr[$k]['property_name']) . " (" . $propArr[$k]['property_oprand'] . $producthelper->getProductFormattedPrice($propArr[$k]['property_price'] + $section_vat) . ")<br/>";
                         $subpropArr = $propArr[$k]['property_childs'];
                         $rowattitem =& $this->getTable('quotation_attribute_item');
                         $rowattitem->quotation_att_item_id = 0;
                         $rowattitem->quotation_item_id = $qitemdata->quotation_item_id;
                         $rowattitem->section_id = $property_id;
                         $rowattitem->section = "property";
                         $rowattitem->parent_section_id = $attribute_id;
                         $rowattitem->section_name = $propArr[$k]['property_name'];
                         $rowattitem->section_price = $propArr[$k]['property_price'];
                         $rowattitem->section_vat = $section_vat;
                         $rowattitem->section_oprand = $propArr[$k]['property_oprand'];
                         $rowattitem->is_accessory_att = 1;
                         if ($property_id > 0) {
                             if (!$rowattitem->store()) {
                                 $this->setError($this->_db->getErrorMsg());
                                 return false;
                             }
                         }
                         for ($l = 0; $l < count($subpropArr); $l++) {
                             $section_vat = 0;
                             if ($subpropArr[$l]['subproperty_price'] > 0) {
                                 $section_vat = $producthelper->getProducttax($qitemdata->product_id, $subpropArr[$l]['subproperty_price'], $user_id);
                             }
                             $subproperty_id = $subpropArr[$l]['subproperty_id'];
                             $accessory_attribute .= urldecode($subpropArr[$l]['subproperty_name']) . " (" . $subpropArr[$l]['subproperty_oprand'] . $producthelper->getProductFormattedPrice($subpropArr[$l]['subproperty_price'] + $section_vat) . ")<br/>";
                             $rowattitem =& $this->getTable('quotation_attribute_item');
                             $rowattitem->quotation_att_item_id = 0;
                             $rowattitem->quotation_item_id = $qitemdata->quotation_item_id;
                             $rowattitem->section_id = $subproperty_id;
                             $rowattitem->section = "subproperty";
                             $rowattitem->parent_section_id = $property_id;
                             $rowattitem->section_name = $subpropArr[$l]['subproperty_name'];
                             $rowattitem->section_price = $subpropArr[$l]['subproperty_price'];
                             $rowattitem->section_vat = $section_vat;
                             $rowattitem->section_oprand = $subpropArr[$l]['subproperty_oprand'];
                             $rowattitem->is_accessory_att = 1;
                             if ($subproperty_id > 0) {
                                 if (!$rowattitem->store()) {
                                     $this->setError($this->_db->getErrorMsg());
                                     return false;
                                 }
                             }
                         }
                     }
                 }
                 $accdata =& $this->getTable('accessory_detail');
                 if ($accessory_id > 0) {
                     $accdata->load($accessory_id);
                 }
                 $accProductinfo = $producthelper->getProductById($accdata->child_product_id);
                 $rowaccitem =& $this->getTable('quotation_accessory_item');
                 $rowaccitem->quotation_item_acc_id = 0;
                 $rowaccitem->quotation_item_id = $qitemdata->quotation_item_id;
                 $rowaccitem->accessory_id = $accessory_id;
                 $rowaccitem->accessory_item_sku = $accProductinfo->product_number;
                 $rowaccitem->accessory_item_name = $accessory_name;
                 $rowaccitem->accessory_price = $accessory_org_price;
                 $rowaccitem->accessory_vat = $accessory_vat_price;
                 $rowaccitem->accessory_quantity = $qitemdata->product_quantity;
                 $rowaccitem->accessory_item_price = $accessory_price;
                 $rowaccitem->accessory_final_price = $accessory_price * $qitemdata->product_quantity;
                 $rowaccitem->accessory_attribute = $accessory_attribute;
                 if ($accessory_id > 0) {
                     if (!$rowaccitem->store()) {
                         $this->setError($this->_db->getErrorMsg());
                         return false;
                     }
                 }
             }
         }
         /** my attribute save in table start */
         if (count($generateAttributeCart) > 0) {
             $attArr = $generateAttributeCart;
             for ($j = 0; $j < count($attArr); $j++) {
                 $attribute_id = $attArr[$j]['attribute_id'];
                 $rowattitem =& $this->getTable('quotation_attribute_item');
                 $rowattitem->quotation_att_item_id = 0;
                 $rowattitem->quotation_item_id = $qitemdata->quotation_item_id;
                 $rowattitem->section_id = $attribute_id;
                 $rowattitem->section = "attribute";
                 $rowattitem->parent_section_id = $qitemdata->product_id;
                 $rowattitem->section_name = $attArr[$j]['attribute_name'];
                 $rowattitem->is_accessory_att = 0;
                 if ($attribute_id > 0) {
                     if (!$rowattitem->store()) {
                         $this->setError($this->_db->getErrorMsg());
                         return false;
                     }
                 }
                 $propArr = $attArr[$j]['attribute_childs'];
                 for ($k = 0; $k < count($propArr); $k++) {
                     $section_vat = 0;
                     if ($propArr[$k]['property_price'] > 0) {
                         $section_vat = $producthelper->getProducttax($qitemdata->product_id, $propArr[$k]['property_price'], $user_id);
                     }
                     $property_id = $propArr[$k]['property_id'];
                     /** product property STOCKROOM update start */
                     $updatestock = $stockroomhelper->updateStockroomQuantity($property_id, $qitemdata->product_quantity, "property");
                     $rowattitem =& $this->getTable('quotation_attribute_item');
                     $rowattitem->quotation_att_item_id = 0;
                     $rowattitem->quotation_item_id = $qitemdata->quotation_item_id;
                     $rowattitem->section_id = $property_id;
                     $rowattitem->section = "property";
                     $rowattitem->parent_section_id = $attribute_id;
                     $rowattitem->section_name = $propArr[$k]['property_name'];
                     $rowattitem->section_price = $propArr[$k]['property_price'];
                     $rowattitem->section_vat = $section_vat;
                     $rowattitem->section_oprand = $propArr[$k]['property_oprand'];
                     $rowattitem->is_accessory_att = 0;
                     if ($property_id > 0) {
                         if (!$rowattitem->store()) {
                             $this->setError($this->_db->getErrorMsg());
                             return false;
                         }
                     }
                     $subpropArr = $propArr[$k]['property_childs'];
                     for ($l = 0; $l < count($subpropArr); $l++) {
                         $section_vat = 0;
                         if ($subpropArr[$l]['subproperty_price'] > 0) {
                             $section_vat = $producthelper->getProducttax($qitemdata->product_id, $subpropArr[$l]['subproperty_price'], $user_id);
                         }
                         $subproperty_id = $subpropArr[$l]['subproperty_id'];
                         /** product subproperty STOCKROOM update start */
                         $updatestock = $stockroomhelper->updateStockroomQuantity($subproperty_id, $qitemdata->product_quantity, "subproperty");
                         $rowattitem =& $this->getTable('quotation_attribute_item');
                         $rowattitem->quotation_att_item_id = 0;
                         $rowattitem->quotation_item_id = $qitemdata->quotation_item_id;
                         $rowattitem->section_id = $subproperty_id;
                         $rowattitem->section = "subproperty";
                         $rowattitem->parent_section_id = $property_id;
                         $rowattitem->section_name = $subpropArr[$l]['subproperty_name'];
                         $rowattitem->section_price = $subpropArr[$l]['subproperty_price'];
                         $rowattitem->section_vat = $section_vat;
                         $rowattitem->section_oprand = $subpropArr[$l]['subproperty_oprand'];
                         $rowattitem->is_accessory_att = 0;
                         if ($subproperty_id > 0) {
                             if (!$rowattitem->store()) {
                                 $this->setError($this->_db->getErrorMsg());
                                 return false;
                             }
                         }
                     }
                 }
             }
         }
         // Store userfields
         $userfields = JRequest::getVar('extrafields' . $qitemdata->product_id);
         $userfields_id = JRequest::getVar('extrafields_id_' . $qitemdata->product_id);
         for ($ui = 0; $ui < count($userfields); $ui++) {
             $quotationHelper->insertQuotationUserfield($userfields_id[$ui], $qitemdata->quotation_item_id, 12, $userfields[$ui]);
         }
     }
     // Update Quotation Record
     $QuotationData = $this->getTable('quotation_detail');
     $QuotationData->load($this->_id);
     $QuotationTotal = 0;
     $QuotationSubTotal = 0;
     $QuotationSpDiscount = 0;
     $QuotationDiscount = 0;
     $QuotationTotDiscount = 0;
     $QuotationTax = 0;
     $quotationItems = $quotationHelper->getQuotationProduct($QuotationData->quotation_id);
     for ($q = 0; $q < count($quotationItems); $q++) {
         $QuotationSubTotal += $quotationItems[$q]->product_excl_price * $quotationItems[$q]->product_quantity;
         $QuotationTax += ($quotationItems[$q]->product_final_price - $quotationItems[$q]->product_excl_price) * $quotationItems[$q]->product_quantity;
     }
     // Deduct normal Discount
     $QuotationDiscount = $QuotationData->quotation_discount;
     // Special Discount
     $QuotationSpDiscount = $QuotationData->quotation_special_discount * ($QuotationSubTotal + $QuotationTax) / 100;
     // Total Discount
     $QuotationTotDiscount = $QuotationDiscount + $QuotationSpDiscount;
     // Count final Total
     $QuotationTotal = $QuotationSubTotal + $QuotationTax - $QuotationTotDiscount;
     $QuotationData->quotation_tax = $QuotationTax;
     $QuotationData->quotation_total = $QuotationTotal;
     $QuotationData->quotation_subtotal = $QuotationSubTotal;
     $QuotationData->quotation_mdate = time();
     if (!$QuotationData->store()) {
         return false;
     } else {
         return true;
     }
     // End
     return true;
 }