예제 #1
0
 /**
  * @return \Application\Model\Bean\ProductLog
  */
 private function newLog(Product $product, $eventType)
 {
     $now = \Zend_Date::now();
     $log = ProductLogFactory::createFromArray(array('id_product' => $product->getItemCode(), 'id_user' => $this->getUser()->getIdUser(), 'date_log' => $now->get('yyyy-MM-dd HH:mm:ss'), 'event_type' => $eventType, 'note' => ''));
     $this->getCatalog('ProductLogCatalog')->create($log);
     return $log;
 }
예제 #2
0
 /**
  * @return \Application\Model\Bean\ProductCostLog
  */
 private function newProductCostLog(Product $product)
 {
     $lastProduct = ProductQuery::create()->findByPKOrThrow($product->getIdProduct(), $this->i18n->_("The Product with id {$product->getIdProduct()} does not exist"));
     $now = \Zend_Date::now();
     $log = ProductCostLogFactory::createFromArray(array('id_product' => $product->getIdProduct(), 'id_user' => $this->getUser()->getBean()->getIdUser(), 'date' => $now->get('yyyy-MM-dd HH:mm:ss'), 'price_from' => $lastProduct->getCost(), 'id_currency_from' => $lastProduct->getIdCurrency(), 'price_to' => $product->getCost(), 'id_currency_to' => $product->getIdCurrency()));
     $this->getCatalog('ProductCostLogCatalog')->create($log);
     return $log;
 }
