public function save() { if (count($this->quotearrays) == 0) { return; } foreach ($this->quotearrays as $productname => $productdata) { //foreach($productdata["buy"] as $i=>$v)echo $i;die(); //check if buy/sell quote data by vendor exists //if buy exists, update if ($productdata["buy"]["object"]) { $productdata["buy"]["object"]->update(array('price' => $productdata["buy"]["price"], 'discrate' => $productdata["buy"]["discrate"], 'discamt' => $productdata["buy"]["discamt"])); } else { $productdata["buy"]["object"] = QuoteTable::createOne(array('date' => $this->main->pricelistdata->date, 'vendor_id' => $this->main->pricelistdata->vendor->getId(), 'product_id' => $this->main->productdata->items[$productname]["object"]->getId(), 'price' => $productdata["price"], 'discrate' => $productdata["discrate"], 'discamt' => $productdata["discamt"], 'ref_class' => "Pricelist", 'ref_id' => $this->main->pricelistdata->pricelist->getId(), 'mine' => 0)); $productdata["buy"]["object"]->calc(); } //if sell exists, update if ($productdata["sell"]["object"]) { $productdata["sell"]["object"]->update(array('price' => $productdata["sell"]["price"], 'discrate' => $productdata["sell"]["discrate"], 'discamt' => $productdata["sell"]["discamt"])); } else { $productdata["sell"]["object"] = QuoteTable::createOne(array('date' => $this->main->pricelistdata->date, 'vendor_id' => SettingsTable::fetch("me_vendor_id"), 'product_id' => $this->main->productdata->items[$productname]["object"]->getId(), 'price' => $productdata["sell"]["price"], 'discrate' => $productdata["sell"]["discrate"], 'discamt' => $productdata["sell"]["discamt"], 'ref_class' => "Pricelist", 'ref_id' => $this->main->pricelistdata->pricelist->getId(), 'mine' => 1)); $productdata["sell"]["object"]->calc(); } } }
public function updateProduct() { //if price edited, find product quote attached to this invoicedetail, update, and product->calc() $quote = $this->getQuote(); if ($quote) { $detailproduct = $this->getProduct(); $quoteproduct = $quote->getProduct(); if ($quote->getPrice() != $this->getPrice() or $quote->getDiscrate() != $this->getDiscrate() or $quote->getDiscamt() != $this->getDiscamt() or $quote->getProductId() != $this->getProductId()) { $quote->setPrice($this->getPrice()); $quote->setDiscrate($this->getDiscrate()); $quote->setDiscamt($this->getDiscamt()); $quote->setProductId($this->getProductId()); $quote->calc(); //auto save $detailproduct->calcSalePrices(); //if product changed, calc old product if ($quoteproduct->getId() != $detailproduct->getId()) { $quoteproduct->calcSalePrices(); } } } else { //if none, see if product quote by vendor with similar pricing exists. $quote = Fetcher::fetchOne("Quote", array('total' => $this->getUnittotal(), 'vendor_id' => SettingsTable::fetch("me_vendor_id"), 'product_id' => $this->getProductId())); //if it doesn't exist, create it, and product->calc() if (!$quote) { QuoteTable::createOne(array('date' => $this->getInvoice()->getDate(), 'price' => $this->getPrice(), 'discrate' => $this->getDiscrate(), 'discamt' => $this->getDiscamt(), 'vendor_id' => SettingsTable::fetch("me_vendor_id"), 'product_id' => $this->getProductId(), 'ref_class' => "Invoicedetail", 'ref_id' => $this->getId(), 'mine' => 1)); $this->getProduct()->calcSalePrices(); } } }