public function updateJournalVoucherStatus($id, $Journal = null, $JournalVoucher = null, $newStatus = null, $databaseConnectionName = null)
  {
    if(empty($newStatus))
    {
      $debitSum = $this->JournalEntry->getJournalVoucherDebitSum($id, $databaseConnectionName);

      $creditSum = $this->JournalEntry->getJournalVoucherCreditSum($id, $databaseConnectionName);

      // var_dump((string) $debitSum, (string) $creditSum, $debitSum == $creditSum, round($debitSum) == round($creditSum), (string) $debitSum  == (string) $creditSum );
      // var_dump(round($debitSum, 2), round($creditSum, 2), round($debitSum, 2) == round($creditSum, 2));

      if(round($debitSum, 2) == round($creditSum, 2))
      {
        $status = 'B';
      }
      else
      {
        $status = 'A';
      }
    }
    else
    {
      $status = $newStatus;
    }

    if(empty($JournalVoucher))
    {
      $JournalVoucher = $this->JournalVoucher->byId($id, $databaseConnectionName);
    }

    $currentStatus = $JournalVoucher->status;

    if($currentStatus != $status)
    {
      $this->JournalVoucher->update(array('status' => $status), $JournalVoucher, $databaseConnectionName);

      if(!empty($Journal))
      {
        $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::journal-management.' . $currentStatus), 'new_value' => $this->Lang->get('decima-accounting::journal-management.' . $status)), $Journal);
      }
    }

    return $status;
  }
public function updateJournalVoucherStatus($id, $Journal = null, $JournalVoucher = null, $newStatus = null, $databaseConnectionName = null)
  {
    if(empty($newStatus))
    {
      $debitSum = $this->JournalEntry->getJournalVoucherDebitSum($id, $databaseConnectionName);

      $creditSum = $this->JournalEntry->getJournalVoucherCreditSum($id, $databaseConnectionName);

      // var_dump((string) $debitSum, (string) $creditSum, $debitSum == $creditSum, round($debitSum) == round($creditSum), (string) $debitSum  == (string) $creditSum );
      // var_dump(round($debitSum, 2), round($creditSum, 2), round($debitSum, 2) == round($creditSum, 2));

      if(round($debitSum, 2) == round($creditSum, 2))
      {
        $status = 'B';
      }
      else
      {
        $status = 'A';
      }
    }
    else
    {
      $status = $newStatus;
    }

    if(empty($JournalVoucher))
    {
      $JournalVoucher = $this->JournalVoucher->byId($id, $databaseConnectionName);
    }

    $currentStatus = $JournalVoucher->status;

    if($currentStatus != $status)
    {
      $this->JournalVoucher->update(array('status' => $status), $JournalVoucher, $databaseConnectionName);

      if(!empty($Journal))
      {
        $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::journal-management.' . $currentStatus), 'new_value' => $this->Lang->get('decima-accounting::journal-management.' . $status)), $Journal);
      }
    }

    return $status;
  }
public function updateJournalVoucherStatus ( $ id , $ Journal = null , $ JournalVoucher = null , $ newStatus = null , $ databaseConnectionName = null ) { if ( empty ( $ newStatus ) ) { $ debitSum = $ this -> JournalEntry -> getJournalVoucherDebitSum ( $ id , $ databaseConnectionName ) ; $ creditSum = $ this -> JournalEntry -> getJournalVoucherCreditSum ( $ id , $ databaseConnectionName ) ; // var_dump((string) $debitSum, (string) $creditSum, $debitSum == $creditSum, round($debitSum) == round($creditSum), (string) $debitSum  == (string) $creditSum ); // var_dump(round($debitSum, 2), round($creditSum, 2), round($debitSum, 2) == round($creditSum, 2)); if ( round ( $ debitSum , 2 ) == round ( $ creditSum , 2 ) ) { $ status = 'B' ; } else { $ status = 'A' ; } } else { $ status = $ newStatus ; } if ( empty ( $ JournalVoucher ) ) { $ JournalVoucher = $ this -> JournalVoucher -> byId ( $ id , $ databaseConnectionName ) ; } $ currentStatus = $ JournalVoucher -> status ; if ( $ currentStatus != $ status ) { $ this -> JournalVoucher -> update ( array ( 'status' => $ status ) , $ JournalVoucher , $ databaseConnectionName ) ; if ( ! empty ( $ Journal ) ) { $ 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::journal-management.' . $ currentStatus ) , 'new_value' => $ this -> Lang -> get ( 'decima-accounting::journal-management.' . $ status ) ) , $ Journal ) ; } } return $ status ; }
Update the status of an existing journal voucher

@param  int $id Voucher id
@param  App\Kwaai\Security\Repositories\Journal\JournalInterface $Journal

@return string
Update the status of an existing journal voucher