示例#1
0
 /**
  * Client constructor
  * @param integer   $agreement
  * @param integer   $userId
  * @param string    $password
  */
 public function __construct($agreement, $userId, $password)
 {
     $this->agreement = $agreement;
     $this->userId = $userId;
     $this->password = $password;
     $this->client = new SoapClient($this->apiUrl, $this->debug);
     $this->client->Connect(array('agreementNumber' => $this->agreement, 'userName' => $this->userId, 'password' => $this->password));
 }
/**
 *
 */
function get_soap_connection()
{
    static $client;
    if (!isset($client)) {
        $settings = parse_ini_file(realpath(dirname(__FILE__) . '/economics.ini'));
        try {
            $client = new SoapClient($settings['wsdl_endpoint'], array("trace" => 1, "exceptions" => 1));
            $client->Connect(array('agreementNumber' => $settings['agreement_number'], 'userName' => $settings['user_name'], 'password' => $settings['password']));
        } catch (SoapFault $fault) {
            trigger_error(sprintf("Soap fault %s - %s", $fault->faultcode, $fault->faultstring), E_USER_ERROR);
        }
    }
    return $client;
}
示例#3
0
try {
    // Helper function to check query parameters.
    function checkParameter($param)
    {
        if (!isset($_REQUEST[$param])) {
            echo "Missing <code>" . $param . "</code> parameter in query string.";
            exit(0);
        }
    }
    checkParameter("agreementNumber");
    checkParameter("username");
    checkParameter("password");
    $me = $_SERVER['PHP_SELF'];
    $wsdlUrl = 'https://api.e-conomic.com/secure/api1/EconomicWebservice.asmx?WSDL';
    $client = new SoapClient($wsdlUrl, array("trace" => 1, "exceptions" => 1));
    $client->Connect(array('agreementNumber' => $_REQUEST['agreementNumber'], 'userName' => $_REQUEST['username'], 'password' => $_REQUEST['password']));
    if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['action'] == 'create_debtor') {
        try {
            $debtorGroupHandles = $client->debtorGroup_GetAll()->DebtorGroup_GetAllResult->DebtorGroupHandle;
            $firstDebtorGroup = $debtorGroupHandles[0];
            $newDebtorHandle = $client->Debtor_Create(array('number' => $_POST['debtor_number'], 'debtorGroupHandle' => $firstDebtorGroup, 'name' => $_POST['debtor_name'], 'vatZone' => 'EU'))->Debtor_CreateResult;
            $client->Debtor_SetAddress(array('debtorHandle' => $newDebtorHandle, 'value' => $_POST['debtor_address']));
            print "<p>A new debtor has be created.</p>";
        } catch (Exception $exception) {
            print "<p><b>Could not create debtor.</b></p>";
            print "<p><i>" . $exception->getMessage() . "</i></p>";
        }
    }
    // Fetch list of all debtors.
    $debtorHandles = $client->Debtor_GetAll()->Debtor_GetAllResult->DebtorHandle;
    $debtorDataObjects = $client->Debtor_GetDataArray(array('entityHandles' => $debtorHandles))->Debtor_GetDataArrayResult->DebtorData;
