/** * Executes index action * * @param sfRequest $request A request object */ public function executeIndex(sfWebRequest $request) { $this->transaction_type = $request->getParameter("transaction_type"); $this->transaction_id = $request->getParameter("transaction_id"); $keywords = explode(" ", $request->getParameter("searchstring")); //search in name $query = Doctrine_Query::create()->from('Product p')->orderBy("p.name")->where('p.id != 0'); foreach ($keywords as $keyword) { $query->andWhere("p.name LIKE '%" . $keyword . "%'"); } //search in description $query->orWhere('p.id != 0'); foreach ($keywords as $keyword) { $query->andWhere("p.description LIKE '%" . $keyword . "%'"); } $this->products = $query->execute(); $productids = array(); foreach ($this->products as $product) { $productids[] = $product->getId(); } $stocks = Doctrine_Query::create()->from('Stock s')->whereIn('s.product_id', $productids)->andWhere('s.warehouse_id = ' . SettingsTable::fetch('default_warehouse_id'))->execute(); $this->stockarray = array(); foreach ($stocks as $stock) { $this->stockarray[$stock->getProductId()] = $stock; } }
public function executeView(sfWebRequest $request) { $this->producttype = $this->getRoute()->getObject(); $this->form = $this->configuration->getForm($this->producttype); $this->levels = $request->getParameter("levels"); if ($this->levels == "") { $this->levels = 1; } $query = Doctrine_Query::create()->from('Product p')->where('p.producttype_id=' . $this->producttype->getId())->orderBy('p.name'); if ($this->producttype->getId() == 1 and $request->getParameter("showall") != 1) { $query->limit('50'); } $this->products = $query->execute(); $productids = array(); foreach ($this->products as $product) { $productids[] = $product->getId(); } $stocks = Doctrine_Query::create()->from('Stock s')->whereIn('s.product_id', $productids)->andWhere('s.warehouse_id = ' . SettingsTable::fetch('default_warehouse_id'))->execute(); $this->stockarray = array(); foreach ($stocks as $stock) { $this->stockarray[$stock->getProductId()] = $stock; } }
public static function generate($array) { $event = new Event(); $event->setType($array["type"]); $event->setParentClass(get_class($array["parent"])); $event->setParentId($array["parent"]->getId()); //$event->setParentName($array["parent_name"]); switch ($array["type"]) { case "Inventory": $parent = $event->getParent(); //create stockentry if (get_class($parent) == "Invoicedetail") { $stockentry = StockTable::createStockOut(SettingsTable::fetch("default_warehouse_id"), $parent->getProductId(), $parent->getQty(), $parent->getInvoice()->getDate(), $parent); } else { if (get_class($parent) == "Purchasedetail") { $stockentry = StockTable::createStockIn(SettingsTable::fetch("default_warehouse_id"), $parent->getProductId(), $parent->getQty(), $parent->getPurchase()->getDate(), $parent); } } $event->setChildClass("Stockentry"); $event->setChildrenId($stockentry->getId()); break; } $event->save(); }
public function getAccountEntry($settingname, $create = false, $qty = 0, $description = null) { $this->getAccountentriesArray(); $account_id = SettingsTable::fetch($settingname); $entry = $this->accountentriesarray[$account_id]; //if it does not exist, and "create or update" if (!$entry and $create) { $account = AccountTable::fetchById($account_id); $entry = $account->addEntry($this->getDate(), $qty, "Event", $this->getId(), null, $description); } else { if ($create) { $entry->setQty($qty); $entry->setBalance(null); $entry->save(); $entry->getAccount()->calcFromAccountentry($entry); } } return $entry; }
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 getAccountIds($force = false) { if ($this->accountids == null or $force) { $this->accountids = SettingsTable::fetchAll(); } return $this->accountids; }
function getCurrentQty() { //return $this->getStock(SettingsTable::get("default_warehouse_id"))->getCurrentQty(); $stock = StockTable::fetch(SettingsTable::fetch("default_warehouse_id"), $this->getId()); return $stock->getCurrentQty(); }
public function getSimilarQuote() { return Fetcher::fetchOne("Quote", array('total' => $this->getUnittotal(), 'vendor_id' => SettingsTable::fetch("me_vendor_id"), 'product_id' => $this->getProductId())); }