コード例 #1
0
 /**
  * @return void
  * @author Carlos Escribano <*****@*****.**>
  **/
 public function save($con = null)
 {
     parent::save();
     $currency_decimals = sfConfig::get('app_currency_decimals', array());
     foreach ($this->getValues() as $key => $value) {
         switch ($key) {
             case 'company_logo':
                 if ("on" == $this->getValue('company_logo_delete') && is_file($old = sfConfig::get('sf_upload_dir') . DIRECTORY_SEPARATOR . PropertyTable::get('company_logo'))) {
                     @unlink($old);
                     PropertyTable::set('company_logo', null);
                 }
                 if ($value) {
                     $fname = $value->generateFilename();
                     $value->save(sfConfig::get('sf_upload_dir') . DIRECTORY_SEPARATOR . $fname);
                     PropertyTable::set('company_logo', $fname);
                 }
                 break;
             case 'company_logo_delete':
                 break;
             case 'currency':
                 PropertyTable::set('currency_decimals', array_key_exists($value, $currency_decimals) ? $currency_decimals[$value] : 2);
                 PropertyTable::set('currency', $value);
                 break;
             case 'seriess':
             case 'taxes':
                 break;
             default:
                 PropertyTable::set($key, $value);
                 break;
         }
     }
 }
コード例 #2
0
 public function configure()
 {
     $decorator = new myFormSchemaFormatter($this->getWidgetSchema());
     $this->widgetSchema->addFormFormatter('custom', $decorator);
     $this->widgetSchema->setFormFormatterName('custom');
     $common_fields = Doctrine::getTable(self::getModelName())->getColumnNames();
     $model_fields = Doctrine::getTable($this->getModelName())->getColumnNames();
     foreach (array_diff($common_fields, $model_fields) as $extra) {
         unset($this[$extra]);
     }
     $this->widgetSchema['customer_id'] = new sfWidgetFormInputHidden();
     $this->widgetSchema['recurring_invoice_id'] = new sfWidgetFormInputHidden();
     $this->widgetSchema['tags'] = new sfWidgetFormInputHidden();
     $this->widgetSchema['type'] = new sfWidgetFormInputHidden(array(), array('value' => $this->getModelName()));
     $this->widgetSchema['series_id'] = new sfWidgetFormSelect(array('choices' => SeriesTable::getChoicesForSelect()));
     $this->widgetSchema['series_id']->setDefault(sfContext::getInstance()->getUser()->getProfile()->getSeries());
     $this->widgetSchema['invoicing_address'] = new sfWidgetFormTextarea();
     $this->widgetSchema['shipping_address'] = new sfWidgetFormTextarea();
     $this->widgetSchema['terms'] = new sfWidgetFormTextarea();
     $common_defaults = array('customer_name' => 'Client Name', 'customer_identification' => 'Client Legal Id', 'contact_person' => 'Contact Person', 'invoicing_address' => 'Invoicing Address', 'shipping_address' => 'Shipping Address', 'customer_email' => 'Client Email Address');
     $this->widgetSchema->setHelps(array_merge($this->widgetSchema->getHelps(), $common_defaults));
     $this->setDefault('tags', implode(',', $this->object->getTags()));
     $this->setDefault('terms', PropertyTable::get('legal_terms'));
     // validators
     $this->validatorSchema['tags'] = new sfValidatorString(array('required' => false));
     $this->validatorSchema['customer_email'] = new sfValidatorEmail(array('max_length' => 100, 'required' => false), array('invalid' => 'Invalid client email address'));
     $this->validatorSchema['customer_name'] = new sfValidatorString(array('required' => true));
     $this->validatorSchema['series_id'] = new sfValidatorString(array('required' => true), array('required' => 'The invoice serie is mandatory'));
     $iforms = array();
     foreach ($this->object->getItems() as $item) {
         $iforms[$item->id] = new ItemForm($item);
     }
     $itemForms = new FormsContainer($iforms, 'ItemForm');
     $this->embedForm('Items', $itemForms);
 }
コード例 #3
0
 /**
  * Updates a Customer object matching the object's data.
  *
  * @return void
  * @author Carlos Escribano <*****@*****.**>
  **/
 public function updateCustomer($obj)
 {
     $customer = $this->getCustomerMatch($obj);
     if ($customer->isNew() || !in_array('customers', PropertyTable::get('siwapp_modules', array()))) {
         $customer->setDataFrom($obj);
     }
     $obj->setCustomer($customer);
     $customer->save();
 }
コード例 #4
0
ファイル: Common.class.php プロジェクト: solutema/siwapp-sf1
 public function setAmounts()
 {
     $this->setBaseAmount($this->calculate('base_amount'));
     $this->setDiscountAmount($this->calculate('discount_amount'));
     $this->setNetAmount($this->getBaseAmount() - $this->getDiscountAmount());
     $this->setTaxAmount($this->calculate('tax_amount'));
     $rounded_gross = round($this->getNetAmount() + $this->getTaxAmount(), PropertyTable::get('currency_decimals', 2));
     $this->setGrossAmount($rounded_gross);
     return $this;
 }
