<?php
-class Bootstrap extends CubeIT_Bootstrap {
-
- protected function _initMinimum() {
- parent::_initMinimum();
- // If a project with html display (don't activate by default for web services apps)
- $this->bootstrap('doctype');
- }
-
- protected function _initScripts() {
- parent::_initScripts();
- }
-
- protected function _initRouter($initCms = true, $standard = true) {
- $router = parent::_initRouter($initCms, $standard);
- $router->addStandardRoute('devis', 'devis');
- $router->addStandardRoute('payment', 'payment');
- $router->addStandardRoute('sogecommerce', 'sogecommerce');
- return $router;
- }
-
- /**
- *
- * @param \Doctrine\DBAL\Schema\Schema $schema
- * @param mixed $options
- */
- protected function _defineSchema(&$schema, $options) {
- parent::_defineSchema($schema, $options);
-
- $devis = $schema->createTable('devis');
- $devis->addColumn('id', 'integer', array('unsigned' => true, 'autoincrement' => true));
- $devis->setPrimaryKey(array('id'));
- $devis->addColumn('nom', 'string', array('length' => 128));
- $devis->addIndex(array('nom'));
- $devis->addColumn('email', 'string', array('length' => 128));
- $devis->addIndex(array('email'));
- $devis->addColumn('prenom', 'string', array('length' => 128));
- $devis->addIndex(array('prenom'));
- $devis->addColumn('societe', 'string', array('length' => 128));
- $devis->addIndex(array('societe'));
- $devis->addColumn('telephone', 'string', array('length' => 32));
- $devis->addColumn('mobile', 'string', array('length' => 32));
- $devis->addColumn('adresse', 'string', array('length' => 128));
- $devis->addColumn('code_postal', 'string', array('length' => 8));
- $devis->addColumn('ville', 'string', array('length' => 128));
- $devis->addColumn('country', 'string', array('length' => 4, 'default' => 'FR'));
- $devis->addColumn('tva_intra', 'string', array('length' => 32));
- $devis->addColumn('reference', 'text');
- $devis->addColumn('demandes', 'text');
- $devis->addColumn('magasin', 'string', array('length' => 32));
- $devis->addIndex(array('magasin'));
- $devis->addColumn('livraison', 'boolean');
- $devis->addColumn('adresse_livraison', 'string', array('length' => 512));
- $devis->addColumn('complement_livraison', 'string', array('length' => 512));
- $devis->addColumn('fichiers', 'text');
- $devis->addColumn('date', 'datetime');
- $devis->addColumn('tva', 'float', array('default' => '20'));
- $devis->addIndex(array('date'));
- $devis->addColumn('status', 'integer');
- $devis->addIndex(array('status'));
- $devis->addColumn('secret', 'string', array('length' => 40));
- $devis->addIndex(array('secret'));
- $devis->addColumn('details', 'text');
- // Réponse
- $devis->addColumn('reponse', 'text');
- $devis->addColumn('date_reponse', 'datetime');
- $devis->addColumn('montant_ht', 'float');
- $devis->addColumn('montant_ttc', 'float');
- // Paiement
- $devis->addColumn('infos_paiement', 'text');
- $devis->addColumn('date_paiement', 'datetime');
- }
-
-
- protected function _initDbViews() {
- parent::_initDbViews();
- $db = Zend_Db_Table::getDefaultAdapter();
- $db->createView("devis_view", $db->select()->from('devis', array('*', 'date_action' => 'GREATEST(`date`,`date_reponse`,`date_paiement`)')));
- }
-
-
- /**
- *
- * @return array
- */
- public function getCMSTemplates() {
- $templates = parent::getCMSTemplates();
- $templates['Pages'] = array(
- 'services' => 'Services',
- 'servicesdetail' => 'Service (détail)',
- 'magasins' => 'Magasins',
- 'devis' => 'Devis',
- 'faq' => 'FAQ'
- );
- return $templates;
- }
-
- /**
- *
- * @return array
- */
- protected function _getNavigationFields() {
- return array('shortTitle', 'longTitle', 'url', 'target', 'theme', 'infos');
- }
-
- protected function _makeNavigationOnePage(&$navigation, $r, $t, $isAdmin, $locale = false) {
- $page = parent::_makeNavigationOnePage($navigation, $r, $t, $isAdmin, $locale);
- if (isset($t['theme'])) {
- $page->setCustomHtmlAttrib('data-theme', $t['theme']);
- }
- if (isset($t['infos'])) {
- $page->infos = $t['infos'];
- }
-
- return $page;
- }
-
- protected function __initDefaultMailTransport() {
- return new CubeIT_Mail_Transport_Mandrill();
- //return new CubeIT_Mail_Transport_Sendmail('-freturn@detouteslescouleurs.com');
- }
-
- protected function _initAcl() {
- $acl = parent::_initAcl();
-
- $acl->addRole('devis', 'staff');
- $acl->addResource('administration/devis');
- $acl->addResource('administration/users/devis', 'administration/users/admin');
- $acl->allow('devis', 'administration/devis');
-
- return $acl;
- }
-
-
- function __destroy() {
- endProfile();
- }
+class Bootstrap extends CubeIT_Bootstrap
+{
+
+ protected function _initMinimum()
+ {
+ parent::_initMinimum();
+ // If a project with html display (don't activate by default for web services apps)
+ $this->bootstrap('doctype');
+ }
+
+ protected function _initScripts()
+ {
+ parent::_initScripts();
+ }
+
+ protected function _initRouter($initCms = true, $standard = true)
+ {
+ $router = parent::_initRouter($initCms, $standard);
+ $router->addStandardRoute('devis', 'devis');
+ $router->addStandardRoute('payment', 'payment');
+ $router->addStandardRoute('sogecommerce', 'sogecommerce');
+ return $router;
+ }
+
+ /**
+ *
+ * @param \Doctrine\DBAL\Schema\Schema $schema
+ * @param mixed $options
+ */
+ protected function _defineSchema(&$schema, $options)
+ {
+ parent::_defineSchema($schema, $options);
+
+ $devis = $schema->createTable('devis');
+ $devis->addColumn('id', 'integer', array('unsigned' => true, 'autoincrement' => true));
+ $devis->setPrimaryKey(array('id'));
+ $devis->addColumn('nom', 'string', array('length' => 128));
+ $devis->addIndex(array('nom'));
+ $devis->addColumn('email', 'string', array('length' => 128));
+ $devis->addIndex(array('email'));
+ $devis->addColumn('prenom', 'string', array('length' => 128));
+ $devis->addIndex(array('prenom'));
+ $devis->addColumn('societe', 'string', array('length' => 128));
+ $devis->addIndex(array('societe'));
+ $devis->addColumn('telephone', 'string', array('length' => 32));
+ $devis->addColumn('type', 'string', array('length' => 3));
+ $devis->addColumn('mobile', 'string', array('length' => 32));
+ $devis->addColumn('adresse', 'string', array('length' => 128));
+ $devis->addColumn('code_postal', 'string', array('length' => 8));
+ $devis->addColumn('ville', 'string', array('length' => 128));
+ $devis->addColumn('country', 'string', array('length' => 4, 'default' => 'FR'));
+ $devis->addColumn('tva_intra', 'string', array('length' => 32));
+ $devis->addColumn('reference', 'text');
+ $devis->addColumn('demandes', 'text');
+ $devis->addColumn('magasin', 'string', array('length' => 32));
+ $devis->addIndex(array('magasin'));
+ $devis->addColumn('livraison', 'boolean');
+ $devis->addColumn('adresse_livraison', 'string', array('length' => 512));
+ $devis->addColumn('complement_livraison', 'string', array('length' => 512));
+ $devis->addColumn('fichiers', 'text');
+ $devis->addColumn('date', 'datetime');
+ $devis->addColumn('tva', 'float', array('default' => '20'));
+ $devis->addIndex(array('date'));
+ $devis->addColumn('status', 'integer');
+ $devis->addIndex(array('status'));
+ $devis->addColumn('secret', 'string', array('length' => 40));
+ $devis->addIndex(array('secret'));
+ $devis->addColumn('details', 'text');
+ // Réponse
+ $devis->addColumn('reponse', 'text');
+ $devis->addColumn('date_reponse', 'datetime');
+ $devis->addColumn('montant_ht', 'float');
+ $devis->addColumn('montant_ttc', 'float');
+ // Paiement
+ $devis->addColumn('infos_paiement', 'text');
+ $devis->addColumn('date_paiement', 'datetime');
+ $devis->addColumn('methode_paiement', 'string', array('length' => 40));
+ }
+
+
+ protected function _initDbViews()
+ {
+ parent::_initDbViews();
+ $db = Zend_Db_Table::getDefaultAdapter();
+ $db->createView("devis_view", $db->select()->from('devis', array('*', 'date_action' => 'GREATEST(`date`,`date_reponse`,`date_paiement`)')));
+ }
+
+
+ /**
+ *
+ * @return array
+ */
+ public function getCMSTemplates()
+ {
+ $templates = parent::getCMSTemplates();
+ $templates['Pages'] = array(
+ 'services' => 'Services',
+ 'servicesdetail' => 'Service (détail)',
+ 'magasins' => 'Magasins',
+ 'devis' => 'Devis',
+ 'faq' => 'FAQ'
+ );
+ return $templates;
+ }
+
+ /**
+ *
+ * @return array
+ */
+ protected function _getNavigationFields()
+ {
+ return array('shortTitle', 'longTitle', 'url', 'target', 'theme', 'infos');
+ }
+
+ protected function _makeNavigationOnePage(&$navigation, $r, $t, $isAdmin, $locale = false)
+ {
+ $page = parent::_makeNavigationOnePage($navigation, $r, $t, $isAdmin, $locale);
+ if (isset($t['theme'])) {
+ $page->setCustomHtmlAttrib('data-theme', $t['theme']);
+ }
+ if (isset($t['infos'])) {
+ $page->infos = $t['infos'];
+ }
+
+ return $page;
+ }
+
+ protected function __initDefaultMailTransport()
+ {
+ $transport = $this->getOpt("mail.transport", 'mandrill');
+ if ($transport === 'mandrill') {
+ return new CubeIT_Mail_Transport_Mandrill();
+ } else if ($transport === 'postal') {
+ return new CubeIT_Mail_Transport_Postal();
+ }
+
+ //return new CubeIT_Mail_Transport_Sendmail('-freturn@detouteslescouleurs.com');
+ }
+
+ protected function _initAcl()
+ {
+ $acl = parent::_initAcl();
+
+ $acl->addRole('devis', 'staff');
+ $acl->addResource('administration/devis');
+ $acl->addResource('administration/users/devis', 'administration/users/admin');
+ $acl->allow('devis', 'administration/devis');
+
+ return $acl;
+ }
+
+
+ function __destroy()
+ {
+ endProfile();
+ }
}
<?php
-class DTLC_Form_Devis extends CubeIT_Form_List {
-
- const REDACTION = -1;
- const ATTENTE_REPONSE = 0;
- const ATTENTE_PAIEMENT = 1;
- const PAYE = 2;
- const ANNULE = 4;
- const DONE = 5;
-
- protected $_status = DTLC_Form_Devis::REDACTION;
- protected $_admin = false;
- protected $_envoiText;
- protected $_confirmationText;
-
- public function init() {
- parent::init();
-
- $this->setAction('/ajax/devis');
- $this->setSubmitMessage("Veuillez patienter");
- $this->addClass('edit');
- $this->setAjax(true);
- $this->addClass('devis');
- $this->setId('devis');
- $this->setFilterColumns(array('status', 'magasin'));
-
- $bootstrap = Bootstrap::getInstance();
-
- $tva = new Zend_Form_Element_Hidden('tva');
- $tva->setValue($bootstrap->getOpt('tva'));
- $this->addElement($tva);
- }
-
- public function renderList(Zend_View_Abstract $view, $element = '', $prefix = 'admin', $div = false, $dataFilters = null, $search = true) {
- $this->_initList();
- if ($this->getElement('id') == null) {
- $this->addElement(new CubeIT_Form_Element_Id());
- }
- return parent::renderList($view, $element, $prefix, $div, $dataFilters, $search);
- }
-
- public function getEnvoiText() {
- return $this->_envoiText;
- }
-
- public function setEnvoiText($envoiText) {
- $this->_envoiText = $envoiText;
- return $this;
- }
-
- public function getConfirmationText() {
- return $this->_confirmationText;
- }
-
- public function setConfirmationText($confirmationText) {
- $this->_confirmationText = $confirmationText;
- return $this;
- }
-
- public function getAdmin() {
- return $this->_admin;
- }
-
-
- public function setAdmin($admin = true) {
- $this->_admin = $admin;
- if ($admin) {
- $this->addClass('admin');
- } else {
- $this->removeClass('admin');
- }
- return $this;
- }
-
- public function getStatus() {
- return $this->_status;
- }
-
- public function setStatus($status) {
- $this->_status = $status;
- $this->_initFields();
- return $this;
- }
-
- protected function _initFields() {
- $this->_setAdminInfos();
- $this->_setMagasins();
- $this->_setCoordonnees();
- $this->_setDemandes();
- $this->_setFichiers();
- $this->_setLivraison();
- $this->_setAdminReponse();
- $this->_setEnvoyer();
-
- $this->_initList();
- }
-
- protected function _initList() {
- $this->setNewTitle(null);
- $this->setEditTitle('Editer le devis $id');
- $this->setListTitle('Gestion des devis');
- $this->setBaseTable('devis_view');
- $this->setWriteTable('devis');
- $this->setIdColumn('id');
- $this->setTitleColumn('societe');
- $this->setPerPage(30);
- $this->setAdditionnalColumns(array('email', 'Prix TTC' => '_montant_ttc', 'status', 'Date' => 'date_action', 'magasin'));
- $this->setEditLinkTemplate(array('helper' => 'link', 'url' => '/admin/devis/%s'));
- $this->setAdditionnalActions(array(
- array($this, '_actionDone'),
- array($this, '_actionDownload'),
- array($this, '_actionDuplicate'),
- array($this, '_actionDocument')
- )
- );
- $this->setAdmin();
-
- if ($this->getElement('nom') == null) {
- $this->_initFields();
- }
- }
-
- public function getValueForDisplay($name, $r = null, $view = null) {
- if ($name == '_montant_ttc') {
- if ($this->getValue('status') == 0) {
- return '-';
- }
- return number_format($this->details->getValue('montant_ttc'), 2, ',', ' ');
- } else if ($name == 'date_action') {
- $date = new CubeIT_Date($r[$name], CubeIT_Date::MYSQL);
- return $date->toString('dd-MM-y HH:mm');
- }
-
- return parent::getValueForDisplay($name);
- }
-
- protected function _actionDuplicate($r, $view) {
- if ($r['status'] < 1) {
- return;
- }
- return $view->linkAjax($view->imageSilk('page_copy'), '/admin/ajax/devisDuplicate/' . $r['id'], array('title' => 'Dupliquer ce devis', 'target' => '_blank'));
- }
-
- protected function _actionDone($r, $view) {
- if ($r['status'] != 2) {
- return;
- }
- return $view->linkPopup($view->imageSilk('tick'), '/admin/ajaxpopup/devisDone/' . $r['id'], array('title' => 'Marquer comme terminé'));
- }
-
-
- protected function _actionDownload($r, $view) {
- if (!$r['fichiers']) {
- return;
- }
- return $view->link($view->imageSilk('attach'), '/admin/devisDownload/' . $r['id'], array('title' => 'Télécharger les pièces jointes'));
- }
-
- protected function _actionDocument($r, $view) {
- if ($r['status'] < 1) {
- return;
- }
- $title = 'Voir le devis';
- $img = 'page_red';
- if ($r['status'] == 2 || $r['status'] == 5) {
- $title = 'Voir la facture';
- $img = 'page_green';
- }
- return $view->link($view->imageSilk($img), '/devis/index/' . $r['id'] . '/' . $r['secret'], array('title' => $title, 'target' => '_blank'));
- }
-
- public function setDefaults(array $defaults) {
- if ($this->getElement('nom') == null) {
- $this->_initFields();
- }
-
- return @parent::setDefaults($defaults);
- }
-
- public function isValid($data) {
- if ($this->getElement('nom') == null) {
- $this->_initFields();
- }
- return parent::isValid($data);
- }
-
- public function render(Zend_View_Interface $view = null) {
- if ($this->getElement('nom') == null) {
- $this->_initFields();
- }
-
- if ($this->getAdmin()) {
- $d = $this->getSubForm('details');
-
- if (null != $d) {
- if ($d->isEmpty()) {
- $demandes = $this->getSubForm('demandes');
- $demandes = $demandes->getTextes();
- $details = array();
-
- foreach ($demandes as $k => $d) {
- $details['descriptif_' . $k] = $d;
- }
-
- $this->getSubForm('details')->setDefaults($details);
- }
- $this->removeSubForm('demandes');
- }
- }
-
- if (!$this->getValue('livraison')) {
- $this->removeElement('adresse_livraison');
- $this->removeElement('complement_livraison');
- }
-
- return parent::render($view);
- }
-
- public function deleteItem($id) {
- $this->_initList();
- parent::deleteItem($id);
- }
-
- protected function _setMagasins() {
- $validator = new Zend_Validate_NotEmpty();
- $validator->setMessage('Veuillez choisir un magasin');
-
- $mags = DTLC_Util::getMagasins();
- $options = array();
- foreach ($mags as $m) {
- $options[$m['id']] = $m['nom'];
- }
-
- $magasins = new Zend_Form_Element_Radio('magasin');
- $magasins->setRegisterInArrayValidator(false);
- if ($this->getAdmin()) {
- $magasins->setLabel('Magasin');
- }
- $magasins->setRequired(true);
- $magasins->setMultiOptions($options);
- $magasins->clearValidators();
- $magasins->addValidator($validator);
- $this->addElement($magasins);
-
- $legend = $this->getAdmin() ? 'Magasin' : 'Choix du magasin*';
- $this->addDisplayGroup(array('magasin'), 'magasins_group', array('legend' => $legend));
- }
-
- protected function _setCoordonnees() {
-
- $notEmptyValidator = new Zend_Validate_NotEmpty();
- $notEmptyValidator->setMessage('Ce champ est obligatoire', Zend_Validate_NotEmpty::IS_EMPTY);
- $notEmptyValidator->zfBreakChainOnFailure = true;
-
- $emailValidator = new Zend_Validate_EmailAddress();
- $emailValidator->setMessage('Cette adresse est invalide', Zend_Validate_EmailAddress::INVALID_FORMAT);
- $emailValidator->setMessage('Cette adresse est invalide', Zend_Validate_EmailAddress::INVALID_HOSTNAME);
- $emailValidator->zfBreakChainOnFailure = true;
-
- $societe = new Zend_Form_Element_Text('societe');
- $societe->setLabel('Société');
- $this->addElement($societe);
-
- $prenom = new Zend_Form_Element_Text('prenom');
- $prenom->setLabel('Prenom');
- $prenom->setRequired(true);
- $prenom->addValidator($notEmptyValidator);
- $this->addElement($prenom);
-
- $nom = new Zend_Form_Element_Text('nom');
- $nom->setLabel('Nom');
- $nom->setRequired(true);
- $nom->addValidator($notEmptyValidator);
- $this->addElement($nom);
-
- $telephone = new CubeIT_Form_Element_Phone('telephone');
- $telephone->setLabel('Téléphone');
- $telephone->setRequired(true);
- $telephone->addValidator($notEmptyValidator);
- $this->addElement($telephone);
-
- $mobile = new CubeIT_Form_Element_Phone('mobile');
- $mobile->setLabel('Mobile');
- $this->addElement($mobile);
-
- $email = new CubeIT_Form_Element_Email('email');
- $email->setLabel(__('Email'));
- $email->setRequired(true);
- $email->clearValidators();
- $email->addValidator($notEmptyValidator, true);
- $email->addValidator($emailValidator, true);
- $this->addElement($email);
-
- $adresse = new Zend_Form_Element_Textarea('adresse');
- $adresse->setLabel('Adresse de facturation');
- $adresse->setAttrib('rows', 2);
- $adresse->setRequired(true);
- $adresse->clearValidators();
- $adresse->addValidator($notEmptyValidator, true);
- $this->addElement($adresse);
-
- $codepostal = new Zend_Form_Element_Text('code_postal');
- $codepostal->setLabel(__('Code postal'));
- $codepostal->setRequired(true);
- $codepostal->clearValidators();
- $codepostal->addValidator($notEmptyValidator, true);
- $this->addElement($codepostal);
-
- $ville = new Zend_Form_Element_Text('ville');
- $ville->setLabel(__('Ville'));
- $ville->setRequired(true);
- $ville->clearValidators();
- $ville->addValidator($notEmptyValidator, true);
- $this->addElement($ville);
-
- $pays = new CubeIT_Form_Element_Country('pays');
- $pays->setLabel(__('Pays'));
- $pays->setRequired(true);
- $pays->setDetectCountry(false);
+class DTLC_Form_Devis extends CubeIT_Form_List
+{
+
+ const REDACTION = -1;
+ const ATTENTE_REPONSE = 0;
+ const ATTENTE_PAIEMENT = 1;
+ const PAYE = 2;
+ const ANNULE = 4;
+ const DONE = 5;
+
+ protected $_status = DTLC_Form_Devis::REDACTION;
+ protected $_admin = false;
+ protected $_envoiText;
+ protected $_confirmationText;
+
+ public function init()
+ {
+ parent::init();
+
+ $this->setAction('/ajax/devis');
+ $this->setSubmitMessage("Veuillez patienter");
+ $this->addClass('edit');
+ $this->setAjax(true);
+ $this->addClass('devis');
+ $this->setId('devis');
+ $this->setFilterColumns(array('status', 'magasin'));
+
+ $bootstrap = Bootstrap::getInstance();
+
+ $tva = new Zend_Form_Element_Hidden('tva');
+ $tva->setValue($bootstrap->getOpt('tva'));
+ $this->addElement($tva);
+ }
+
+ public function renderList(Zend_View_Abstract $view, $element = '', $prefix = 'admin', $div = false, $dataFilters = null, $search = true)
+ {
+ $this->_initList();
+ if ($this->getElement('id') == null) {
+ $this->addElement(new CubeIT_Form_Element_Id());
+ }
+ return parent::renderList($view, $element, $prefix, $div, $dataFilters, $search);
+ }
+
+ public function getEnvoiText()
+ {
+ return $this->_envoiText;
+ }
+
+ public function setEnvoiText($envoiText)
+ {
+ $this->_envoiText = $envoiText;
+ return $this;
+ }
+
+ public function getConfirmationText()
+ {
+ return $this->_confirmationText;
+ }
+
+ public function setConfirmationText($confirmationText)
+ {
+ $this->_confirmationText = $confirmationText;
+ return $this;
+ }
+
+ public function getAdmin()
+ {
+ return $this->_admin;
+ }
+
+
+ public function setAdmin($admin = true)
+ {
+ $this->_admin = $admin;
+ if ($admin) {
+ $this->addClass('admin');
+ } else {
+ $this->removeClass('admin');
+ }
+ return $this;
+ }
+
+ public function getStatus()
+ {
+ return $this->_status;
+ }
+
+ public function setStatus($status)
+ {
+ $this->_status = $status;
+ $this->_initFields();
+ return $this;
+ }
+
+ protected function _initFields()
+ {
+ $this->_setAdminInfos();
+ $this->_setMagasins();
+ $this->_setCoordonnees();
+ $this->_setDemandes();
+ $this->_setFichiers();
+ $this->_setLivraison();
+ $this->_setAdminReponse();
+ $this->_setEnvoyer();
+
+ $this->_initList();
+ }
+
+ protected function _initList()
+ {
+ $this->setNewTitle(null);
+ $this->setEditTitle('Editer le devis $id');
+ $this->setListTitle('Gestion des devis');
+ $this->setBaseTable('devis_view');
+ $this->setWriteTable('devis');
+ $this->setIdColumn('id');
+ $this->setTitleColumn('societe');
+ $this->setPerPage(30);
+ $this->setAdditionnalColumns(array('email', 'Prix TTC' => '_montant_ttc', 'status', 'Date' => 'date_action', '' => 'type', 'magasin'));
+ $this->setEditLinkTemplate(array('helper' => 'link', 'url' => '/admin/devis/%s'));
+ $this->setAdditionnalActions(array(
+ array($this, '_actionDone'),
+ array($this, '_actionDownload'),
+ array($this, '_actionDuplicate'),
+ array($this, '_actionStore'),
+ array($this, '_actionDocument')
+ )
+ );
+ $this->setAdmin();
+
+ if ($this->getElement('nom') == null) {
+ $this->_initFields();
+ }
+ }
+
+ public function getValueForDisplay($name, $r = null, $view = null)
+ {
+ if ($name == '_montant_ttc') {
+ if ($this->getValue('status') == 0) {
+ return '-';
+ }
+ return number_format($this->details->getValue('montant_ttc'), 2, ',', ' ');
+ } else if ($name == 'date_action') {
+ $date = new CubeIT_Date($r[$name], CubeIT_Date::MYSQL);
+ return $date->toString('dd-MM-y HH:mm');
+ }
+
+ return parent::getValueForDisplay($name);
+ }
+
+ protected function _actionDuplicate($r, $view)
+ {
+ if ($r['status'] < 1) {
+ return;
+ }
+ return $view->linkAjax($view->imageSilk('page_copy'), '/admin/ajax/devisDuplicate/' . $r['id'], array('title' => 'Dupliquer ce devis', 'target' => '_blank'));
+ }
+
+ protected function _actionStore($r, $view)
+ {
+ if ($r['status'] > 1) {
+ return;
+ }
+ return $view->linkPopup($view->imageSilk('cart'), '/admin/ajaxpopup/devisConvertToStoreOrder/' . $r['id'], array('title' => 'Convertir en facture magasin'));
+ }
+
+ protected function _actionDone($r, $view)
+ {
+ if ($r['status'] != 2) {
+ return;
+ }
+ return $view->linkPopup($view->imageSilk('tick'), '/admin/ajaxpopup/devisDone/' . $r['id'], array('title' => 'Marquer comme terminé'));
+ }
+
+
+ protected function _actionDownload($r, $view)
+ {
+ if (!$r['fichiers']) {
+ return;
+ }
+ return $view->link($view->imageSilk('attach'), '/admin/devisDownload/' . $r['id'], array('title' => 'Télécharger les pièces jointes'));
+ }
+
+ protected function _actionDocument($r, $view)
+ {
+ if ($r['status'] < 1) {
+ return;
+ }
+ $title = 'Voir le devis';
+ $img = 'page_red';
+ if ($r['status'] == 2 || $r['status'] == 5) {
+ $title = 'Voir la facture';
+ $img = 'page_green';
+ }
+ return $view->link($view->imageSilk($img), '/devis/index/' . $r['id'] . '/' . $r['secret'], array('title' => $title, 'target' => '_blank'));
+ }
+
+ public function setDefaults(array $defaults)
+ {
+ if ($this->getElement('nom') == null) {
+ $this->_initFields();
+ }
+
+ return @parent::setDefaults($defaults);
+ }
+
+ public function isValid($data)
+ {
+ if ($this->getElement('nom') == null) {
+ $this->_initFields();
+ }
+ return parent::isValid($data);
+ }
+
+ public function render(Zend_View_Interface $view = null)
+ {
+ if ($this->getElement('nom') == null) {
+ $this->_initFields();
+ }
+
+ if ($this->getAdmin()) {
+ $d = $this->getSubForm('details');
+
+ if (null != $d) {
+ if ($d->isEmpty()) {
+ $demandes = $this->getSubForm('demandes');
+ $demandes = $demandes->getTextes();
+ $details = array();
+
+ foreach ($demandes as $k => $d) {
+ $details['descriptif_' . $k] = $d;
+ }
+
+ $this->getSubForm('details')->setDefaults($details);
+ }
+ $this->removeSubForm('demandes');
+ }
+ }
+
+ if (!$this->getValue('livraison')) {
+ $this->removeElement('adresse_livraison');
+ $this->removeElement('complement_livraison');
+ }
+
+ return parent::render($view);
+ }
+
+ public function deleteItem($id)
+ {
+ $this->_initList();
+ parent::deleteItem($id);
+ }
+
+ protected function _setMagasins()
+ {
+ $validator = new Zend_Validate_NotEmpty();
+ $validator->setMessage('Veuillez choisir un magasin');
+
+ $mags = DTLC_Util::getMagasins();
+ $options = array();
+ foreach ($mags as $m) {
+ $options[$m['id']] = $m['nom'];
+ }
+
+ $magasins = new Zend_Form_Element_Radio('magasin');
+ $magasins->setRegisterInArrayValidator(false);
+ if ($this->getAdmin()) {
+ $magasins->setLabel('Magasin');
+ }
+ $magasins->setRequired(true);
+ $magasins->setMultiOptions($options);
+ $magasins->clearValidators();
+ $magasins->addValidator($validator);
+ $this->addElement($magasins);
+
+ $legend = $this->getAdmin() ? 'Magasin' : 'Choix du magasin*';
+ $this->addDisplayGroup(array('magasin'), 'magasins_group', array('legend' => $legend));
+ }
+
+ protected function _setCoordonnees()
+ {
+
+ $notEmptyValidator = new Zend_Validate_NotEmpty();
+ $notEmptyValidator->setMessage('Ce champ est obligatoire', Zend_Validate_NotEmpty::IS_EMPTY);
+ $notEmptyValidator->zfBreakChainOnFailure = true;
+
+ $emailValidator = new Zend_Validate_EmailAddress();
+ $emailValidator->setMessage('Cette adresse est invalide', Zend_Validate_EmailAddress::INVALID_FORMAT);
+ $emailValidator->setMessage('Cette adresse est invalide', Zend_Validate_EmailAddress::INVALID_HOSTNAME);
+ $emailValidator->zfBreakChainOnFailure = true;
+
+ $societe = new Zend_Form_Element_Text('societe');
+ $societe->setLabel('Société');
+ $this->addElement($societe);
+
+ $prenom = new Zend_Form_Element_Text('prenom');
+ $prenom->setLabel('Prenom');
+ $prenom->setRequired(true);
+ $prenom->addValidator($notEmptyValidator);
+ $this->addElement($prenom);
+
+ $nom = new Zend_Form_Element_Text('nom');
+ $nom->setLabel('Nom');
+ $nom->setRequired(true);
+ $nom->addValidator($notEmptyValidator);
+ $this->addElement($nom);
+
+ $telephone = new CubeIT_Form_Element_Phone('telephone');
+ $telephone->setLabel('Téléphone');
+ $telephone->setRequired(true);
+ $telephone->addValidator($notEmptyValidator);
+ $this->addElement($telephone);
+
+ $mobile = new CubeIT_Form_Element_Phone('mobile');
+ $mobile->setLabel('Mobile');
+ $this->addElement($mobile);
+
+ $email = new CubeIT_Form_Element_Email('email');
+ $email->setLabel(__('Email'));
+ $email->setRequired(true);
+ $email->clearValidators();
+ $email->addValidator($notEmptyValidator, true);
+ $email->addValidator($emailValidator, true);
+ $this->addElement($email);
+
+ $adresse = new Zend_Form_Element_Textarea('adresse');
+ $adresse->setLabel('Adresse de facturation');
+ $adresse->setAttrib('rows', 2);
+ $adresse->setRequired(true);
+ $adresse->clearValidators();
+ $adresse->addValidator($notEmptyValidator, true);
+ $this->addElement($adresse);
+
+ $codepostal = new Zend_Form_Element_Text('code_postal');
+ $codepostal->setLabel(__('Code postal'));
+ $codepostal->setRequired(true);
+ $codepostal->clearValidators();
+ $codepostal->addValidator($notEmptyValidator, true);
+ $this->addElement($codepostal);
+
+ $ville = new Zend_Form_Element_Text('ville');
+ $ville->setLabel(__('Ville'));
+ $ville->setRequired(true);
+ $ville->clearValidators();
+ $ville->addValidator($notEmptyValidator, true);
+ $this->addElement($ville);
+
+ $pays = new CubeIT_Form_Element_Country('pays');
+ $pays->setLabel(__('Pays'));
+ $pays->setRequired(true);
+ $pays->setDetectCountry(false);
$pays->setValue('FR');
- $this->addElement($pays);
-
- $tva_intra = new Zend_Form_Element_Text('tva_intra');
- $tva_intra->setLabel(__('N° de TVA'));
- $tva_intra->clearValidators();
- $tva_intra->addValidator(new CubeIT_Validate_VATEurope(), true);
- $this->addElement($tva_intra);
-
- $reference = new Zend_Form_Element_Text('reference');
- $reference->setLabel(__('Référence dossier (facultatif)'));
- $this->addElement($reference);
-
- $legend = $this->getAdmin() ? 'Coordonnées' : 'Vos coordonnées';
- $this->addDisplayGroup(array('societe', 'prenom', 'nom', 'telephone', 'mobile', 'email', 'reference', 'adresse', 'code_postal', 'ville', 'pays', 'tva_intra'), 'coordonnees', array('legend' => $legend));
- }
-
- protected function _setDemandes() {
- $demandes = new DTLC_Form_Devis_Demandes();
- if ($this->getAdmin()) {
- $demandes->setLegend('Demandes');
- } else {
- $demandes->setLegend('Vos demandes');
- }
- $demandes->setAdmin($this->getAdmin());
- $this->addSubForm($demandes, 'demandes');
- }
-
- protected function _setAdminInfos() {
- if ($this->getAdmin()) {
- $this->setAction('/admin/ajax/devis');
-
- $id = new CubeIT_Form_Element_Id();
- $this->addElement($id);
-
- $date = new CubeIT_Form_Element_Date('date');
- $date->setLabel('Date');
- $date->setAttrib('disabled', 'disabled');
- $date->setPrecision(Zend_Date::MINUTE);
- $date->setDisplayFormat(Zend_Date::DATETIME_SHORT);
- $this->addElement($date);
-
- $status = new Zend_Form_Element_Select('status');
- $status->setLabel('Status');
- $status->setMultiOptions(array(self::ATTENTE_REPONSE => 'En attente de réponse', self::ATTENTE_PAIEMENT => 'Répondu, en attente de paiement', self::PAYE => 'Payé', self::ANNULE => 'Annulé', self::DONE => 'Payé et terminé'));
- $this->addElement($status);
-
- $this->addDisplayGroup(array('id', 'status', 'date'), 'group_infos', array('legend' => 'Demande de devis'));
- }
- }
-
- protected function _setFichiers() {
- $fichiers = new CubeIT_Form_Element_File('fichiers');
- $fichiers->clearValidators();
- $fichiers->setRequired(false);
- $fichiers->setAttrib('data-download', $this->getAdmin());
- $fichiers->setAttrib('data-dir', 'userfiles');
- $fichiers->setAttrib('data-admin', 0);
- $fichiers->setAttrib('data-timecomponent', false);
- $this->addElement($fichiers);
-
- $legend = $this->getAdmin() ? 'Fichiers joints' : 'Vos fichiers';
- $this->addDisplayGroup(array('fichiers'), 'fichiers_group', array('legend' => $legend));
- }
-
- protected function _setEnvoyer() {
- $confirmation = new Zend_Form_Element_Hidden('confirmation');
- $confirmation->setValue($this->getConfirmationText());
- $this->addElement($confirmation);
-
- $texte = new CubeIT_Form_Element_Static('texte');
- if (!$this->getAdmin()) {
- $texte->setValue($this->getEnvoiText());
- } else {
- $texte->setValue('<br /><br /><br />');
- }
-
- $this->addElement($texte);
-
- $submit = new Zend_Form_Element_Submit('submit');
- if (!$this->getAdmin()) {
- $submit->setLabel('Envoyer');
- } else if ($this->getStatus() == self::ATTENTE_REPONSE) {
- $submit->setLabel('Envoyer la réponse');
- } else {
- $submit->setLabel('Enregistrer');
- }
- $this->addElement($submit);
-
- $this->addDisplayGroup(array('confirmation', 'texte', 'submit'), 'last');
- }
-
- protected function _setLivraison() {
-
- $livraison = new Zend_Form_Element_Radio('livraison');
- $livraison->setMultiOptions(array(1 => 'Oui', 0 => 'Non'));
- $livraison->setValue(0);
- $this->addElement($livraison);
-
- $adresseLivraison = new Zend_Form_Element_Textarea('adresse_livraison');
- $adresseLivraison->setLabel('Adresse de livraison (si différente)');
- $adresseLivraison->setAttrib('rows', 3);
- $this->addElement($adresseLivraison);
-
- $complementLivraison = new Zend_Form_Element_Textarea('complement_livraison');
- $complementLivraison->setLabel('Digicode, étage, interphone, bâtiment, etc.');
- $complementLivraison->setAttrib('rows', 2);
- $this->addElement($complementLivraison);
-
- $this->addDisplayGroup(array('livraison', 'adresse_livraison', 'complement_livraison'), 'livraison_group', array('legend' => 'Livraison / Expédition'));
- }
-
- protected function _setAdminReponse() {
- if ($this->getAdmin()) {
- if ($this->getStatus() >= self::ATTENTE_PAIEMENT) {
- $date_reponse = new CubeIT_Form_Element_Date('date_reponse');
- $date_reponse->setLabel('Date de la réponse');
- $date_reponse->setAttrib('disabled', 'disabled');
- $this->addElement($date_reponse);
- }
-
- $reponse = new DTLC_Form_Element_Markitup_Color('reponse');
- $reponse->setLabel('Réponse');
- $this->addElement($reponse);
-
- $this->addDisplayGroup(array('date_reponse', 'reponse'), 'reponse_group', array('legend' => 'Réponse DTLC'));
-
-
- $details = new DTLC_Form_Devis_Reponses();
- $details->setTVA($this->getValue('tva'));
- $details->setLegend('Détails de l\'offre');
- $this->addSubForm($details, 'details');
-
- if ($this->getStatus() >= self::ATTENTE_PAIEMENT) {
- $date = new CubeIT_Form_Element_Date('date_paiement');
- $date->setLabel('Date du paiement');
- $date->setAttrib('disabled', 'disabled');
- $this->addElement($date);
-
- $infos = new Zend_Form_Element_Textarea('infos_paiement');
- $infos->setLabel('Informations sur le paiement');
- $this->addElement($infos);
-
- $this->addDisplayGroup(array('date_paiement', 'infos_paiement'), 'paiement_group', array('legend' => 'Paiement'));
- }
- }
- }
+ $this->addElement($pays);
+
+ $tva_intra = new Zend_Form_Element_Text('tva_intra');
+ $tva_intra->setLabel(__('N° de TVA'));
+ $tva_intra->clearValidators();
+ $tva_intra->addValidator(new CubeIT_Validate_VATEurope(), true);
+ $this->addElement($tva_intra);
+
+ $reference = new Zend_Form_Element_Text('reference');
+ $reference->setLabel(__('Référence dossier (facultatif)'));
+ $this->addElement($reference);
+
+ $legend = $this->getAdmin() ? 'Coordonnées' : 'Vos coordonnées';
+ $this->addDisplayGroup(array('societe', 'prenom', 'nom', 'telephone', 'mobile', 'email', 'reference', 'adresse', 'code_postal', 'ville', 'pays', 'tva_intra'), 'coordonnees', array('legend' => $legend));
+ }
+
+ protected function _setDemandes()
+ {
+ $demandes = new DTLC_Form_Devis_Demandes();
+ if ($this->getAdmin()) {
+ $demandes->setLegend('Demandes');
+ } else {
+ $demandes->setLegend('Vos demandes');
+ }
+ $demandes->setAdmin($this->getAdmin());
+ $this->addSubForm($demandes, 'demandes');
+ }
+
+ protected function _setAdminInfos()
+ {
+ if ($this->getAdmin()) {
+ $this->setAction('/admin/ajax/devis');
+
+ $id = new CubeIT_Form_Element_Id();
+ $this->addElement($id);
+
+ $date = new CubeIT_Form_Element_Date('date');
+ $date->setLabel('Date');
+ $date->setAttrib('disabled', 'disabled');
+ $date->setPrecision(Zend_Date::MINUTE);
+ $date->setDisplayFormat(Zend_Date::DATETIME_SHORT);
+ $this->addElement($date);
+
+ $status = new Zend_Form_Element_Select('status');
+ $status->setLabel('Status');
+ $status->setMultiOptions(array(self::ATTENTE_REPONSE => 'En attente de réponse', self::ATTENTE_PAIEMENT => 'Répondu, en attente de paiement', self::PAYE => 'Payé', self::ANNULE => 'Annulé', self::DONE => 'Payé et terminé'));
+ $this->addElement($status);
+
+ $type = new Zend_Form_Element_Select('type');
+ $type->setLabel('Type de commande');
+ $type->setMultiOptions(['NET' => 'Internet', 'MAG' => 'Magasin']);
+ $type->setValue('NET');
+ $this->addElement($type);
+
+ $this->addDisplayGroup(array('id', 'status', 'date', 'type'), 'group_infos', array('legend' => 'Demande de devis'));
+ }
+ }
+
+ protected function _setFichiers()
+ {
+ $fichiers = new CubeIT_Form_Element_File('fichiers');
+ $fichiers->clearValidators();
+ $fichiers->setRequired(false);
+ $fichiers->setAttrib('data-download', $this->getAdmin());
+ $fichiers->setAttrib('data-dir', 'userfiles');
+ $fichiers->setAttrib('data-admin', 0);
+ $fichiers->setAttrib('data-timecomponent', false);
+ $this->addElement($fichiers);
+
+ $legend = $this->getAdmin() ? 'Fichiers joints' : 'Vos fichiers';
+ $this->addDisplayGroup(array('fichiers'), 'fichiers_group', array('legend' => $legend));
+ }
+
+ protected function _setEnvoyer()
+ {
+ $confirmation = new Zend_Form_Element_Hidden('confirmation');
+ $confirmation->setValue($this->getConfirmationText());
+ $this->addElement($confirmation);
+
+ $texte = new CubeIT_Form_Element_Static('texte');
+ if (!$this->getAdmin()) {
+ $texte->setValue($this->getEnvoiText());
+ } else {
+ $texte->setValue('<br /><br /><br />');
+ }
+
+ $this->addElement($texte);
+
+ $submit = new Zend_Form_Element_Submit('submit');
+ if (!$this->getAdmin()) {
+ $submit->setLabel('Envoyer');
+ } else if ($this->getStatus() == self::ATTENTE_REPONSE) {
+ $submit->setLabel('Envoyer la réponse');
+ } else {
+ $submit->setLabel('Enregistrer');
+ }
+ $this->addElement($submit);
+
+ $this->addDisplayGroup(array('confirmation', 'texte', 'submit'), 'last');
+ }
+
+ protected function _setLivraison()
+ {
+
+ $livraison = new Zend_Form_Element_Radio('livraison');
+ $livraison->setMultiOptions(array(1 => 'Oui', 0 => 'Non'));
+ $livraison->setValue(0);
+ $this->addElement($livraison);
+
+ $adresseLivraison = new Zend_Form_Element_Textarea('adresse_livraison');
+ $adresseLivraison->setLabel('Adresse de livraison (si différente)');
+ $adresseLivraison->setAttrib('rows', 3);
+ $this->addElement($adresseLivraison);
+
+ $complementLivraison = new Zend_Form_Element_Textarea('complement_livraison');
+ $complementLivraison->setLabel('Digicode, étage, interphone, bâtiment, etc.');
+ $complementLivraison->setAttrib('rows', 2);
+ $this->addElement($complementLivraison);
+
+ $this->addDisplayGroup(array('livraison', 'adresse_livraison', 'complement_livraison'), 'livraison_group', array('legend' => 'Livraison / Expédition'));
+ }
+
+ protected function _setAdminReponse()
+ {
+ if ($this->getAdmin()) {
+ if ($this->getStatus() >= self::ATTENTE_PAIEMENT) {
+ $date_reponse = new CubeIT_Form_Element_Date('date_reponse');
+ $date_reponse->setLabel('Date de la réponse');
+ $date_reponse->setAttrib('disabled', 'disabled');
+ $this->addElement($date_reponse);
+ }
+
+ $reponse = new DTLC_Form_Element_Markitup_Color('reponse');
+ $reponse->setLabel('Réponse');
+ $this->addElement($reponse);
+
+ $this->addDisplayGroup(array('date_reponse', 'reponse'), 'reponse_group', array('legend' => 'Réponse DTLC'));
+
+
+ $details = new DTLC_Form_Devis_Reponses();
+ $details->setTVA($this->getValue('tva'));
+ $details->setLegend('Détails de l\'offre');
+ $this->addSubForm($details, 'details');
+
+ if ($this->getStatus() >= self::ATTENTE_PAIEMENT) {
+ $payment_method = new Zend_Form_Element_Select('methode_paiement');
+ $payment_method->setLabel('Moyen de paiement');
+ $payment_method->setMultiOptions(['SOGENACTIF' => 'Sogenactif', 'CB' => 'Carte bancaire', 'ESPECES' => 'Espèces', 'CHEQUE' => 'Chèque', 'VIREMENT' => 'Virement']);
+ $payment_method->setValue('SOGENACTIF');
+ $this->addElement($payment_method);
+
+ $date = new CubeIT_Form_Element_Date('date_paiement');
+ $date->setLabel('Date du paiement');
+ $date->setAttrib('disabled', 'disabled');
+ $this->addElement($date);
+
+ $infos = new Zend_Form_Element_Textarea('infos_paiement');
+ $infos->setLabel('Informations sur le paiement');
+ $this->addElement($infos);
+
+ $this->addDisplayGroup(array('methode_paiement', 'date_paiement', 'infos_paiement'), 'paiement_group', array('legend' => 'Paiement'));
+ }
+ }
+ }
}