コード例 #1
0
 function testGetCompaniesSeveralCompaniesOK()
 {
     $email = '*****@*****.**';
     $name = 'ACME';
     WebfinanceUser::Create($email);
     $company = array('name' => $name, 'address1' => '1110 Gateway Drive', 'zip_code' => 'CA 94404', 'city' => 'San Mateo', 'country' => 'US', 'email' => $email);
     $company_id = WebfinanceCompany::Create($company);
     $user = new WebfinanceUser($email);
     $companies = $user->GetCompanies();
     $this->assertType('array', $companies);
     $expected = array(array('id' => $company_id, 'name' => $name));
     $this->assertEquals($expected, $companies);
 }
コード例 #2
0
 /**
  * Update an invoice
  *
  * @param invoice array. The array defining the invoice to create, example:
  *
  * \code
  * array(
  *    'id'                     => 4, // the invoice ID
  *    'type'                   => 'invoice', // or 'quotation'
  *    'paid'                   => false, // or true
  *    'vat'                    => 20.0,  // %
  *    'period'                 => 'none', // 'monthly', 'quarterly', 'yearly'
  *    'periodic_next_deadline' => 2012-01-04, // YYYY-MM-DD
  *    'delivery'               => 'email', // or 'postal'
  *    'payment_method'         => 'unknown', // 'direct_debit', 'check' or
  *                                           // 'wire_transfer'
  *    'items'  => array(
  *       0 => array(
  *          'description' => 'the item description',
  *          'price'       => 123.32, // the unit price, excluding VAT
  *          'quantity'    => 3,
  *       ),
  *       1 => array(
  *          'description' => 'the second item description',
  *          'price'       => 23,
  *          'quantity'    => 1,
  *       ),
  *    )
  * )
  * \endcode
  *
  */
 function InvoiceUpdate(array $invoice = array())
 {
     CybPHP_Validate::ValidateInt($this->_company_id);
     CybPHP_Validate::ValidateInt($invoice['id']);
     WebfinanceCompany::ValidateInvoiceExists($invoice['id']);
     WebfinanceCompany::ValidateInvoiceType($invoice['type']);
     WebfinanceCompany::ValidateInvoicePeriod($invoice['period']);
     WebfinanceCompany::ValidateInvoiceDelivery($invoice['delivery']);
     WebfinanceCompany::ValidateInvoicePaymentMethod($invoice['payment_method']);
     if ($invoice['period'] != 'none') {
         CybPHP_Validate::ValidateDate($invoice['periodic_next_deadline']);
     }
     CybPHP_Validate::ValidateFloat($invoice['vat']);
     CybPHP_Validate::ValidateBool($invoice['paid']);
     # Define empty items if needed
     if (empty($invoice['items'])) {
         $invoice['items'] = array();
     }
     # Define periodic_next_deadline if needed
     if (empty($invoice['periodic_next_deadline'])) {
         $invoice['periodic_next_deadline'] = '0000-00-00';
     }
     foreach ($invoice['items'] as &$item) {
         CybPHP_Validate::ValidateFloat($item['price']);
         CybPHP_Validate::ValidateInt($item['quantity']);
         $item['description'] = mysql_escape_string($item['description']);
     }
     $type_translation = array('invoice' => 'facture', 'quotation' => 'devis');
     $invoice['type'] = $type_translation[$invoice['type']];
     $invoice['paid'] = $invoice['paid'] ? 1 : 0;
     $invoice['reference'] = WebfinanceCompany::GenerateInvoiceReference();
     CybPHP_MySQL::Query('BEGIN');
     CybPHP_MySQL::Query('UPDATE webfinance_invoices SET ' . 'date_created           = NOW(), ' . "type_doc               = '{$invoice['type']}', " . "is_paye                = {$invoice['paid']}, " . "tax                    = {$invoice['vat']}, " . "period                 = '{$invoice['period']}', " . "periodic_next_deadline = '{$invoice['periodic_next_deadline']}', " . "delivery               = '{$invoice['delivery']}', " . "payment_method         = '{$invoice['payment_method']}', " . "num_facture            = '{$invoice['reference']}' " . "WHERE id_facture       = {$invoice['id']}");
     $invoice_id = mysql_insert_id();
     CybPHP_MySQL::Query('DELETE FROM webfinance_invoice_rows ' . "WHERE id_facture = {$invoice_id}");
     $ordre = 1;
     foreach ($invoice['items'] as $item) {
         CybPHP_MySQL::Query('INSERT INTO webfinance_invoice_rows SET ' . "id_facture  = {$invoice_id}, " . "description = '{$item['description']}', " . "qtt         = {$item['quantity']}, " . "prix_ht     = {$item['price']}, " . "ordre       = {$ordre}");
         $ordre++;
     }
     CybPHP_MySQL::Query('COMMIT');
 }