コード例 #5
0
 public function configure()
 {
     $optional_mods = sfConfig::get('app_modules_optional');
     foreach (sfConfig::get('app_modules_optional') as $mod => $opts) {
         $choices[$mod] = $opts['verbose_name'];
     }
     $this->setWidgets(array('siwapp_modules' => new sfWidgetFormSelectCheckbox(array('choices' => $choices), array('class' => 'siwapp_modules'))));
     $this->widgetSchema->setLabels(array('siwapp_modules' => 'Siwapp Modules'));
     $this->setDefaults(array('siwapp_modules' => PropertyTable::get('siwapp_modules')));
     $this->widgetSchema->setNameFormat('config[%s]');
     $this->setValidators(array('siwapp_modules' => new sfValidatorPass()));
 }
コード例 #6
0
 public function loadUserSettings()
 {
     $currency = PropertyTable::get('currency', 'USD');
     $currency_decimals = PropertyTable::get('currency_decimals', 2);
     $siwapp_mandatory_modules = array_keys(sfConfig::get('app_modules_mandatory'));
     $siwapp_optional_modules = PropertyTable::get('siwapp_modules', array());
     $this->setAttribute('currency', $currency);
     $this->setAttribute('currency_decimals', $currency_decimals);
     $this->setAttribute('siwapp_modules', array_merge($siwapp_mandatory_modules, $siwapp_optional_modules));
     $culture = $this->getLanguage();
     if ($this->getCountry()) {
         $culture .= '_' . $this->getCountry();
     }
     $this->setCulture($culture);
 }
コード例 #7
0
ファイル: EmailMessages.php プロジェクト: solutema/siwapp-sf1
 public function __construct($invoice)
 {
     parent::__construct();
     $this->setTo($invoice->customer_email, $invoice->customer_name);
     // To get all the properties loaded for the template
     foreach ($invoice->Items as $it) {
         $it->refreshRelated();
     }
     $data[] = $invoice;
     $model = get_class($invoice);
     $printer = new Printer($model, TemplateTable::getTemplateForModel($model)->getId());
     try {
         $body = $printer->render($data);
         $pdf = $printer->renderPdf($data)->output();
         $attachment = new Swift_Attachment($pdf, $model . '-' . $invoice->getId() . '.pdf', 'application/pdf');
         $this->setSubject(PropertyTable::get('company_name') . ' [' . $model . ': ' . $invoice . ']')->setBody($printer->render($data), 'text/html')->attach($attachment);
         $this->setReadyState(true);
     } catch (LogicException $e) {
         $this->setReadyState(false);
     }
 }
コード例 #8
0
ファイル: actions.class.php プロジェクト: solutema/siwapp-sf1
 /**
  * Receives the Invoice form data and calculates each row total amount and
  * full invoice totals. Returns a json
  *
  * @param 'invoice' from Request
  * @return JSON through Response
  */
 public function executeCalculate(sfWebRequest $request)
 {
     $currency = PropertyTable::get('currency');
     $format = new sfNumberFormat($this->culture);
     $data = $request->getParameter('invoice');
     $this->getResponse()->setHttpHeader('Content-Type', 'application/json; charset=utf-8');
     $invoice = new Invoice();
     $items = array();
     $totals = array();
     if (isset($data['Items'])) {
         foreach ((array) $data['Items'] as $itemId => $itemData) {
             if ($itemData['remove']) {
                 continue;
             }
             $item = new Item();
             $item->setUnitaryCost($itemData['unitary_cost']);
             $item->setQuantity($itemData['quantity']);
             $item->setDiscount($itemData['discount']);
             if (isset($itemData['taxes_list'])) {
                 $taxes = Doctrine::getTable('Tax')->createQuery()->whereIn('id', $itemData['taxes_list'])->execute();
                 $item->Taxes = $taxes;
             }
             $items[$itemId] = $format->format($item->getGrossAmount(), 'c', $currency);
             $invoice->Items[] = $item;
         }
         $totals['base'] = $format->format($invoice->calculate('base_amount', true), 'c', $currency);
         $totals['discount'] = $format->format($invoice->calculate('discount_amount', true), 'c', $currency);
         $totals['net'] = $format->format($invoice->calculate('net_amount', true), 'c', $currency);
         $totals['taxes'] = $format->format($invoice->calculate('tax_amount', true), 'c', $currency);
         $totals['gross'] = $format->format($invoice->calculate('gross_amount', true), 'c', $currency);
     } else {
         $zero = $format->format(0, 'c', $currency);
         $totals['base'] = $zero;
         $totals['discount'] = $zero;
         $totals['net'] = $zero;
         $totals['taxes'] = $zero;
         $totals['gross'] = $zero;
     }
     return $this->renderText(json_encode(array('items' => $items, 'totals' => $totals)));
 }