示例#4
0
 /**
  * connect to the e-conomic server
  *
  * @return the client object
  */
 private function _connect()
 {
     try {
         $client = new SoapClient('https://www.e-conomic.com/secure/api1/EconomicWebservice.asmx?WSDL', array("trace" => 1, "exceptions" => 1));
         $client->Connect(array('agreementNumber' => $this->_agreementNumber, 'userName' => $this->_username, 'password' => $this->_password));
     } catch (Exception $e) {
         echo __('Could not connect to E-Conomic server');
     }
     return $client;
 }
 public function loaddataAction()
 {
     //try {
     $wsdlUrl = 'https://api.e-conomic.com/secure/api1/EconomicWebservice.asmx?WSDL';
     $client = new \SoapClient($wsdlUrl, array("trace" => 1, "exceptions" => 1));
     $translator = $this->getServiceLocator()->get('translator');
     /* Get current local user */
     $user = $this->zfcUserAuthentication()->getIdentity();
     $entityManager = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     /* Get E-conomic credentials for current user */
     $eUser = $entityManager->getRepository('MyEconomic\\Entity\\EconomicUser')->findOneBy(array('user' => $user));
     /* Connect to E-conomic SOAP API server */
     if (empty($eUser)) {
         return $this->redirect()->toRoute('myeconomic', array('action' => 'adduser'));
     }
     /* Connect to E-conomic SOAP API server */
     $client->Connect(array('agreementNumber' => $eUser->getAgreementNumber(), 'userName' => $eUser->getUsername(), 'password' => $eUser->getPassword()));
     /* Get accounting years */
     $accYears = $client->AccountingPeriod_GetAll()->AccountingPeriod_GetAllResult->AccountingPeriodHandle;
     $accPeriodData = $client->AccountingPeriod_GetDataArray(array('entityHandles' => $accYears))->AccountingPeriod_GetDataArrayResult;
     /* Get accounting periods */
     $accountPeriods = array();
     $tmpPeriod = array();
     $tmp = array();
     $counter = count($accPeriodData->AccountingPeriodData);
     foreach ($accPeriodData->AccountingPeriodData as $period) {
         if (!in_array($period->AccountingYearHandle->Year, $tmp)) {
             array_push($tmp, $period->AccountingYearHandle->Year);
             if ($tmpPeriod) {
                 array_push($accountPeriods, $tmpPeriod);
             }
             $tmpPeriod = array('Year' => $period->AccountingYearHandle->Year, 'SubPeriods' => array());
         }
         $tmpSubPeriod['FromDate'] = $period->FromDate;
         $tmpSubPeriod['ToDate'] = $period->ToDate;
         array_push($tmpPeriod['SubPeriods'], $tmpSubPeriod);
         $counter--;
         if (!$counter) {
             array_push($accountPeriods, $tmpPeriod);
         }
     }
     /* Get turnovers */
     $keyFigureCodeHundlers = $client->KeyFigureCode_FindByNumber(array('number' => '1'))->KeyFigureCode_FindByNumberResult;
     $accs = $client->KeyFigureCode_GetAccounts(array('keyFigureCodeHandle' => $keyFigureCodeHundlers))->KeyFigureCode_GetAccountsResult;
     if ($accs->AccountHandle) {
         /* Get turnovers array for every month */
         foreach ($accountPeriods as $year) {
             $tmpPeriod = array();
             foreach ($year['SubPeriods'] as $period) {
                 $tmp = abs(array_sum($client->Account_GetEntryTotalsByDate(array('accounts' => $accs->AccountHandle, 'first' => $period['FromDate'], 'last' => $period['ToDate']))->Account_GetEntryTotalsByDateResult->decimal));
                 array_push($tmpPeriod, $tmp);
             }
             $turnover[$year['Year']] = $tmpPeriod;
         }
         /* Save Turnovers in local database */
         foreach ($turnover as $key => $value) {
             /* check if record already exist */
             $tmp = $entityManager->getRepository('MyEconomic\\Entity\\Turnover')->findOneBy(array('user' => $user, 'year' => $key));
             $turnoverRecord = $tmp ? $tmp : new Turnover();
             /* fill fields with data */
             $turnoverRecord->setUser($user);
             $turnoverRecord->setYear($key);
             $turnoverRecord->setTurnover(json_encode($value));
             /* save */
             $entityManager->persist($turnoverRecord);
             $entityManager->flush();
         }
     }
     /* Get Variable Costs */
     $keyFigureCodeHundlers = $client->KeyFigureCode_FindByNumber(array('number' => '2'))->KeyFigureCode_FindByNumberResult;
     $accs = $client->KeyFigureCode_GetAccounts(array('keyFigureCodeHandle' => $keyFigureCodeHundlers))->KeyFigureCode_GetAccountsResult;
     if ($accs->AccountHandle) {
         /* Get variable costs array for every month */
         foreach ($accountPeriods as $year) {
             $tmpPeriod = array();
             foreach ($year['SubPeriods'] as $period) {
                 $tmp = abs(array_sum($client->Account_GetEntryTotalsByDate(array('accounts' => $accs->AccountHandle, 'first' => $period['FromDate'], 'last' => $period['ToDate']))->Account_GetEntryTotalsByDateResult->decimal));
                 array_push($tmpPeriod, $tmp);
             }
             $variableCosts[$year['Year']] = $tmpPeriod;
         }
         /* Save Variable Costs in local database */
         foreach ($variableCosts as $key => $value) {
             /* check if record already exist */
             $tmp = $entityManager->getRepository('MyEconomic\\Entity\\VariableCosts')->findOneBy(array('user' => $user, 'year' => $key));
             $variableCostsRecord = $tmp ? $tmp : new VariableCosts();
             /* fill fields with data */
             $variableCostsRecord->setUser($user);
             $variableCostsRecord->setYear($key);
             $variableCostsRecord->setVariableCosts(json_encode($value));
             /* save */
             $entityManager->persist($variableCostsRecord);
             $entityManager->flush();
         }
     }
     /* Get Company Tax */
     $keyFigureCodeHundlers = $client->KeyFigureCode_FindByNumber(array('number' => '9'))->KeyFigureCode_FindByNumberResult;
     $accs = $client->KeyFigureCode_GetAccounts(array('keyFigureCodeHandle' => $keyFigureCodeHundlers))->KeyFigureCode_GetAccountsResult;
     if ($accs->AccountHandle) {
         /* Get Company Tax array for every month */
         foreach ($accountPeriods as $year) {
             $tmpPeriod = array();
             foreach ($year['SubPeriods'] as $period) {
                 $tmp = abs(array_sum($client->Account_GetEntryTotalsByDate(array('accounts' => $accs->AccountHandle, 'first' => $period['FromDate'], 'last' => $period['ToDate']))->Account_GetEntryTotalsByDateResult->decimal));
                 array_push($tmpPeriod, $tmp);
             }
             $companyTax[$year['Year']] = $tmpPeriod;
         }
         /* Save Company Tax in local database */
         foreach ($companyTax as $key => $value) {
             /* check if record already exist */
             $tmp = $entityManager->getRepository('MyEconomic\\Entity\\CompanyTax')->findOneBy(array('user' => $user, 'year' => $key));
             $companyTaxRecord = $tmp ? $tmp : new CompanyTax();
             /* fill fields with data */
             $companyTaxRecord->setUser($user);
             $companyTaxRecord->setYear($key);
             $companyTaxRecord->setCompanyTax(json_encode($value));
             /* save */
             $entityManager->persist($companyTaxRecord);
             $entityManager->flush();
         }
     }
     /* Get Direct Pay */
     $keyFigureCodeHundlers = $client->KeyFigureCode_FindByNumber(array('number' => '3'))->KeyFigureCode_FindByNumberResult;
     $accs = $client->KeyFigureCode_GetAccounts(array('keyFigureCodeHandle' => $keyFigureCodeHundlers))->KeyFigureCode_GetAccountsResult;
     /* Get Direct Pay array for every month */
     foreach ($accountPeriods as $year) {
         $tmpPeriod = array();
         foreach ($year['SubPeriods'] as $period) {
             if ($accs->AccountHandle) {
                 $tmp = abs(array_sum($client->Account_GetEntryTotalsByDate(array('accounts' => $accs->AccountHandle, 'first' => $period['FromDate'], 'last' => $period['ToDate']))->Account_GetEntryTotalsByDateResult->decimal));
             } else {
                 $tmp = 0;
             }
             array_push($tmpPeriod, $tmp);
         }
         $directPay[$year['Year']] = $tmpPeriod;
     }
     /* Save Direct Pay in local database */
     foreach ($directPay as $key => $value) {
         /* check if record already exist */
         $tmp = $entityManager->getRepository('MyEconomic\\Entity\\DirectPay')->findOneBy(array('user' => $user, 'year' => $key));
         $directPayRecord = $tmp ? $tmp : new DirectPay();
         /* fill fields with data */
         $directPayRecord->setUser($user);
         $directPayRecord->setYear($key);
         $directPayRecord->setDirectPay(json_encode($value));
         /* save */
         $entityManager->persist($directPayRecord);
         $entityManager->flush();
     }
     /* Get OtherDirectCosts */
     $keyFigureCodeHundlers = $client->KeyFigureCode_FindByNumber(array('number' => '4'))->KeyFigureCode_FindByNumberResult;
     $accs = $client->KeyFigureCode_GetAccounts(array('keyFigureCodeHandle' => $keyFigureCodeHundlers))->KeyFigureCode_GetAccountsResult;
     /* Get OtherDirectCosts array for every month */
     foreach ($accountPeriods as $year) {
         $tmpPeriod = array();
         foreach ($year['SubPeriods'] as $period) {
             if ($accs->AccountHandle) {
                 $tmp = abs(array_sum($client->Account_GetEntryTotalsByDate(array('accounts' => $accs->AccountHandle, 'first' => $period['FromDate'], 'last' => $period['ToDate']))->Account_GetEntryTotalsByDateResult->decimal));
             } else {
                 $tmp = 0;
             }
             array_push($tmpPeriod, $tmp);
         }
         $otherDirectCosts[$year['Year']] = $tmpPeriod;
     }
     /* Save OtherDirectCosts in local database */
     foreach ($otherDirectCosts as $key => $value) {
         /* check if record already exist */
         $tmp = $entityManager->getRepository('MyEconomic\\Entity\\OtherDirectCosts')->findOneBy(array('user' => $user, 'year' => $key));
         $otherDirectCostsRecord = $tmp ? $tmp : new OtherDirectCosts();
         /* fill fields with data */
         $otherDirectCostsRecord->setUser($user);
         $otherDirectCostsRecord->setYear($key);
         $otherDirectCostsRecord->setOtherDirectCosts(json_encode($value));
         /* save */
         $entityManager->persist($otherDirectCostsRecord);
         $entityManager->flush();
     }
     /* Get Overheads */
     $keyFigureCodeHundlers = $client->KeyFigureCode_FindByNumber(array('number' => '5'))->KeyFigureCode_FindByNumberResult;
     $accs = $client->KeyFigureCode_GetAccounts(array('keyFigureCodeHandle' => $keyFigureCodeHundlers))->KeyFigureCode_GetAccountsResult;
     if ($accs->AccountHandle) {
         /* Get Overheads array for every month */
         foreach ($accountPeriods as $year) {
             $tmpPeriod = array();
             foreach ($year['SubPeriods'] as $period) {
                 $tmp = abs(array_sum($client->Account_GetEntryTotalsByDate(array('accounts' => $accs->AccountHandle, 'first' => $period['FromDate'], 'last' => $period['ToDate']))->Account_GetEntryTotalsByDateResult->decimal));
                 array_push($tmpPeriod, $tmp);
             }
             $overheads[$year['Year']] = $tmpPeriod;
         }
         /* Save Overheads in local database */
         foreach ($overheads as $key => $value) {
             /* check if record already exist */
             $tmp = $entityManager->getRepository('MyEconomic\\Entity\\Overheads')->findOneBy(array('user' => $user, 'year' => $key));
             $overheadsRecord = $tmp ? $tmp : new Overheads();
             /* fill fields with data */
             $overheadsRecord->setUser($user);
             $overheadsRecord->setYear($key);
             $overheadsRecord->setOverheads(json_encode($value));
             /* save */
             $entityManager->persist($overheadsRecord);
             $entityManager->flush();
         }
     }
     /* Get Depreciation/Amortisation */
     $keyFigureCodeHundlers = $client->KeyFigureCode_FindByNumber(array('number' => '6'))->KeyFigureCode_FindByNumberResult;
     $accs = $client->KeyFigureCode_GetAccounts(array('keyFigureCodeHandle' => $keyFigureCodeHundlers))->KeyFigureCode_GetAccountsResult;
     if ($accs->AccountHandle) {
         /* Get Depreciation/Amortisation array for every month */
         foreach ($accountPeriods as $year) {
             $tmpPeriod = array();
             foreach ($year['SubPeriods'] as $period) {
                 $tmp = abs(array_sum($client->Account_GetEntryTotalsByDate(array('accounts' => $accs->AccountHandle, 'first' => $period['FromDate'], 'last' => $period['ToDate']))->Account_GetEntryTotalsByDateResult->decimal));
                 array_push($tmpPeriod, $tmp);
             }
             $depreciations[$year['Year']] = $tmpPeriod;
         }
         /* Save Depreciation/Amortisation in local database */
         foreach ($depreciations as $key => $value) {
             /* check if record already exist */
             $tmp = $entityManager->getRepository('MyEconomic\\Entity\\Depreciation')->findOneBy(array('user' => $user, 'year' => $key));
             $depreciationsRecord = $tmp ? $tmp : new Depreciation();
             /* fill fields with data */
             $depreciationsRecord->setUser($user);
             $depreciationsRecord->setYear($key);
             $depreciationsRecord->setDepreciation(json_encode($value));
             /* save */
             $entityManager->persist($depreciationsRecord);
             $entityManager->flush();
         }
     }
     /* Get Financial Items */
     $keyFigureCodeHundlers = $client->KeyFigureCode_FindByNumber(array('number' => '7'))->KeyFigureCode_FindByNumberResult;
     $accs = $client->KeyFigureCode_GetAccounts(array('keyFigureCodeHandle' => $keyFigureCodeHundlers))->KeyFigureCode_GetAccountsResult;
     if ($accs->AccountHandle) {
         /* Get Financial Items array for every month */
         foreach ($accountPeriods as $year) {
             $tmpPeriod = array();
             foreach ($year['SubPeriods'] as $period) {
                 $tmp = abs(array_sum($client->Account_GetEntryTotalsByDate(array('accounts' => $accs->AccountHandle, 'first' => $period['FromDate'], 'last' => $period['ToDate']))->Account_GetEntryTotalsByDateResult->decimal));
                 array_push($tmpPeriod, $tmp);
             }
             $financialItems[$year['Year']] = $tmpPeriod;
         }
         /* Save Financial Items in local database */
         foreach ($financialItems as $key => $value) {
             /* check if record already exist */
             $tmp = $entityManager->getRepository('MyEconomic\\Entity\\FinancialItems')->findOneBy(array('user' => $user, 'year' => $key));
             $financialItemsRecord = $tmp ? $tmp : new FinancialItems();
             /* fill fields with data */
             $financialItemsRecord->setUser($user);
             $financialItemsRecord->setYear($key);
             $financialItemsRecord->setFinancialItems(json_encode($value));
             /* save */
             $entityManager->persist($financialItemsRecord);
             $entityManager->flush();
         }
     }
     /* Get Extraordinary Items */
     $keyFigureCodeHundlers = $client->KeyFigureCode_FindByNumber(array('number' => '8'))->KeyFigureCode_FindByNumberResult;
     $accs = $client->KeyFigureCode_GetAccounts(array('keyFigureCodeHandle' => $keyFigureCodeHundlers))->KeyFigureCode_GetAccountsResult;
     if ($accs->AccountHandle) {
         /* Get Extraordinary Items array for every month */
         foreach ($accountPeriods as $year) {
             $tmpPeriod = array();
             foreach ($year['SubPeriods'] as $period) {
                 $tmp = abs(array_sum($client->Account_GetEntryTotalsByDate(array('accounts' => $accs->AccountHandle, 'first' => $period['FromDate'], 'last' => $period['ToDate']))->Account_GetEntryTotalsByDateResult->decimal));
                 array_push($tmpPeriod, $tmp);
             }
             $extraordinaryItems[$year['Year']] = $tmpPeriod;
         }
         /* Save Extraordinary Items in local database */
         foreach ($extraordinaryItems as $key => $value) {
             /* check if record already exist */
             $tmp = $entityManager->getRepository('MyEconomic\\Entity\\ExtraordinaryItems')->findOneBy(array('user' => $user, 'year' => $key));
             $extraordinaryItemsRecord = $tmp ? $tmp : new ExtraordinaryItems();
             /* fill fields with data */
             $extraordinaryItemsRecord->setUser($user);
             $extraordinaryItemsRecord->setYear($key);
             $extraordinaryItemsRecord->setExtraordinaryItems(json_encode($value));
             /* save */
             $entityManager->persist($extraordinaryItemsRecord);
             $entityManager->flush();
         }
     }
     /* Close connection */
     $client->Disconnect();
     $resultMessage = 'Your data loaded from E-Conomic to local service successfully!';
     return array('message' => $resultMessage);
 }