예제 #3
0
 /**
  *
  * Gets all Products from SAP, searches the DB for the itemcode, then updates or creates
  */
 public function syncProductsAction()
 {
     $r = SapProductQuery::create()->whereAdd(SapProduct::INVNTITEM, "Y")->find();
     $errors = 0;
     $new = 0;
     $updated = 0;
     echo "<pre>";
     echo "Name, itemcode, clave madre, resultado, mensaje \n";
     while ($r->valid()) {
         $save = 0;
         $sapProduct = $r->read();
         echo "\"" . trim($sapProduct->getItemname()) . "\", " . $sapProduct->getItemcode() . ", " . $sapProduct->getUMadre9() . ", ";
         if (strlen($sapProduct->getItemcode()) != 11) {
             echo "1, Error! ItemCode invalido: len " . strlen($sapProduct->getItemcode()) . "\n";
             $errors++;
             continue;
         }
         $product = ProductQuery::create()->whereAdd(Product::ITEM_CODE, $sapProduct->getItemcode(), ProductQuery::EQUAL)->findOne();
         if (!$product instanceof Product) {
             $product = new Product();
             $save = 1;
         }
         $brand = BrandQuery::create()->whereAdd(Brand::CODE, substr($sapProduct->getItemcode(), 7, 2))->findOne();
         if (!$brand instanceof Brand) {
             echo "2, Error! No Brand: " . substr($sapProduct->getItemcode(), 7, 2) . "\n";
             $errors++;
             continue;
         }
         $product->setIdBrand($brand->getIdBrand());
         $color = ColorQuery::create()->whereAdd(Color::CODE, substr($sapProduct->getItemcode(), 9, 2))->findOne();
         if (!$color instanceof Color) {
             echo "3, Error! No Color: " . substr($sapProduct->getItemcode(), 9, 2) . "\n";
             $errors++;
             continue;
         }
         $product->setIdColor($color->getIdColor());
         $customsTariffCode = CustomsTariffCodeQuery::create()->whereAdd(CustomsTariffCode::CODE, $sapProduct->getCstGrpCode())->findOne();
         if (!$customsTariffCode instanceof CustomsTariffCode) {
             echo "4, Error! No Tax Code: " . $sapProduct->getCstGrpCode() . "\n";
             $errors++;
             continue;
         }
         $product->setIdCustomsTariffCode($customsTariffCode->getIdCustomsTariffCode());
         $productGroup = ProductGroupQuery::create()->whereAdd(ProductGroup::CODE, substr($sapProduct->getItemcode(), 0, 2))->findOne();
         if (!$productGroup instanceof ProductGroup) {
             echo "5, Error! No ProductGroup: " . substr($sapProduct->getItemcode(), 0, 2) . "\n";
             $errors++;
             continue;
         }
         $product->setIdProductGroup($productGroup->getIdProductGroup());
         $family = FamilyQuery::create()->whereAdd(Family::CODE, substr($sapProduct->getItemcode(), 2, 1))->whereAdd(Family::ID_PRODUCT_GROUP, $productGroup->getIdProductGroup())->findOne();
         if (!$family instanceof Family) {
             echo "6, Error! No Family: " . substr($sapProduct->getItemcode(), 2, 1) . "\n";
             $errors++;
             continue;
         }
         $product->setIdFamily($family->getIdFamily());
         $subfamily = SubfamilyQuery::create()->whereAdd(Subfamily::CODE, substr($sapProduct->getItemcode(), 3, 1))->whereAdd(Subfamily::ID_FAMILY, $family->getIdFamily())->findOne();
         if (!$subfamily instanceof Subfamily) {
             echo "7, Error! No SubFamily: " . substr($sapProduct->getItemcode(), 3, 1) . "\n";
             $errors++;
             continue;
         }
         $product->setIdSubfamily($subfamily->getIdSubfamily());
         $product->setBuyUnit($sapProduct->getBuyUnitMsr());
         $product->setCost(0);
         $product->setIdCurrency(1);
         $product->setIdIncoterm(1);
         $product->setImportant(0);
         $product->setInventaryItem($sapProduct->getInvntItem() == 'Y' ? 1 : 0);
         $product->setInventoryUnit($sapProduct->getInvntryUom());
         $product->setItemCode($sapProduct->getItemcode());
         $product->setItemName($sapProduct->getItemname());
         $product->setKeyMother(substr($sapProduct->getItemcode(), 0, 7));
         $product->setMcDepth($sapProduct->getUMCProfundida());
         $product->setMcFront($sapProduct->getUMCFrente());
         $product->setMcHeight($sapProduct->getUMCAltura());
         $product->setMcParts($sapProduct->getUPzasXCaja());
         $product->setMcWeight($sapProduct->getUMCPeso());
         $product->setNumBuy($sapProduct->getNumInBuy());
         $product->setNumSales($sapProduct->getNumInSales());
         $product->setPurchaseItem($sapProduct->getPrchseItem() == 'Y' ? 1 : 0);
         $product->setPzaDepth($sapProduct->getUPzaprofu());
         $product->setPzaDiameter($sapProduct->getUPzadiametro());
         $product->setPzaFront($sapProduct->getUPzafrente());
         $product->setPzaHeight($sapProduct->getUPpzaaltura());
         $product->setPzaWeight($sapProduct->getUPesoXPza());
         $product->setRescue(0);
         $product->setSaiUnit($sapProduct->getSAlUnitMsr());
         $product->setSellItem($sapProduct->getSellItem() == 'Y' ? 1 : 0);
         $product->setStatus($sapProduct->getSWW());
         if ($save) {
             $this->getProductCatalog()->create($product);
             $new++;
         } else {
             $this->getProductCatalog()->update($product);
             $updated++;
         }
         echo "0, Ok! \n";
     }
     echo "\n\nTotals:\nErrors: " . $errors . "\nNew: " . $new . "\nUpdated: " . $updated;
     die;
 }
예제 #4
0
 public function newImportMinMax(Product $product, RestockEntry $restockEntry, $quantity)
 {
     $targetPrice = $this->getMinTargetPriceUSDByIdProduct($product->getItemCode());
     $newQuantityMinMax = false;
     if (!$restockEntry->isManualRestock()) {
         $newQuantityMinMax = ceil($quantity / $product->getMcParts()) * $product->getMcParts() * $targetPrice;
     }
     return $newQuantityMinMax;
 }