コード例 #9
0
ファイル: actions.class.php プロジェクト: solutema/siwapp-sf1
 /**
  * undocumented function
  *
  * @return void
  * @author JoeZ99 <*****@*****.**>
  **/
 public function executeSiwappModules(sfWebRequest $request)
 {
     $user = $this->getUser();
     $i18n = $this->getContext()->getI18N();
     $form = new SiwappModulesForm();
     if ($request->isMethod('post')) {
         $form->bind($request->getParameter($form->getName()));
         if ($form->isValid()) {
             $config = $request->getParameter($form->getName());
             if (!(isset($config['siwapp_modules']) and $smodules = $config['siwapp_modules'])) {
                 $smodules = array();
             }
             PropertyTable::set('siwapp_modules', $smodules);
             $user->info($i18n->__('Your settings were successfully saved.'));
             $user->loadUserSettings();
             $this->redirect('@siwapp_modules');
         } else {
             $user->error($i18n->__('Settings could not be saved'), false);
         }
     }
     $this->form = $form;
 }
コード例 #10
0
ファイル: InvoiceTest.php プロジェクト: solutema/siwapp-sf1
$invoice->setSeriesId('1');
$invoice->save();
$t->is($invoice->number, 9, 'When changing number series, the inv number changes');
$invoice->setSeriesId('2');
$invoice->save();
$t->is($invoice->number, 5, 'When changing back it gets the next maximun number available');
// checks savings with modified customer data
$t->diag('customers mod available: checking that moddified cust data does not alter customer object itself');
$invoice = Doctrine::getTable('Invoice')->findOneBy('CustomerName', 'Smith and Co.');
$invoice->customer_email = '*****@*****.**';
$invoice->save();
$t->is($invoice->customer_id, $customer_id, "customer id not changed");
$c = Doctrine::getTable('Customer')->findOneById($customer_id);
$t->is($c->name . $c->email, 'Smith and Co.jody_nichols@example.com', 'Customer object is not modified');
$t->diag('customers mod not available: checking that moddified cust data in the invoice alter customer object itself');
PropertyTable::set('siwapp_modules', array('products', 'estimates'));
$invoice->customer_email = '*****@*****.**';
$invoice->save();
$c = Doctrine::getTable('Customer')->findOneById($customer_id);
$t->is($c->name . $c->email, 'Smith and Co.test2@testmail.com', 'Customer object is modified');
PropertyTable::set('siwapp_modules', array('customers', 'products', 'estimates'));
$t->diag('checking that changing customer name changes customer');
$invoice->customer_name = 'Rouster and Sideways';
$invoice->save();
$c = Doctrine::getTable('Customer')->findOneById($invoice->customer_id);
$t->is($c->name_slug, CustomerTable::slugify($invoice->customer_name), 'A different customer object is associated');
$t->diag('checking that db-new customer name creates a new customer');
$invoice->customer_name = 'New Rouster and Sideways';
$invoice->save();
$c = Doctrine::getTable('Customer')->findOneByNameSlug(CustomerTable::slugify($invoice->customer_name));
$t->is($c->name, $invoice->customer_name, 'New Customer created');
コード例 #11
0
 protected function setSeoFilterProperties()
 {
     $this->properties = PropertyTable::getList(['select' => ['PROPERTY_ID', 'SORT'], 'order' => ['SORT' => 'ASC']])->fetchAll();
 }
コード例 #12
0
ファイル: Tools.class.php プロジェクト: solutema/siwapp-sf1
 public static function getDecimals()
 {
     return PropertyTable::get('currency_decimals', 2);
 }
コード例 #13
0
ファイル: actions.class.php プロジェクト: solutema/siwapp-sf1
 /**
  * this checks if recalculation of totals and status is needed
  * of the opened invoices
  *
  * @return void
  **/
 private function checkIfUpdateTotals()
 {
     // if the property is not set, we set it here
     if (!PropertyTable::get('last_calculation_date')) {
         PropertyTable::set('last_calculation_date', '1970-01-01');
     }
     $last = new sfDate(PropertyTable::get('last_calculation_date'));
     $today = new sfDate();
     if ($today->diff($last, sfTime::DAY) > 0) {
         CommonTable::calculateTotals();
         PropertyTable::set('last_calculation_date', $today->format('Y-m-d'));
     }
 }
コード例 #14
0
ファイル: PaymentTest.php プロジェクト: solutema/siwapp-sf1
<?php

include dirname(__FILE__) . '/../../bootstrap/Doctrine.php';
include dirname(__FILE__) . '/../../testTools.php';
$t = new lime_test(2, new lime_output_color());
PropertyTable::set('currency_decimals', 3);
$p = new Payment();
$p->setAmount(2.1215);
$t->is($p->getAmount(), 2.122, 'rounds amount to 3 decimals');
PropertyTable::set('currency_decimals', 2);
$p->setAmount(2.123);
$t->is($p->getAmount(), 2.12, 'rounds amount to 2 decimals');
コード例 #15
0
ファイル: Payment.class.php プロジェクト: solutema/siwapp-sf1
 public function setAmount($v)
 {
     $v = round($v, PropertyTable::get('currency_decimals', 2));
     return $this->_set('amount', $v);
 }