/**
  * @param  TemplateModel $template
  * @return TemplateModel
  */
 public function create(ModelAbstract $template, $org = null)
 {
     if ($template->getId()) {
         throw new InvalidArgumentException('Supplied template model already has an Id');
     }
     if (!$template->getType()) {
         throw new InvalidArgumentException('Supplied template model needs a type');
     }
     if (!$org) {
         $org = \App::getOrgUserLogged();
     }
     $template->setOrganizationId($org->getId());
     return parent::create($template);
 }
 public function update(models\ModelAbstract $model)
 {
     if (!strlen((string) $model->getId())) {
         throw new AppEx\InvalidArgumentException('Supplied supplServices model must have an Id', \Application\Error\ValidationCodes::MODEL_SUPPL_SERVICE_PACK);
     }
     if ($model->getPublished() == \Application\Model\SupplServicesModel::STATUS_PUBLISHED) {
         // If the supplementary service pack is published, applicationOriginatedSmsMsisdn,
         // currency can't be updated
         if ($model->getCurrency()) {
             unset($model->currency);
         }
     }
     return parent::update($model);
 }
Пример #3
0
 /**
  *
  * @param  Application\Model\OrgModelAbstract $org
  * @return Application\Model\OrgModelAbstract
  */
 public function update(ModelAbstract $org)
 {
     if ($org instanceof OrgCustomerModel) {
         // Check if exists before update
         $checkOrg = $this->load($org->getId());
         if (NULL === $checkOrg) {
             throw new \Application\Exceptions\NotFoundException("Organization not exists");
         }
         // Default + Other billing accounts
         $billings = $org->getAllBillingAccounts();
         // Capture billing cycle info
         foreach ($billings as $billing) {
             if ($billing->billingAccountId !== null) {
                 // Needs modification?
                 $oldBilling = $checkOrg->getBillingAccount($billing->billingAccountId);
                 if (!$oldBilling) {
                     throw new \Application\Exceptions\NotFoundException("Billing account {$billing->billingAccountId} not exists");
                 }
                 $oldBillingDay = $oldBilling->billingCycleStartDay === null || $oldBilling->billingCycleStartDay === $org->billingCycleStart->dayOfMonth ? 0 : $oldBilling->billingCycleStartDay;
                 if (isset($billing->billingCycleStartDay) && $billing->billingCycleStartDay !== $oldBillingDay) {
                     // Send async request
                     $transacionId = $this->changeBillingCycleStartDay($org->getId(), $billing->billingAccountId, $billing->billingCycleStartDay ?: null);
                     // Log action (ignoring async response)
                     \App::audit("Updating customer {$org->getId()} billing account {$billing->billingAccountId} " . "cycle start day from {$billing->billingCycleNextStartDay} to " . "{$billing->billingCycleStartDay}: async transaction {$transacionId}", $org);
                 } else {
                     \App::log()->info("Customer {$org->getId()} billing account {$billing->billingAccountId} " . "cycle start day not modified");
                 }
                 // Unset update info
                 unset($billing->billingCycleStartDay);
             } else {
                 if (!$billing->billingCycleStartDay) {
                     unset($billing->billingCycleStartDay);
                 }
             }
             // Unset read info
             unset($billing->billingCycleNextStartDay);
             unset($billing->billingCycleModifiable);
         }
         if ($org->billingCycleStart->dayOfMonth !== $checkOrg->billingCycleStart->dayOfMonth) {
             $transacionId = $this->changeBillingCycleStartDay($org->getId(), null, $org->billingCycleStart->dayOfMonth);
             \App::log()->info("Updating customer {$org->getId()} default cycle start day from " . "{$checkOrg->billingCycleStart->dayOfMonth} to {$org->billingCycleStart->dayOfMonth}: " . "async transaction {$transacionId}");
         }
     }
     return parent::update($org);
 }
 public function update(models\ModelAbstract $tariff)
 {
     if (!$tariff instanceof TariffPlanLifeCycleModel && !$tariff instanceof TariffPlanServicesModel) {
         throw new AppEx\InvalidArgumentException('Supplied data must be a tariff model');
     }
     if (!strlen((string) $tariff->getId())) {
         throw new AppEx\InvalidArgumentException('Supplied tariff model must have Id');
     }
     // Make sure that defaultTermVoice/T2SModified has a value
     if ($tariff instanceof TariffPlanServicesModel) {
         if ($tariff->getDefaultTermVoice()->getT2SModified() == null) {
             if ($tariff->getDefaultTermVoice()->getT2S() == null) {
                 $tariff->getDefaultTermVoice()->setT2S(0);
             }
             $tariff->getDefaultTermVoice()->setT2SModified($tariff->getDefaultTermVoice()->getT2S());
         }
         //Zone Plan,
         $this->_createZonePlan($tariff);
     }
     $valid = $this->validate($tariff, true);
     $tariff->save();
     if ($tariff instanceof TariffPlanLifeCycleModel) {
         \App::audit('Updated life cycle tariff with Id ' . $tariff->getId(), $tariff);
     } else {
         \App::audit('Updated services tariff with Id ' . $tariff->getId(), $tariff);
     }
     return $tariff->getId();
 }
 /**
  * @param  Application\Model\ServicePackModel $service
  * @return Application\Model\ServicePackModel
  */
 public function update(Model\ModelAbstract $service)
 {
     if (!strlen((string) $service->getId())) {
         throw new AppEx\InvalidArgumentException("The Service Pack must have an id");
     }
     $tariffService = TariffPlanService::getInstance();
     if ($tariff = $service->getTariffPlanLifeCycle()) {
         $tariff->setName((string) microtime(true));
         $tariff->setId(null);
         $tariffService->create($tariff);
         $service->setTariffPlanLifeCycleId($tariff->getId());
     }
     if ($tariff = $service->getTariffPlanServices()) {
         $tariff->setName((string) microtime(true));
         $tariff->setId(null);
         $tariffService->create($tariff);
         $service->setTariffPlanServicesId($tariff->getId());
     }
     $lcService = LifeCycleService::getInstance();
     if ($lc = $service->getLifeCycle()) {
         $lc->setName((string) microtime(true));
         $lc->setId(null);
         $lcService->create($lc);
         $service->setLifeCycleId($lc->getId());
     }
     $restricService = RestrictionService::getInstance();
     if ($re = $service->getRestrictions()) {
         $re->setName((string) microtime(true));
         $re->setId(null);
         $restricService->create($re);
         $service->setRestrictionsId($re->getId());
     }
     $result = parent::update($service);
     $steeringListService = SteeringListService::getInstance();
     $steeringListService->applySteering($service->getRestrictions(), $service->id);
     return $result;
 }