public function closePeriod(array $input)
  {
    $canBeClosed = true;

    $this->DB->transaction(function() use ($input, &$canBeClosed)
    {
      $loggedUserId = $this->AuthenticationManager->getLoggedUserId();
      $organizationId = $this->AuthenticationManager->getCurrentUserOrganization('id');

      if($this->JournalVoucher->getByOrganizationByPeriodAndByStatus($organizationId, array($input['id']), 'A')->count() > 0)
      {
        $canBeClosed = false;
        return;
      }

      $Period = $this->Period->byId($input['id']);
      $Journal = $this->Journal->create(array('journalized_id' => $input['id'], 'journalized_type' => $this->Period->getTable(), 'user_id' => $loggedUserId, 'organization_id' => $organizationId));
      // $this->Journal->attachDetail($Journal->id, array('field' => $this->Lang->get('decima-accounting::journal-management.status'), 'field_lang_key' => 'decima-accounting::journal-management.status', 'old_value' => $this->Lang->get('decima-accounting::period-management.opened'), 'new_value' => $this->Lang->get('decima-accounting::period-management.closed')), $Journal);
      $this->Journal->attachDetail($Journal->id, array('note' => $this->Lang->get('decima-accounting::period-management.periodClosedJournal', array('period' => $this->Lang->get('decima-accounting::period-management.' . $Period->month))), $Journal));
      $this->Period->update(array('is_closed' => true), $Period);
    });

    if(!$canBeClosed)
    {
      return json_encode(array('success' => false, 'info' => $this->Lang->get('decima-accounting::period-management.voucherException')));
    }

    return json_encode(array('success' => $this->Lang->get('form.defaultSuccessOperationMessage'), 'periods' => $this->getPeriods(), 'periodsFilter' => $this->getPeriods2()));
  }
public function closePeriod(array $input)
  {
    $canBeClosed = true;

    $this->DB->transaction(function() use ($input, &$canBeClosed)
    {
      $loggedUserId = $this->AuthenticationManager->getLoggedUserId();
      $organizationId = $this->AuthenticationManager->getCurrentUserOrganization('id');

      if($this->JournalVoucher->getByOrganizationByPeriodAndByStatus($organizationId, array($input['id']), 'A')->count() > 0)
      {
        $canBeClosed = false;
        return;
      }

      $Period = $this->Period->byId($input['id']);
      $Journal = $this->Journal->create(array('journalized_id' => $input['id'], 'journalized_type' => $this->Period->getTable(), 'user_id' => $loggedUserId, 'organization_id' => $organizationId));
      // $this->Journal->attachDetail($Journal->id, array('field' => $this->Lang->get('decima-accounting::journal-management.status'), 'field_lang_key' => 'decima-accounting::journal-management.status', 'old_value' => $this->Lang->get('decima-accounting::period-management.opened'), 'new_value' => $this->Lang->get('decima-accounting::period-management.closed')), $Journal);
      $this->Journal->attachDetail($Journal->id, array('note' => $this->Lang->get('decima-accounting::period-management.periodClosedJournal', array('period' => $this->Lang->get('decima-accounting::period-management.' . $Period->month))), $Journal));
      $this->Period->update(array('is_closed' => true), $Period);
    });

    if(!$canBeClosed)
    {
      return json_encode(array('success' => false, 'info' => $this->Lang->get('decima-accounting::period-management.voucherException')));
    }

    return json_encode(array('success' => $this->Lang->get('form.defaultSuccessOperationMessage'), 'periods' => $this->getPeriods(), 'periodsFilter' => $this->getPeriods2()));
  }
public function closePeriod ( array $ input ) { $ canBeClosed = true ; $ this -> DB -> transaction ( function ( ) use ( $ input , & $ canBeClosed ) { $ loggedUserId = $ this -> AuthenticationManager -> getLoggedUserId ( ) ; $ organizationId = $ this -> AuthenticationManager -> getCurrentUserOrganization ( 'id' ) ; if ( $ this -> JournalVoucher -> getByOrganizationByPeriodAndByStatus ( $ organizationId , array ( $ input [ 'id' ] ) , 'A' ) -> count ( ) > 0 ) { $ canBeClosed = false ; return ; } $ Period = $ this -> Period -> byId ( $ input [ 'id' ] ) ; $ Journal = $ this -> Journal -> create ( array ( 'journalized_id' => $ input [ 'id' ] , 'journalized_type' => $ this -> Period -> getTable ( ) , 'user_id' => $ loggedUserId , 'organization_id' => $ organizationId ) ) ; // $this->Journal->attachDetail($Journal->id, array('field' => $this->Lang->get('decima-accounting::journal-management.status'), 'field_lang_key' => 'decima-accounting::journal-management.status', 'old_value' => $this->Lang->get('decima-accounting::period-management.opened'), 'new_value' => $this->Lang->get('decima-accounting::period-management.closed')), $Journal); $ this -> Journal -> attachDetail ( $ Journal -> id , array ( 'note' => $ this -> Lang -> get ( 'decima-accounting::period-management.periodClosedJournal' , array ( 'period' => $ this -> Lang -> get ( 'decima-accounting::period-management.' . $ Period -> month ) ) ) , $ Journal ) ) ; $ this -> Period -> update ( array ( 'is_closed' => true ) , $ Period ) ; } ) ; if ( ! $ canBeClosed ) { return json_encode ( array ( 'success' => false , 'info' => $ this -> Lang -> get ( 'decima-accounting::period-management.voucherException' ) ) ) ; } return json_encode ( array ( 'success' => $ this -> Lang -> get ( 'form.defaultSuccessOperationMessage' ) , 'periods' => $ this -> getPeriods ( ) , 'periodsFilter' => $ this -> getPeriods2 ( ) ) ) ; }
Close an existing period

@param array $input
An array as follows: array(id => $id);

@return JSON encoded string
A string as follows:
In case of success: {"success" : form.defaultSuccessOperationMessage}
Close an existing period