private function _checkOperation() { $data = $this->_repoBasic->getEntityByPk(Transaction::ENTITY_NAME, [Transaction::ATTR_OPERATION_ID => $this->operationId]); $pvAccounted = isset($data[Transaction::ATTR_VALUE]) ? $data[Transaction::ATTR_VALUE] : null; $this->assertEquals(self::DATA_PV_TOTAL, $pvAccounted); $this->_logger->debug("Total '{$pvAccounted}' PV is accounted for the order #{$this->orderId}."); }
/** * @param AggWarehouse $data * @return null|AggWarehouse */ public function create($data) { $result = null; $def = $this->_manTrans->begin(); try { $tbl = Cfg::ENTITY_MAGE_CATALOGINVENTORY_STOCK; $stockId = $data->getId(); if ($stockId) { /* lookup for catalog inventory stock by ID */ $stockData = $this->_repoGeneric->getEntityByPk($tbl, [Cfg::E_CATINV_STOCK_A_STOCK_ID => $stockId]); if (!$stockData) { /* create top level object (catalog inventory stock) */ $bind = [Cfg::E_CATINV_STOCK_A_WEBSITE_ID => $data->getWebsiteId(), Cfg::E_CATINV_STOCK_A_STOCK_NAME => $data->getCode()]; $stockId = $this->_repoGeneric->addEntity($tbl, $bind); } } else { /* create top level object (catalog inventory stock) */ $bind = [Cfg::E_CATINV_STOCK_A_WEBSITE_ID => $data->getWebsiteId(), Cfg::E_CATINV_STOCK_A_STOCK_NAME => $data->getCode()]; $stockId = $this->_repoGeneric->addEntity($tbl, $bind); } /* then create next level object (warehouse) */ $tbl = EntityWarehouse::ENTITY_NAME; $bind = [EntityWarehouse::ATTR_STOCK_REF => $stockId, EntityWarehouse::ATTR_CODE => $data->getCode(), EntityWarehouse::ATTR_CURRENCY => $data->getCurrency(), EntityWarehouse::ATTR_COUNTRY_CODE => $data->getCountryCode(), EntityWarehouse::ATTR_NOTE => $data->getNote()]; $this->_repoGeneric->addEntity($tbl, $bind); /* commit changes and compose result data object */ $this->_manTrans->commit($def); $result = $data; $result->setId($stockId); } finally { $this->_manTrans->end($def); } return $result; }
public function getLotsByProductId($prodId, $stockId) { /** @var \Magento\Framework\DB\Adapter\AdapterInterface $conn */ $conn = $this->_repoGeneric->getConnection(); /* aliases and tables */ $asStockItem = 'csi'; $asQty = 'pwq'; $asLot = 'pwl'; $tblStockItem = [$asStockItem => $this->_resource->getTableName(Cfg::ENTITY_MAGE_CATALOGINVENTORY_STOCK_ITEM)]; $tblQty = [$asQty => $this->_resource->getTableName(Quantity::ENTITY_NAME)]; $tblLot = [$asLot => $this->_resource->getTableName(Lot::ENTITY_NAME)]; /* SELECT FROM cataloginventory_stock_item */ $query = $conn->select(); $cols = [Alias::AS_STOCK_ITEM_ID => Cfg::E_CATINV_STOCK_ITEM_A_ITEM_ID]; $query->from($tblStockItem, $cols); /* LEFT JOIN prxgt_wrhs_qty pwq */ $on = $asQty . '.' . Quantity::ATTR_STOCK_ITEM_REF . '=' . $asStockItem . '.' . Cfg::E_CATINV_STOCK_ITEM_A_ITEM_ID; $cols = [Alias::AS_QTY => Quantity::ATTR_TOTAL]; $query->joinLeft($tblQty, $on, $cols); // LEFT JOIN prxgt_wrhs_lot pwl $on = $asLot . '.' . Lot::ATTR_ID . '=' . $asQty . '.' . Quantity::ATTR_LOT_REF; $cols = [Alias::AS_LOT_ID => Lot::ATTR_ID, Alias::AS_LOT_CODE => Lot::ATTR_CODE, Alias::AS_LOT_EXP_DATE => Lot::ATTR_EXP_DATE]; $query->joinLeft($tblLot, $on, $cols); /* where */ $where = $asStockItem . '.' . Cfg::E_CATINV_STOCK_ITEM_A_PROD_ID . '=' . (int) $prodId; $where .= ' AND ' . $asStockItem . '.' . Cfg::E_CATINV_STOCK_ITEM_A_STOCK_ID . '=' . (int) $stockId; $query->where($where); /* order by */ $order = $asLot . '.' . Lot::ATTR_EXP_DATE . ' ASC'; $query->order($order); /* fetch data */ $result = $conn->fetchAll($query); return $result; }
public function enableForAllStoreViews() { /* delete all store views data except admin */ $entity = Cfg::ENTITY_MAGE_CATALOG_CATEGORY_EAV_INT; $where = Cfg::E_CATCAT_EAV_INT_STORE_ID . '>' . self::DEF_STORE_VIEW_ID_ADMIN; $this->repoGeneric->deleteEntity($entity, $where); /* enable all categories */ $bind = [Cfg::E_CATCAT_EAV_INT_VALUE => 1]; $where = Cfg::E_CATCAT_EAV_INT_ATTR_ID . '=' . self::DEF_CATEGORY_EAV_ID_IS_ACTIVE; $this->repoGeneric->updateEntity($entity, $bind, $where); }
private function _validateWalletsAfterTeam() { $EXPECT_REPRES_AMOUNT = -6.25; $EXPECT_BALANCE = [1 => 0.0, 2 => 0, 3 => 6.25, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0, 13 => 0]; /* get Asset Type ID foe WALLET_ACTIVE */ $assetTypeId = $this->_repoTypeAsset->getIdByCode(Cfg::CODE_TYPE_ASSET_WALLET_ACTIVE); /* get representative account for WALLET_ACTIVE */ $reqRepresAcc = new AccGetRepresentativeRequest(); $reqRepresAcc->setAssetTypeId($assetTypeId); $respRepresAcc = $this->_callAccAccount->getRepresentative($reqRepresAcc); $represAccId = $respRepresAcc->getData(Account::ATTR_ID); /* get data for WALLET_ACTIVE accounts */ $where = Account::ATTR_ASSET_TYPE_ID . '=' . $assetTypeId; $balanceData = $this->_repoBasic->getEntities(Account::ENTITY_NAME, null, $where); /* convert balances to form that is relative to customer index (not id) */ foreach ($balanceData as $one) { $accId = $one[Account::ATTR_ID]; $custId = $one[Account::ATTR_CUST_ID]; $balance = $one[Account::ATTR_BALANCE]; if ($accId == $represAccId) { $this->assertEquals($EXPECT_REPRES_AMOUNT, $balance); } else { /* get customer index by customer id */ $index = $this->_mapCustomerIndexByMageId[$custId]; $expBalance = $EXPECT_BALANCE[$index]; $this->assertEquals($expBalance, $balance); } } }
public function renameGroups() { $entity = Cfg::ENTITY_MAGE_CUSTOMER_GROUP; /* retail */ $id = [Cfg::E_CUSTGROUP_A_ID => BusinessCodesManager::M_CUST_GROUP_RETAIL]; $bind = [Cfg::E_CUSTGROUP_A_CODE => BusinessCodesManager::B_CUST_GROUP_RETAIL]; $this->_repoGeneric->updateEntityById($entity, $bind, $id); /* distributor */ $id = [Cfg::E_CUSTGROUP_A_ID => BusinessCodesManager::M_CUST_GROUP_DISTRIBUTOR]; $bind = [Cfg::E_CUSTGROUP_A_CODE => BusinessCodesManager::B_CUST_GROUP_DISTRIBUTOR]; $this->_repoGeneric->updateEntityById($entity, $bind, $id); /* wholesaler */ $id = [Cfg::E_CUSTGROUP_A_ID => BusinessCodesManager::M_CUST_GROUP_WHOLESALE]; $bind = [Cfg::E_CUSTGROUP_A_CODE => BusinessCodesManager::B_CUST_GROUP_WHOLESALE]; $this->_repoGeneric->updateEntityById($entity, $bind, $id); }
private function _createTypeOperation() { $bind = [TypeOperation::ATTR_CODE => self::DATA_TYPE_OPER_CODE, TypeOperation::ATTR_NOTE => 'Operation for integration tests.']; $id = $this->_repoGeneric->addEntity(TypeOperation::ENTITY_NAME, $bind); $this->assertTrue($id > 0); $this->typeOperId = $id; $this->_logger->debug("Operation type is created (#{$id})."); }
/** * Update calculated Team Volumes in compressed data table. * * @param $data * @param $calcId */ public function saveValueTv($data, $calcId) { foreach ($data as $custId => $tv) { $whereByCalcId = PtcCompress::ATTR_CALC_ID . '=' . $calcId; $whereByCustId = PtcCompress::ATTR_CUSTOMER_ID . '=' . $custId; $this->_repoBasic->updateEntity(PtcCompress::ENTITY_NAME, [PtcCompress::ATTR_TV => $tv], "{$whereByCalcId} AND {$whereByCustId}"); } }
private function _setRanks() { $data = [[Rank::ATTR_CODE => 'MANAGER', Rank::ATTR_NOTE => 'Manager'], [Rank::ATTR_CODE => 'SENIOR MANAGER', Rank::ATTR_NOTE => 'Senior Manager'], [Rank::ATTR_CODE => 'SUPERVISOR', Rank::ATTR_NOTE => 'Supervisor'], [Rank::ATTR_CODE => 'DIRECTOR', Rank::ATTR_NOTE => 'Director'], [Rank::ATTR_CODE => 'SENIOR DIRECTOR', Rank::ATTR_NOTE => 'Senior Director']]; foreach ($data as $item) { $id = $this->_repoBasic->addEntity(Rank::ENTITY_NAME, $item); $this->_logger->debug("Rank '" . $item[Rank::ATTR_CODE] . "' is added with ID=" . $id . "."); } $this->_logger->debug("Ranks are set."); }
/** * Create new period record and related calculation record. * * @param $calcTypeId * @param $dsBegin * @param $dsEnd * * @return DataObject */ public function addNewPeriodAndCalc($calcTypeId, $dsBegin, $dsEnd) { $result = new DataObject(); /* add new period */ $periodData = [Period::ATTR_CALC_TYPE_ID => $calcTypeId, Period::ATTR_DSTAMP_BEGIN => $dsBegin, Period::ATTR_DSTAMP_END => $dsEnd]; $periodId = $this->_repoBasic->addEntity(Period::ENTITY_NAME, $periodData); $this->_logger->info("New period #{$periodId} for calculation type #{$calcTypeId} is registered ({$dsBegin}-{$dsEnd})."); $periodData[Period::ATTR_ID] = $periodId; $result->setData(self::DATA_PERIOD, $periodData); /* add related calculation */ $dateStarted = $this->_toolDate->getUtcNowForDb(); $calcData = [Calculation::ATTR_PERIOD_ID => $periodId, Calculation::ATTR_DATE_STARTED => $dateStarted, Calculation::ATTR_DATE_ENDED => null, Calculation::ATTR_STATE => Cfg::CALC_STATE_STARTED]; $calcId = $this->_repoBasic->addEntity(Calculation::ENTITY_NAME, $calcData); $this->_logger->info("New calculation #{$calcId} for period #{$periodId} is registered."); $calcData[Calculation::ATTR_ID] = $calcId; $result->setData(self::DATA_CALC, $calcData); return $result; }
private function saveTaxRule($code) { $result = $this->getTaxRuleByCode($code); if (!$result) { $entity = Cfg::ENTITY_MAGE_TAX_CALC_RULE; $bind = [EntityTaxRate::KEY_CODE => $code]; $result = $this->repoGeneric->addEntity($entity, $bind); } return $result; }
/** * @param null $code * @param null $note * * @return int ID of the new entity */ private function _createWarehouse($code, $note) { /* create stock */ $stock = $this->_createMageStock($code); $result = $stock->getStockId(); /* ... then create warehouse itself */ $tbl = Warehouse::ENTITY_NAME; $bind = [Warehouse::ATTR_STOCK_REF => $result, Warehouse::ATTR_CODE => $code, Warehouse::ATTR_NOTE => $note]; $this->_repoGeneric->addEntity($tbl, $bind); return $result; }
public function saveQualificationParams($updates) { $def = $this->_manTrans->begin(); try { foreach ($updates as $item) { $this->_repoBasic->addEntity(Qualification::ENTITY_NAME, $item); } $this->_manTrans->commit($def); } finally { $this->_manTrans->end($def); } }
private function _validateCompression($calcId) { $EXP_COUNT = 11; $EXP_TREE = [1 => 1, 2 => 1, 3 => 1, 4 => 2, 5 => 2, 6 => 3, 8 => 6, 9 => 6, 11 => 3, 12 => 3, 13 => 3]; $where = Compress::ATTR_CALC_ID . '=' . $calcId; $data = $this->_repoCore->getEntities(Compress::ENTITY_NAME, null, $where); $this->assertEquals($EXP_COUNT, count($data)); foreach ($data as $item) { $custId = $item[Compress::ATTR_CUSTOMER_ID]; $parentId = $item[Compress::ATTR_PARENT_ID]; $custNdx = $this->_mapCustomerIndexByMageId[$custId]; $parentNdx = $this->_mapCustomerIndexByMageId[$parentId]; $this->assertEquals($EXP_TREE[$custNdx], $parentNdx); } }
/** * IDs for customers with forced qualification. * * @return array [[Customer::ATTR_CUSTOMER_ID=>..., Customer::ATTR_HUMAN_REF=>...], ...] */ private function _getForcedCustomersIds() { $mlmIds = array_keys($this->QUALIFIED_CUSTOMERS); $where = ''; foreach ($mlmIds as $one) { /* skip first iteration */ if (strlen($where) > 0) { $where .= ' OR '; } $quoted = $this->_conn->quote($one); $where .= Customer::ATTR_HUMAN_REF . "=\"{$quoted}\""; } $cols = [Customer::ATTR_CUSTOMER_ID, Customer::ATTR_HUMAN_REF]; $result = $this->_repoBasic->getEntities(Customer::ENTITY_NAME, $cols, $where); return $result; }
/** @inheritdoc */ public function updateById($id, $data) { if (is_array($id)) { /* probably this is complex PK */ $where = ''; foreach ($id as $key => $value) { $val = is_int($value) ? $value : $this->_conn->quote($value); $where .= "({$key}={$val}) AND "; } $where .= '1'; // WHERE ... AND 1; } else { $val = is_int($id) ? $id : $this->_conn->quote($id); $where = $this->_idFieldName . '=' . $val; } $result = $this->_repoGeneric->updateEntity($this->_entityName, $data, $where); return $result; }
public function getRepresentativeCustomerId() { if (is_null($this->_cachedRepresCustId)) { $conn = $this->_conn; /* there is no cached value for the customer ID, select data from DB */ $where = Cfg::E_CUSTOMER_A_EMAIL . '=' . $conn->quote(self::CUSTOMER_REPRESENTATIVE_EMAIL); $data = $this->_repoGeneric->getEntities(Cfg::ENTITY_MAGE_CUSTOMER, Cfg::E_CUSTOMER_A_ENTITY_ID, $where); if (count($data) == 0) { $bind = [Cfg::E_CUSTOMER_A_WEBSITE_ID => self::ADMIN_WEBSITE_ID, Cfg::E_CUSTOMER_A_EMAIL => self::CUSTOMER_REPRESENTATIVE_EMAIL]; $id = $this->_repoGeneric->addEntity(Cfg::ENTITY_MAGE_CUSTOMER, $bind); if ($id > 0) { $this->_cachedRepresCustId = $id; } } else { $first = reset($data); $this->_cachedRepresCustId = $first[Cfg::E_CUSTOMER_A_ENTITY_ID]; } } return $this->_cachedRepresCustId; }
public function getSaleOrderCustomerId($saleId) { $data = $this->_repoGeneric->getEntityByPk(Cfg::ENTITY_MAGE_SALES_ORDER, [Cfg::E_COMMON_A_ENTITY_ID => $saleId], [Cfg::E_SALE_ORDER_A_CUSTOMER_ID]); $result = $data[Cfg::E_SALE_ORDER_A_CUSTOMER_ID]; return $result; }
private function _setRanks() { $data = [[Rank::ATTR_CODE => Def::RANK_MANAGER, Rank::ATTR_NOTE => 'Manager (#01, lowest).'], [Rank::ATTR_CODE => Def::RANK_SEN_MANAGER, Rank::ATTR_NOTE => 'Senior Manager (#02).'], [Rank::ATTR_CODE => Def::RANK_SUPERVISOR, Rank::ATTR_NOTE => 'Supervisor (#3).'], [Rank::ATTR_CODE => Def::RANK_DIRECTOR, Rank::ATTR_NOTE => 'Director (#4).'], [Rank::ATTR_CODE => Def::RANK_SEN_DIRECTOR, Rank::ATTR_NOTE => 'Senior Director (#5).'], [Rank::ATTR_CODE => Def::RANK_EXEC_DIRECTOR, Rank::ATTR_NOTE => 'Executive Director (#6).'], [Rank::ATTR_CODE => Def::RANK_SEN_VICE, Rank::ATTR_NOTE => 'Senior Vice President (#7).'], [Rank::ATTR_CODE => Def::RANK_EXEC_VICE, Rank::ATTR_NOTE => 'Executive Vice President (#8).'], [Rank::ATTR_CODE => Def::RANK_PRESIDENT, Rank::ATTR_NOTE => 'President Director (#9, highest).']]; foreach ($data as $item) { $this->_repoBasic->addEntity(Rank::ENTITY_NAME, $item); } $this->_logger->debug("Ranks are set."); }
/** * Registry new relation between instances in Odoo & Magento. * @param string $entityName * @param int $mageId * @param int $odooId */ protected function _registerMageIdForOdooId($entityName, $mageId, $odooId) { $bind = [IOdooEntity::ATTR_MAGE_REF => (int) $mageId, IOdooEntity::ATTR_ODOO_REF => (int) $odooId]; $this->_repoBasic->addEntity($entityName, $bind); }