예제 #5
0
 /**
  *
  * @return array
  */
 public function listAction()
 {
     $this->view->page = $page = $this->getRequest()->getParam('page') ?: 1;
     $this->view->contentTitle = $this->i18n->_("Requisition List");
     $this->view->setTpl("Index");
     // Get all filter params
     $post = array(Requisition::ID_REQUISITION => $this->getRequest()->getParam(Requisition::ID_REQUISITION, ""), Requisition::STATUS => $this->getRequest()->getParam(Requisition::STATUS, ""), Requisition::NUM_REQUISITION => $this->getRequest()->getParam(Requisition::NUM_REQUISITION, ""), Requisition::ID_DESTINATION_COUNTRY => $this->getRequest()->getParam(Requisition::ID_DESTINATION_COUNTRY, ""), "startDate" => $this->getRequest()->getParam("startDate", ""), "endDate" => $this->getRequest()->getParam("endDate", ""), Requisition::TYPE => $this->getRequest()->getParam(Requisition::TYPE, ""));
     $this->view->post = $post;
     $this->view->filter = $this->createFilterForUrl($post);
     $total = RequisitionQuery::create()->filter($post)->whereAdd(Requisition::STATUS, Requisition::$Status["Inactive"], BaseQuery::NOT_EQUAL)->count();
     $this->view->requisitions = $requisitions = RequisitionQuery::create()->filter($post)->whereAdd(Requisition::STATUS, Requisition::$Status["Inactive"], BaseQuery::NOT_EQUAL)->page($page, $this->getMaxPerPage())->addAscendingOrderBy(Requisition::STATUS)->addAscendingOrderBy(Requisition::DATE)->find();
     if ($requisitions->count() > 0) {
         // Get all requisition entries
         $this->view->entries = $entries = RequisitionEntryQuery::create()->noInactives()->whereAdd(RequisitionEntry::ID_REQUISITION, $requisitions->getPrimaryKeys(), BaseQuery::IN)->find();
         if ($entries->count() > 0) {
             // Get all entry products by product id
             $this->view->products = $products = ProductQuery::create()->whereAdd(Product::ITEM_CODE, $entries->getDistinctProducts(), BaseQuery::IN)->find();
             // Get all distinct Suppliers
             $supplierIds = $entries->getDistinctSuppliers();
             if ($supplierIds > 0) {
                 $this->view->suppliers = SapSupplierQuery::create()->whereAdd(SapSupplier::CARDCODE, $supplierIds, SapSupplierQuery::IN)->find();
             }
         }
     }
     $emptyProduct = new Product();
     $emptyMessage = $this->i18n->_('N/S');
     $emptyProduct->setItemCode($emptyMessage);
     $emptyProduct->setKeyMother($emptyMessage);
     $emptyProduct->setStatus($emptyMessage);
     $this->view->emptyProduct = $emptyProduct;
     // Get all currencies
     $this->view->currencies = $currencies = CurrencyQuery::create()->find();
     $this->view->usd = $usd = CurrencyQuery::create()->findByPK(Currency::$defaultCurrency);
     $this->view->emptyCurrency = new Currency();
     $this->view->currencyExchanges = $a = CurrencyExchangeQuery::create()->addAscendingOrderBy(CurrencyExchange::RATEDATE)->find();
     $this->view->manager = new RequisitionEntryProcessor();
     $this->view->countries = array("" => $this->i18n->_("All")) + CountryQuery::create()->find()->toCombo();
     // Get all status
     $status = Requisition::$Status;
     // Discard status active and inactive and create a array to status combo
     $status = array_filter($status, function ($var) {
         return $var != Requisition::$Status["Active"] && $var != Requisition::$Status["Inactive"] ? true : false;
     });
     $this->view->status = array("" => $this->i18n->_("All")) + array_flip($status);
     // Get requisition Types
     $this->view->types = array("" => $this->i18n->_("All")) + array_flip(Requisition::$Type);
     $this->view->paginator = $this->createPaginator($total, $page);
 }