/** * Set type of document depending reference document */ public function resolveType() { if (($config = Configs::invoice($this->reff_type)) !== null) { $this->type = $config['type']; } else { $this->addError('reff_type', "Reference type {$this->reff_type} not recognize"); } }
public function getReffConfig() { return Configs::invoice($this->reff_type); }
protected function getReference($reff_type, $reff_id, $origin = []) { $config = Configs::invoice($reff_type); $class = $config['class']; $relation = $config['relation']; $modelRef = $class::findOne($reff_id); $details = ArrayHelper::index($origin, 'product_id'); // $refDtls = $modelRef->$relation; // foreach ($refDtls as $refDtl) { // if (!isset($details[$refDtl->product_id])) { // $details[$refDtl->product_id] = new GoodsMovementDtl([ // 'product_id' => $refDtl->product_id, // ]); // } // if (!empty($config['apply_method'])) { // call_user_func([$refDtl, $config['apply_method']], $details[$refDtl->product_id]); // } // } return [$modelRef, array_values($details)]; }