コード例 #3
0
ファイル: index.php プロジェクト: lopacinski/WebFinance
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program. If not, see <http://www.gnu.org/licenses/>.
//
require_once '../../htdocs/inc/sso.php';
require_once '../../htdocs/inc/smarty.php';
try {
    // Check arguments
    if (empty($_GET['company_id'])) {
        throw new Exception('Missing argument');
    }
    // Check permissions
    $company = new WebfinanceCompany($_GET['company_id']);
    $company->ValidatePermission($_SESSION['cybsso_user']['email']);
    // Display localized amounts and dates
    foreach (array(LC_MESSAGES, LC_TIME, LC_MONETARY, LC_CTYPE) as $locale) {
        setlocale($locale, $_SESSION['cybsso_user']['language'] . ".UTF-8") or die("locale {$locale} language failed {$_SESSION['cybsso_user']}[language]");
    }
    $user = new WebfinanceUser($_SESSION['cybsso_user']['email']);
    $smarty->assign('this_company_id', $_GET['company_id']);
    $smarty->assign('companies', $user->GetCompanies());
    $smarty->assign('company_info', $company->GetInfo());
    $smarty->assign('invoices', $company->InvoicesGet());
} catch (SoapFault $fault) {
    $smarty->assign('error', $fault->getMessage());
} catch (Exception $fault) {
    $smarty->assign('error', $fault->getMessage());
}
コード例 #4
0
ファイル: update.php プロジェクト: lopacinski/WebFinance
if (empty($_POST['date'])) {
    $_POST['date'] = 'NULL';
} else {
    $_POST['date'] = "'{$_POST['date']}'";
}
$query = "UPDATE document\nSET\n paid         = '{$_POST['paid']}',\n date         = {$_POST['date']},\n provider_id  = {$_POST['provider_id']},\n vat          = {$_POST['vat']},\n total_amount = {$_POST['total_amount']},\n currency     = '{$_POST['currency']}',\n note         = '{$_POST['note']}',\n accounting   = '{$_POST['accounting']}',\n type         = '{$_POST['type']}'";
$where = "WHERE md5 = '{$_POST['md5']}'";
# Open ticket if needed
if (!empty($_POST['open_ticket'])) {
    require_once 'WebfinancePreferences.php';
    require_once 'WebfinanceCompany.php';
    $prefs = new WebfinancePreferences();
    $wsdl = $prefs->prefs['mantis_api_url'] . '?wsdl';
    $username = $prefs->prefs['mantis_login'];
    $password = $prefs->prefs['mantis_password'];
    $company = new WebfinanceCompany($_POST['provider_id']);
    $company_info = $company->GetInfo();
    $method = 'http://';
    if (!empty($_SERVER['HTTPS']) and $_SERVER['HTTPS'] !== 'off') {
        $method = 'https://';
    }
    $url = $method . $_SERVER['HTTP_HOST'] . '/document/edit.php?md5=' . $_POST['md5'];
    $issue = array('summary' => "Document {$note} from {$company_info['name']}", 'description' => "New document {$note} from {$company_info['name']}\n\n{$url}", 'category' => 'Documents', 'project' => array('id' => 381));
    try {
        $mantis = new SoapClient($wsdl);
        $ticket_id = $mantis->mc_issue_add($username, $password, $issue);
        $query .= ", ticket_id    = {$ticket_id}";
    } catch (SoapFault $fault) {
        echo $fault;
        exit;
    }
コード例 #5
0
 function testGetInfo()
 {
     $email = '*****@*****.**';
     WebfinanceUser::Create($email);
     $new_company = array('name' => 'ACME', 'address1' => '1110 Gateway Drive', 'zip_code' => 'CA 94404', 'city' => 'San Mateo', 'country' => 'US', 'email' => $email);
     $company_id = WebfinanceCompany::Create($new_company);
     $company = new WebfinanceCompany($company_id);
     $company_info = $company->GetInfo();
     $this->assertEquals($new_company['name'], $company_info['name']);
 }