/** * * @return array */ public function editAction() { $id = $this->getRequest()->getParam('id'); $product = ProductQuery::create()->findByPK($id)->toArray(); $product['prepend'] = substr($product['ItemCode'], 0, 4); $product['key'] = substr($product['ItemCode'], 4, 3); if (ProductGroupQuery::create()->whereAdd(ProductGroup::CODE, $product['product_group_code'])->count()) { $product['id_product_group'] = $productGroup = ProductGroupQuery::create()->whereAdd(ProductGroup::CODE, $product['product_group_code'])->findOne()->getIndex(); } else { $this->setFlash('warning', $this->i18n->_('This product (' . $id . ') cannot be edited because there is not a Product Group associated with it')); $this->_redirect('product/list'); } $product['id_family'] = $family = FamilyQuery::create()->whereAdd(Family::ID_PRODUCT_GROUP, $product['id_product_group'])->whereAdd(Family::CODE, $product['family_code']); if (!$family->count()) { $this->setFlash('error', "It does not exist a Product group 2 with code {$product['family_code']} for Product Group " . ProductGroupQuery::create()->whereAdd(ProductGroup::CODE, $product['product_group_code'])->findOne()->getName()); $this->_redirect('product/list'); } $product['id_family'] = $family = $family->findOne()->getIndex(); $subfamilyCode = $product['subfamily_code']; $itemQuery = ProductQuery::create()->whereAdd(Product::ITEM_CODE, substr($id, 0, 9), ProductQuery::LIKE)->find(); $colors = ColorQuery::create()->find(); $i = 0; $product['brand_code'] = BrandQuery::create()->findByPK($product['id_brand'])->getName(); while ($item = $itemQuery->read()) { $itemCode = $item->getItemCode(); $colorCode = substr($itemCode, -2); $items[$i]['idProduct'] = $item->getItemCode(); $items[$i]['idColor'] = $colors->getByCodeOrEmpty($colorCode)->getIdColor(); $items[$i]['colorCode'] = $colorCode; $items[$i]['status'] = $item->getStatus(); $items[$i]['itemName'] = $item->getItemName(); $items[$i]['itemCode'] = $item->getItemCode(); $items[$i]['vim'] = $item->getIndividualVim(); $i++; } if (!empty($product['CardCode'])) { $supplier = SapSupplierQuery::create()->findByPKOrThrow($product['CardCode'], $this->i18n->_("The Supplier with id {$product['CardCode']} does not exist.")); } else { $supplier = new Supplier(); } if (!empty($product['U_PCS_Def_Freight_Fa'])) { $this->view->freightFare = $this->getFreightInformation($product['U_PCS_Def_Freight_Fa']); } if (!empty($product['CstGrpCode'])) { $customTariffCode = CustomsTariffCodeQuery::create()->findByPK($product['CstGrpCode']); $product['percent'] = $customTariffCode->getPercent(); $product['tariff_remarks'] = ""; } if ($product['U_PCS_Impor_per_id'] > 0) { $this->view->importPermitFile = FileQuery::create()->findByPKOrThrow($product['U_PCS_Impor_per_id'], $this->i18n->_("The File with id {$product['U_PCS_Impor_per_id']} does not exist.")); } $npdFileQuery = \Application\Query\FileQuery::create()->innerJoinNpdSheet()->whereAdd('NpdSheet.id_npd_sheet', $product["id_npd_sheet"])->whereAdd('File.Type', file::$typeFile["typeFile"])->findOne(); if ($npdFileQuery) { $filePath = $npdFileQuery->getContent(); $idFile = $npdFileQuery->getIdFile(); } $subfamilyQuery = SubfamilyQuery::create()->whereAdd(Subfamily::ID_FAMILY, $product['id_family'])->whereAdd(Subfamily::CODE, $subfamilyCode)->findOne(); $product["id_subfamily"] = $subfamilyQuery ? $subfamilyQuery->getIdSubfamily() : null; $currency = CurrencyQuery::create()->whereAdd(Currency::CURRCODE, $product["Currency"])->findOne(); $this->view->npdSheetFile = $filePath; $this->view->id = $id; $this->view->items = $items; $this->view->itemCount = $i; $this->view->product = $product; $this->view->brands = $this->getBrands(); $this->view->countries = $this->getCountries(); $this->view->currencies = $this->getCurrencies(); $this->view->families = $families = $this->getFamilies($product['id_product_group']); $this->view->subfamilies = $this->getSubFamilies($product['id_family'], $product['subfamily_code']); $this->view->productGroups = $productGroups = $this->getProductGroup(); $this->view->supplier = $supplier->toArray(); $this->view->years = $this->getLastYears(); $this->view->defaultShipping = $this->getDefaultShipping(); $this->view->incoterms = $this->getIncoterms(); $this->view->customsTariffCodes = $this->getCustomsTariffCode(); $this->view->colors = $this->getColors(); $this->view->status = $this->getStatus(); $this->view->currency = $currency; $this->view->contentTitle = $this->i18n->_('Edit Product'); $this->view->edit = true; $this->view->action = 'update'; $this->view->setTpl("Form"); //die("<pre>".print_r($product,true)."</pre>"); }
/** * * Gets all Suppliers from SAP, searches the DB for the cardcode, then updates or creates */ public function syncSuppliersAction() { $r = SapSupplierQuery::create()->whereAdd(SapSupplier::CARDTYPE, "s", SapSupplierQuery::EQUAL)->find(); echo "<pre>"; $errors = 0; $new = 0; $updated = 0; while ($r->valid()) { $save = 0; $sapSupplier = $r->read(); echo "Name: " . $sapSupplier->getCardname() . " Code: " . $sapSupplier->getCardcode() . "\n"; $supplier = SupplierQuery::create()->whereAdd(Supplier::SAP_ID_BUSSINESS_ASSOCIATE, $sapSupplier->getCardcode(), SupplierQuery::EQUAL)->findOne(); if (!$supplier instanceof Supplier) { $supplier = new Supplier(); $save = 1; } $currency = CurrencyQuery::create()->whereAdd(Currency::CODE, substr($sapSupplier->getCardcode(), 0, 3))->findOne(); if (!$currency instanceof Currency) { echo " Error! No Currency: " . substr($sapSupplier->getCardcode(), 0, 3) . "\n"; $errors++; continue; } $supplier->setIdCurrency($currency->getIdCurrency()); $supplier->setCardName($sapSupplier->getCardname()); $supplier->setConsistency(0); $supplier->setIdApprovalStatus(1); $supplier->setIdPaymentTerm(1); $supplier->setName($sapSupplier->getCardname()); $supplier->setQuality(0); $supplier->setRfc($sapSupplier->getLicTradNum()); $supplier->setSapIdBussinessAssociate($sapSupplier->getCardcode()); $supplier->setStatus(1); $supplier->setTime(0); $supplier->setIdDefaultPort(1); $supplier->setTypePerson($sapSupplier->getCmpPrivate()); try { $this->getSupplierCatalog()->beginTransaction(); if ($save) { $this->getSupplierCatalog()->create($supplier); $new++; } else { $this->getSupplierCatalog()->update($supplier); $updated++; } $this->getSupplierCatalog()->commit(); } catch (Exception $e) { $this->getSupplierCatalog()->rollBack(); echo "\nError al intentar guardar el proveedor: " . $e->getMessage(); } } echo "\n\nTotals:\nErrors: " . $errors . "\nNew: " . $new . "\nUpdated: " . $updated; die; }