Example #1
0
 function setModel($m)
 {
     $m = parent::setModel($m);
     $complete = $this->add('xepan\\projects\\View_Progressbar', null, 'totalprogress', ['view\\progressbar']);
     $complete->template->set('total_task', $m['total_task']);
     $complete->template->set('completed_percentage', $m['completed_percentage']);
     $complete->template->set('color', $m['color']);
     $complete->template->set('critical_completed_percentage', abs($m['critical_completed_percentage'] - 100));
     $complete->template->set('high_completed_percentage', abs($m['high_completed_percentage'] - 100));
     $complete->template->set('medium_completed_percentage', abs($m['medium_completed_percentage'] - 100));
     $complete->template->set('low_completed_percentage', abs($m['low_completed_percentage'] - 100));
     $complete->template->set('title', 'Total Tasks');
     $self = $this->add('xepan\\projects\\View_Progressbar', null, 'selfprogress', ['view\\progressbar']);
     $self->template->set('self_task', $m['self_task']);
     $self->template->set('self_percentage', $m['self_percentage']);
     $self->template->set('self_color', $m['self_color']);
     $self->template->set('critical_self_percentage', abs($m['critical_self_percentage'] - 100));
     $self->template->set('high_self_percentage', abs($m['high_self_percentage'] - 100));
     $self->template->set('medium_self_percentage', abs($m['medium_self_percentage'] - 100));
     $self->template->set('low_self_percentage', abs($m['low_self_percentage'] - 100));
     $self->template->set('title', 'Your Tasks');
     // $this->js('click')->_selector('.do-view-project-details')->univ()->frameURL('Project Details',[$this->api->url('xepan_projects_projectdetail'),'project_id'=>$this->js()->_selectorThis()->closest('[data-id]')->data('id')]);
     $this->js('click')->_selector('.do-view-project-lives-details')->univ()->frameURL('Employee Status', [$this->api->url('xepan_projects_projectlive'), 'project_id' => $this->js()->_selectorThis()->closest('[data-id]')->data('id')]);
     $this->js('click')->_selector('.do-view-project-all-task-lists')->univ()->frameURL('Task/Request List', [$this->api->url('xepan_projects_projecttasklist'), 'project_id' => $this->js()->_selectorThis()->closest('[data-id]')->data('id')]);
     // $this->js('click')->_selector('.do-view-project-calendar')->univ()->frameURL('Project Calendar',[$this->api->url('xepan_projects_calendar'),'project_id'=>$this->js()->_selectorThis()->closest('[data-id]')->data('id')]);
     // $this->js('click')->_selector('.do-view-project-progress')->univ()->frameURL('Project Conversation',[$this->api->url('xepan_projects_progress'),'project_id'=>$this->js()->_selectorThis()->closest('[data-id]')->data('id')]);
     // $this->js('click')->_selector('.do-view-project-conversion')->univ()->frameURL('Project Files',[$this->api->url('xepan_projects_conversation'),'project_id'=>$this->js()->_selectorThis()->closest('[data-id]')->data('id')]);
     return $m;
 }
Example #2
0
 function setModel($m)
 {
     if (!$m instanceof Model_Hosteler) {
         throw $this->exception('Model can be only Hosteler');
     }
     parent::setModel($m);
     $this->information_grid->setModel($m, array('name', 'father_name', 'room_no', 'building_name', 'attendance_status', 'image_url'));
     $m->tryLoadAny();
     if (!$m->loaded()) {
         $this->gaurdian_grid->destroy();
         $this->information_grid->destroy();
         $this->form->destroy();
         return;
     }
     $this->hosteler = $m;
     $this->gaurdian_grid->setModel($m->ref('scholar_id')->ref('Scholars_Guardian'), array('gname', 'address', 'contact', 'relation', 'image_url'));
     $this->form->getElement('hosteler_id')->set($m->id);
     // $map = $this->add('Model_Scholars_Guardian');
     $sel = $this->form->getElement('sel');
     $this->gaurdian_grid->addSelectable($sel);
     //          if($this->form->isSubmitted()){
     // 	$this->form->js()->univ()->successMessage("Student ID" . $this->form->get('hosteler_id'))->execute();
     // 	// $this->handelForm($this->form);
     // }
 }
Example #3
0
 function setModel($m)
 {
     parent::setModel($m);
     $l = $this->api->add('listers/Lister_Tree', null, 'tree');
     $l->setModel($m);
     $l->setRelationFields('id', 'parent_id');
     $l->js(true)->univ()->jstreePlugin();
 }
Example #4
0
File: Tool.php Project: xepan/cms
 function setModel($model, $fields = null)
 {
     $m = parent::setModel($model, $fields);
     if ($this->add_option_helper) {
         $this->add('xepan\\cms\\Controller_Tool_Optionhelper');
     }
     return $m;
 }
Example #5
0
 function setModel($model, $fields = null, $grid_fields = null)
 {
     parent::setModel($model);
     if ($this->form) {
         $m = $this->form->setModel($this->model, $fields);
         $this->form->addSubmit();
     } else {
         $m = $this->grid->setModel($this->model, $grid_fields ? $grid_fields : $fields);
     }
     $this->initComponents();
     return $m;
 }
Example #6
0
 function setModel($model)
 {
     parent::setModel($model);
     $model->tryLoadAny();
     $this->template->trySet('val1', $model['average_receiving_time']);
     $this->template->trySet('val2', $model['average_submission_time']);
     $this->template->trySet('val3', $model['average_reacting_time']);
     $this->template->trySet('val4', 0);
     $this->template->trySet('heading1', 'Average Receiving Time');
     $this->template->trySet('heading2', 'Average Submission Time');
     $this->template->trySet('heading3', 'Average Reacting Time');
     $this->template->trySet('heading4', 'Dummy');
 }
Example #7
0
 function setModel($scholar)
 {
     $student = $scholar->ref('Student');
     $student->addExpression('class_section')->set(function ($m, $q) {
         return $m->refSQL('class_id')->fieldQuery('section');
     })->display('hindi');
     $student->addExpression('className')->set(function ($m, $q) {
         return $m->refSQL('class_id')->fieldQuery('class_name');
     })->display('hindi');
     $this->add('View_Scholar_Details', null, 'details_location')->setModel($student);
     $this->template->tryset('date_of_birth', date('d-m-Y', strtotime($scholar['dob'])));
     $this->template->tryset('admissiondate', date('d-m-Y', strtotime($scholar['admission_date'])));
     parent::setModel($scholar);
 }
 function setModel($model)
 {
     parent::setModel($model);
     if (!$this->model->loaded()) {
         return;
     }
     $f = $this->add('Form');
     foreach ($this->model->ref('RuleOption') as $model) {
         if (preg_match_all("/{[^}]*}/", $model['gMarks'], $tags)) {
             foreach ($tags as $key => $value) {
                 foreach ($value as $key_id => $value_name) {
                     $f->addField($value_name)->validate('required');
                 }
             }
         }
     }
     $f->addSubmit('Go');
     if ($f->isSubmitted()) {
         $m = $this->model;
         $rule = $this->add('Model_Rule');
         foreach ($m->getActualFields() as $field) {
             if (in_array($field, ["id", "is_template"])) {
                 continue;
             }
             $rule[$field] = $m[$field];
         }
         $rule->save();
         foreach ($m->ref('RuleOption') as $rbo) {
             $ro = $this->add('Model_RuleOption');
             $ro['rule_id'] = $rule->id;
             foreach ($rbo->getActualFields() as $field) {
                 if ($field == "id") {
                     continue;
                 }
                 if (preg_match_all("/{[^}]*}/", $rbo['gMarks'], $tags)) {
                     foreach ($tags as $key => $values) {
                         foreach ($values as $key => $value) {
                             $rbo[$field] = str_replace($value, $f[$this->api->normalizeName($value)], $rbo[$field]);
                         }
                     }
                 }
                 $ro[$field] = $rbo[$field];
             }
             $ro->saveAndUnload();
         }
         $this->api->stickyForget('rulebook_id');
         $f->js(null, $this->owner->js()->reload())->univ()->successMessage('ok')->execute();
     }
 }
Example #9
0
 function setModel($m)
 {
     $upsthiti = 0;
     $total_meeting = 0;
     foreach ($m as $junk) {
         $this->template->trySet("total_" . $m['month'], $m['total_attendance']);
         $this->template->trySet("att_" . $m['month'], $m['present']);
         $upsthiti += $m['total_attendance'];
         $total_meeting += $m['present'];
         // echo $month;
     }
     $this->template->trySet("total_meeting", $total_meeting);
     $this->template->trySet("total_att", $upsthiti);
     parent::setModel($m);
 }
Example #10
0
 public function setModel($m)
 {
     $m = parent::setModel($m);
     foreach ($m as $model) {
         // check subitems
         if (@$model->hierarchy_controller && $model[$model->hierarchy_controller->child_ref . '_cnt']) {
             $m = $this->addMenu($model['name']);
             foreach ($model->ref($model->hierarchy_controller->child_ref) as $child) {
                 $m->addItem($child['name'], $child['page']);
             }
         } else {
             $this->addItem($model['name'], $model['page']);
         }
     }
 }
Example #11
0
 public function setModel($m, $options = array())
 {
     $m = parent::setModel($m);
     foreach ($m as $model) {
         // check subitems
         if (@$model->hierarchy_controller && $model[strtolower($model->hierarchy_controller->child_ref) . '_cnt']) {
             $m = $this->addMenu($model[$options['title_field'] ?: $m->title_field]);
             foreach ($model->ref($model->hierarchy_controller->child_ref) as $child) {
                 $m->addItem($options['title_field'] ?: $child[$options['title_field'] ?: $model->title_field], $child['page']);
             }
         } else {
             $this->addItem($model[$options['title_field'] ?: $model->title_field], $model['page']);
         }
     }
     return $m;
 }
Example #12
0
 function setModel($m)
 {
     parent::setModel($m);
     $student = $m->ref('Student')->addCondition('session_id', $this->add('Model_Sessions_Current')->fieldQuery('id'))->tryLoadAny();
     // $student=$this->add('Model_Student');
     $sc = $student->join('scholars_master.id', 'scholar_id');
     $sc->addField('guardian_name');
     $this->template->set('class', $student->ref('class_id')->get('name'));
     $this->template->trySet('roll_no', $student['roll_no']);
     $this->template->trySet('dob1', date('d/m/Y', strtotime($m['dob'])));
     $sch = $student->ref('scholar_id');
     // $g=$sch->ref('Scholars_Guardian')->setOrder('id','desc')->tryLoadAny();
     // if($g['name']==$sch['mother_name'])
     // 	$g->setOrder('name','asc');
     // else
     // 	$g->setOrder('name','desc');
     $this->template->trySet('guardian_name', $student['guardian_name']);
 }
Example #13
0
 function setModel($model)
 {
     $m = parent::setModel($model);
     $to_raw = $m['to_raw'];
     $to_lister = $this->add('CompleteLister', null, 'to_lister', ['view/emails/email-detail', 'to_lister']);
     // var_dump($m['to_raw']);
     // exit;
     $to_lister->setSource($to_raw);
     $cc_raw = $m['cc_raw'];
     $cc_lister = $this->add('CompleteLister', null, 'cc_lister', ['view/emails/email-detail', 'cc_lister']);
     $cc_lister->setSource($cc_raw);
     $this->template->setHTML('email_body', $model['description']);
     $this->template->setHTML('attachment_count', $model['attachment_count']);
     if (!$model['attachment_count']) {
         $this->template->tryDel('check_attach');
     }
     $attach_m = $this->add('xepan\\communication\\Model_Communication_Attachment');
     $attach_m->addCondition('communication_id', $m->id);
     $attach_m->addCondition('type', 'attach');
     $attach = $this->add('xepan\\communication\\View_Lister_Attachment', null, 'Attachments');
     $attach->setModel($attach_m);
     // $(".reply").click(function(){
     //       $('.compose-email-view-popup').show();
     //   });
     //   $("li.reply-all").click(function(){
     //       $('.compose-email-view-popup').show();
     //   });
     //   $("li.forward").click(function(){
     //       $('.compose-email-view-popup').show();
     //   });
     $this->js('click', [$this->js()->show()->_selector('.compose-email-view-popup'), $this->js()->reload()])->_selector('.reply');
     $this->js('click', [$this->js()->show()->_selector('.compose-email-view-popup'), $this->js()->reload()])->_selector('li.reply-all');
     $this->js('click', [$this->js()->show()->_selector('.compose-email-view-popup'), $this->js()->reload()])->_selector('li.forward');
     $this->add('xepan\\base\\Controller_Avatar', ['options' => ['size' => 45, 'border' => ['width' => 0]], 'name_field' => 'communication_with', 'default_value' => '']);
     return $m;
 }
Example #14
0
 function setModel($model, $view_fields = null, $form_fields = null)
 {
     $this->view_fields = $view_fields;
     $this->form_fields = $form_fields;
     if ($this->action == 'view') {
         $fields = $view_fields;
     } else {
         foreach ($this->form_fields as $fld) {
             if ($model->getElement($fld)->system()) {
                 $model->getElement($fld)->system(false)->editable(true);
             }
         }
         $m = $this->form->setModel($model, $this->form_fields);
         $fields = $view_fields ?: $m->getActualFields();
         /* Still NonEditable fields should show as on view mode */
         $readonly_fields = array_diff($fields, $this->form_fields ?: []);
         // remove derefrenced_fields
         $remove_tag = [];
         foreach ($readonly_fields as $key => $rf) {
             if (in_array($rf . '_id', $this->form_fields) && !in_array($rf . '_id', $this->deref_fields_in_form)) {
                 unset($readonly_fields[$key]);
             }
         }
         foreach ($readonly_fields as $fld) {
             @$this->form->layout->template->trySetHTML($fld, $model[$fld]);
         }
     }
     $m = parent::setModel($model, $fields);
     return $m;
 }
Example #15
0
 function setModel($m)
 {
     parent::setModel($m);
     $this->child_ref = $this->model->hierarchy_controller->child_ref;
     return $this->model;
 }
Example #16
0
File: Draw.php Project: rvadym/gmap
 function setModel($model, $actual_fields = undefined)
 {
     parent::setModel($model, $actual_fields);
     $this->l->setModel($model, array('name', 'draw'));
     $this->map->showMap();
 }
Example #17
0
 function setModel($model)
 {
     $m = parent::setModel($model);
     // throw new \Exception($this->reply_view, 1);
     if ($m['to_raw']) {
         $to_lister = $this->add('CompleteLister', null, 'to_lister', ['view/grid/ticketdetail-grid', 'to_lister']);
         $to_lister->setSource($m['to_raw']);
     }
     if ($m['cc_raw']) {
         $cc_lister = $this->add('CompleteLister', null, 'cc_lister', ['view/grid/ticketdetail-grid', 'cc_lister']);
         $cc_lister->setSource($m['cc_raw']);
     }
     $this->template->setHTML('collapse_header', strip_tags(substr($model['message'], 0, 100)) ?: "No Subject");
     $this->template->setHTML('email_body', $model['message']);
     $attach = $this->add('xepan\\communication\\View_Lister_Attachment', null, 'Attachments');
     $attach->setModel('xepan\\communication\\Communication_Attachment')->addCondition('communication_id', $m['communication_id']);
     $m_comment = $this->add('xepan\\crm\\Model_Ticket_Comments');
     $m_comment->addCondition('ticket_id', $this->model->id);
     $ticket_j = $m_comment->join('support_ticket.document_id', 'ticket_id');
     $comment_join = $m_comment->leftJoin('communication.id', 'communication_id');
     $comment_join->addField('status');
     $m_comment->setOrder('created_at', 'desc');
     $comment_view = $this->add('xepan\\crm\\View_Lister_TicketComments', null, 'comment_view');
     $comment_view->setModel($m_comment);
     // $comment_view->add('xepan\base\Controller_Avatar',['name_field'=>'contact','image_field'=>'contact_image','options'=>['size'=>50,'display'=>'block','margin'=>'auto'],'float'=>null,'model'=>$m_comment]);
     // $comment_view->add('xepan\base\Controller_Avatar',['options'=>['size'=>50,'margin'=>0,'border'=>['width'=>0]],'name_field'=>'from','default_value'=>'','image_field','contact_image']);
     $contact = $this->model->ref('contact_id');
     $member_phones = array_reverse($contact->getPhones());
     if ($this->reply_view) {
         $form = $this->add('xepan\\communication\\Form_Communication', null, 'reply_form');
         // $form->setLayout(['form/comment-reply']);
         $form->setContact($contact);
         // $form->getElement('email_to')->set(implode(", ", $ticket_model->ref('contact_id')->getEmails()));
         $emails_to = [];
         foreach ($this->model->getReplyEmailFromTo()['to'] as $flipped) {
             $emails_to[] = $flipped['email'];
         }
         $emails_cc = [];
         foreach ($this->model->getReplyEmailFromTo()['cc'] as $flipped) {
             $emails_cc[] = $flipped['email'];
         }
         $emails_bcc = [];
         foreach ($this->model->getReplyEmailFromTo()['bcc'] as $flipped) {
             $emails_bcc[] = $flipped['email'];
         }
         $form->getElement('email_to')->set(implode(", ", $emails_to));
         $form->getElement('cc_mails')->set(implode(", ", $emails_cc));
         $form->getElement('bcc_mails')->set(implode(", ", $emails_bcc));
         $form->getElement('called_to')->set(array_pop($member_phones));
         $form->getElement('title')->set("Re: Ticket " . $this->model->getToken() . " " . $this->model['subject']);
         $body_field = $form->getElement('body');
         $body_field->options = ['toolbar1' => "styleselect | bold italic fontselect fontsizeselect | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | forecolor backcolor", 'menubar' => false];
         $from_email = $form->getElement('from_email');
         $from_email->getModel()->addcondition('is_support_email', true);
         $from_email->set($this->model->supportEmail()->id);
         $form->addSubmit('Save')->addClass('pull-right btn btn-primary');
         if ($form->isSubmitted()) {
             $comm = $form->process();
             $this->model->createCommentOnly($comm);
             // $js=[];
             // $js[]=$form->js()->reload();
             // $js[]=$comment_lister->js()->reload();
             $js = [$form->js()->reload(), $this->js()->find('.xepan-crm-reply-tool')->toggleClass('xepan-crm-reply-tool-closed'), $comment_view->js()->reload()];
             $form->js(true, $js)->univ()->successMessage('Done')->execute();
         }
         $this->js('click', $this->js()->toggleClass('xepan-crm-reply-tool-closed')->_selector('.xepan-crm-reply-tool'))->_selector('.close-reply-comment-popup');
         // $this->js('click',$this->js()->slideToggle()->_selector('.xepan-crm-reply-tool'))->_selector('.minimize-comment-popup');
     } else {
         $this->template->tryDel('reply_wrapper');
     }
     return $m;
 }
Example #18
0
 function setModel(Model_Contact $contact)
 {
     parent::setModel($contact);
     $this->document_view->setModel($this->model, null, ['first_name', 'last_name', 'address', 'city', 'state_id', 'country_id', 'pin_code', 'organization', 'post', 'website']);
     if ($this->action == 'edit') {
         $this->document_view->form->layout->add('xepan\\base\\Controller_Avatar', ['extra_classes' => 'profile-img center-block', 'options' => ['size' => 200, 'display' => 'block', 'margin' => 'auto'], 'float' => null, 'model' => $this->model]);
     } else {
         $this->document_view->add('xepan\\base\\Controller_Avatar', ['extra_classes' => 'profile-img center-block', 'options' => ['size' => 200, 'display' => 'block', 'margin' => 'auto'], 'float' => null]);
     }
     $country_field = $this->document_view->form->getElement('country_id');
     $state_field = $this->document_view->form->getElement('state_id');
     if ($this->app->stickyGET('country_id')) {
         $state_field->getModel()->addCondition('country_id', $_GET['country_id'])->setOrder('name', 'asc');
     }
     $country_field->js('change', $state_field->js()->reload(null, null, [$this->app->url(null, ['cut_object' => $state_field->name]), 'country_id' => $country_field->js()->val()]));
     if ($this->model->loaded()) {
         $email_m = $this->add('xepan\\base\\Model_Contact_Email');
         $email_m->addCondition('contact_id', $this->model->id);
         if ($this->acl) {
             $email_m->acl = $this->acl;
         }
         $e = $this->document_view->addMany('Emails', null, 'Emails', ['view/addmany']);
         $e->setModel($email_m);
         $g = $e;
         if ($e instanceof \CRUD && !$e->isEditing()) {
             $g = $e->grid;
         }
         if ($g instanceof \Grid) {
             $g->addMethod('format_value', function ($g, $f) {
                 if ($g->model['is_active'] != true) {
                     $g->current_row_html[$f] = "<span style='color:gray'>" . $g->model['value'] . "</span>";
                 }
                 if ($g->model['is_valid'] != true) {
                     $g->current_row_html[$f] = "<span style='color:red'>" . $g->model['value'] . "</span>";
                 }
             });
             $g->addFormatter('value', 'value');
         }
         $e->template->tryDel('Pannel');
         $phone_m = $contact->ref('Phones');
         if ($this->acl) {
             $phone_m->acl = $this->acl;
         }
         $phone = $this->document_view->addMany('Phones', null, 'Phones', ['view/addmany']);
         $phone->setModel($phone_m);
         $phone->template->tryDel('Pannel');
         $ims_m = $contact->ref('IMs');
         if ($this->acl) {
             $ims_m->acl = $this->acl;
         }
         $im = $this->document_view->addMany('IMs', null, 'IMs', ['view/addmany']);
         $im->setModel($ims_m);
         $im->template->tryDel('Pannel');
         $event_m = $contact->ref('Events');
         if ($this->acl) {
             $event_m->acl = $this->acl;
         }
         $event = $this->document_view->addMany('Events', null, 'Events', ['view/addmany']);
         $event->setModel($event_m);
         $event->template->tryDel('Pannel');
         $relation_m = $contact->ref('Relations');
         if ($this->acl) {
             $relation_m->acl = $this->acl;
         }
         $relation = $this->document_view->addMany('Relations', null, 'Relations', ['view/addmany']);
         $relation->setModel($relation_m);
         $relation->template->tryDel('Pannel');
     }
     $contact_emails = implode(',', $this->model->getEmails());
     $this->document_view->js('click')->_selector('.do-contact-email')->univ()->location($this->app->url('xepan_communication_composeemail', ['send_email_contact' => true, 'contact_id' => $this->model->id]));
     return $this->model;
 }
Example #19
0
File: Chart.php Project: xepan/base
 function setModel($model, $x_Axis_field, $y_Axis_fields, $x_Axis_type = 'category')
 {
     $m = parent::setModel($model, array_merge($y_Axis_fields, [$x_Axis_field]));
     $this->x_Axis_field = $x_Axis_field;
     $this->y_Axis_fields = $y_Axis_fields;
     $this->setXAxis($x_Axis_field, $x_Axis_type);
     $this->setYAxises($y_Axis_fields);
     return $this;
     //not returning model
 }
Example #20
0
 /**
  * Assign model to your CRUD and specify list of fields to use from model
  *
  * {@inheritdoc}
  *
  * @param string|object $model       Same as parent
  * @param array         $fields      Specify list of fields for form and grid
  * @param array         $grid_fields Overide list of fields for the grid
  *
  * @return AbstractModel $model
  */
 public function setModel($model, $fields = null, $grid_fields = null)
 {
     $model = parent::setModel($model);
     if ($this->entity_name === null) {
         if ($model->caption === null) {
             // Calculates entity name
             $class = get_class($this->model);
             $class = substr(strrchr($class, '\\') ?: ' ' . $class, 1);
             // strip namespace
             $this->entity_name = str_replace(array('Model_', '_'), array('', ' '), $class);
         } else {
             $this->entity_name = $model->caption;
         }
     }
     if (!$this->isEditing()) {
         $this->configureGrid(is_null($grid_fields) ? $fields : $grid_fields);
     }
     if ($this->allow_add) {
         if ($this->configureAdd($fields)) {
             return $model;
         }
     } elseif (isset($this->add_button)) {
         $this->add_button->destroy();
     }
     if ($this->allow_edit) {
         if ($this->configureEdit($fields)) {
             return $model;
         }
     }
     if ($this->allow_del) {
         $this->configureDel();
     }
     return $model;
 }
 function setModel($m)
 {
     parent::setModel($m);
     $this->addForm($_GET[$this->name] ? $_GET[$this->name] : 1);
 }
Example #22
0
 function setModel($model)
 {
     $default_currency_json_mdl = $this->add('xepan\\base\\Model_ConfigJsonModel', ['fields' => ['currency_id' => 'DropDown'], 'config_key' => 'FIRM_DEFAULT_CURRENCY_ID', 'application' => 'accounts']);
     $default_currency_json_mdl->tryLoadAny();
     $defaultCurrency = $this->recall($this->app->epan->id . '_defaultCurrency', $this->memorize($this->app->epan->id . '_defaultCurrency', $this->add('xepan\\accounts\\Model_Currency')->tryLoadBy('id', $default_currency_json_mdl['currency_id'])));
     $form = $this->form;
     $custom_fields = $model->activeAssociateCustomField();
     $custom_fields->setOrder('order', 'asc');
     $groups = [];
     //price section added
     $fieldset = $groups[$this->options['amount_group_in_multistepform']];
     if ($this->options['amount_group_in_multistepform'] && !isset($fieldset)) {
         $fieldset = $groups[$this->options['amount_group_in_multistepform']] = $form->add('HtmlElement')->setElement('fieldset');
         $fieldset->add('HtmlElement')->setElement('legend')->set($this->options['amount_group_in_multistepform']);
         $price_view = $fieldset->add('View', null, null, ['view/tool/addtocartbutton', 'amount_section']);
         $this->template->tryDel('amount_section');
     } else {
         $this->template->tryDel('amount_section');
     }
     //Populating custom fields
     // $price_added = 0;
     $count = 1;
     foreach ($custom_fields as $custom_field) {
         if (!isset($groups[$custom_field['group']])) {
             $fieldset = $groups[$custom_field['group']] = $form->add('HtmlElement')->setElement('fieldset');
             $fieldset->add('HtmlElement')->setElement('legend')->set($custom_field['group']);
         }
         $fieldset = $groups[$custom_field['group']];
         if (strtolower($custom_field['display_type']) === "dropdown") {
             $field = $fieldset->addField('xepan\\commerce\\DropDown', "f_" . $count, $custom_field['name']);
             $field->setModel($this->add('xepan\\commerce\\Model_Item_CustomField_Value', ['id_field' => 'name', 'title_field' => 'name'])->addCondition('customfield_association_id', $custom_field->id));
             $field->setEmptyText("Please Select");
             $field->addClass("required");
         } else {
             if (strtolower($custom_field['display_type']) === 'color') {
                 $field = $fieldset->addField('xepan\\commerce\\DropDown', "f_" . $count, $custom_field['name']);
                 $field->setModel($this->add('xepan\\commerce\\Model_Item_CustomField_Value', ['id_field' => 'name'])->addCondition('customfield_association_id', $custom_field->id));
             } else {
                 if (strtolower($custom_field['display_type']) === "line") {
                     $field = $fieldset->addField('Line', "f_" . $count, $custom_field['name']);
                 }
             }
         }
         $count++;
     }
     // add Quantity Set in respective group
     $fieldset = $groups[$model['quantity_group']];
     if (!isset($fieldset)) {
         // $fieldset = $form;
         $fieldset = $form->add('HtmlElement')->setElement('fieldset');
         $fieldset->add('HtmlElement')->setElement('legend')->set($model['quantity_group']);
     }
     if ($model['qty_from_set_only']) {
         $qty_set_model = $this->add('xepan\\commerce\\Model_Item_Quantity_Set', ['id_field' => 'qty']);
         $qty_set_model->addCondition('item_id', $model->id);
         $qty_set_model->setOrder('qty', 'asc');
         $qty_set_model->_dsql()->group('name');
         $field_qty = $fieldset->addField('xepan\\commerce\\DropDown', 'qty');
         $field_qty->setModel($qty_set_model);
     } else {
         $field_qty = $fieldset->addField('Number', 'qty')->set(1);
     }
     $field_qty->validate('required');
     // add File Upload into respective groups
     if ($model['is_allowuploadable'] and $model['upload_file_label']) {
         $images_count = 0;
         $upload_array = explode(',', $model['upload_file_label']);
         $images_count = count($upload_array);
         if (!$images_count) {
             return;
         }
         // file upload hint
         $fieldset = $groups[$model['upload_file_group']];
         if (!isset($fieldset)) {
             $fieldset = $form->add('HtmlElement')->setElement('fieldset');
             $fieldset->add('HtmlElement')->setElement('legend')->set($model['upload_file_group']);
         }
         $fieldset->add('View')->setHtml($model['item_specific_upload_hint']);
         foreach ($upload_array as $field_label) {
             $field_mandatory = explode(":", $field_label);
             $field_label = $field_mandatory[0];
             $field_name = $this->app->normalizeName($field_label);
             $multi_upload_field = $fieldset->addField('xepan\\base\\Upload', $field_name, $field_label)->allowMultiple(1)->setFormatFilesTemplate('view/tool/xepan_commerce_file_upload');
             // $multi_upload_field->setAttr('accept','.jpeg,.png,.jpg');
             $file_model = $this->add('xepan\\filestore\\Model_Image', ['policy_add_new_type' => true]);
             $multi_upload_field->setModel($file_model);
             $multi_upload_field->addClass('required');
             // $multi_upload_field->template->set('after_field','Max size: 500k');
         }
     }
     //submit button
     $getprice_btn = $form->addSubmit('get price')->addStyle('display', 'none')->addClass('btn-block btn btn-primary');
     $addtocart_btn = $form->addSubmit($this->options['button_name'] ?: 'Add To Cart')->addClass('btn-block btn btn-primary');
     if (!$this->options['show_addtocart_button']) {
         $addtocart_btn->addStyle('display', 'none');
     }
     //change event handeling
     $form->on('change', 'select, input:not([type="file"])', $getprice_btn->js()->click());
     // $fields_qty->js('change',$getprice_btn->js(true)->trigger('click'));
     // $field_qty->js('change',$form->js()->submit());
     // Show modal popup
     $popup = $this->app->add('xepan\\base\\View_ModelPopup', ['addSaveButton' => false]);
     $popup->addClass('xepan-commerce-itemadded-popup');
     $popup->add('View')->setHtml('<div class="alert alert-succesrsubs">' . ($this->options['success_message'] ?: "Added to cart successfully") . '</div>');
     $continue_shopping_btn = $popup->add('Button', null, "footer")->set("Continue Shopping")->addClass(' btn btn-primary atk-button');
     $checkout_btn = $popup->add('Button', null, "footer")->set("Checkout")->addClass(' btn btn-primary atk-button');
     $continue_shopping_btn->js('click', $this->js()->univ()->redirect($this->app->url($this->options['continue_shopping_page'])));
     $checkout_btn->js('click', $this->js()->univ()->redirect($this->app->url($this->options['checkout_page'])));
     if ($form->isSubmitted()) {
         //get price according to selected custom field
         // $custom_field_array = [];
         $department_custom_field = [];
         $count = 1;
         foreach ($custom_fields as $custom_field) {
             // $custom_field_array[$custom_field['name']] = $form[$count];
             $department_id = $custom_field['department_id'] ?: 0;
             if (!isset($department_custom_field[$department_id])) {
                 $department_custom_field[$department_id] = ['department_name' => $custom_field['department']];
             }
             if (!isset($department_custom_field[$department_id][$custom_field['customfield_generic_id']])) {
                 $value_id = $this->add('xepan\\commerce\\Model_Item_CustomField_Value')->addCondition('customfield_association_id', $custom_field->id)->addCondition('name', $form["f_" . $count])->tryLoadAny()->id;
                 $temp = ["custom_field_name" => $custom_field['name'], "custom_field_value_id" => $value_id ? $value_id : $form["f_" . $count], "custom_field_value_name" => $form["f_" . $count]];
                 $department_custom_field[$department_id][$custom_field['customfield_generic_id']] = $temp;
             }
             $count++;
         }
         //populate price according to selected customfield
         $price_array = $model->getAmount($department_custom_field, $form['qty']);
         //
         if ($form->isClicked($addtocart_btn)) {
             $count = 1;
             foreach ($custom_fields as $custom_field) {
                 // echo "id = ".$custom_field['id']." optional = ".$custom_field['is_optional']." foem value = ".$form["f_".$count];
                 $field_name = "f_" . $count;
                 if (!$custom_field['is_optional']) {
                     if (!$form[$field_name]) {
                         $form->error($field_name, $custom_field['name'] . " is a mandatory " . $custom_field['is_optional']);
                         break;
                     }
                 }
                 $count++;
             }
             if (!$this->item_member_design) {
                 $this->item_member_design = 0;
             }
             //selected custom field options array
             $other_fields = null;
             $file_upload_id = 0;
             // Custom Field Uploaded Image management
             $upload_images_array = [];
             if (isset($upload_array)) {
                 foreach ($upload_array as $field_label) {
                     $field_mandatory = explode(":", $field_label);
                     $field_label = $field_mandatory[0];
                     $field_name = $this->app->normalizeName($field_label);
                     if (isset($field_mandatory[1]) && $field_mandatory[1] == 'mandatory' && !$form[$field_name]) {
                         $form->error($field_name, 'mandatory');
                     }
                     $upload_images_array[] = $form[$field_name];
                 }
             }
             $cart = $this->add('xepan\\commerce\\Model_Cart');
             if ($_GET['edit_cartitem_id']) {
                 $cart->deleteItem($_GET['edit_cartitem_id']);
             }
             $cart->addItem($model->id, $form['qty'], $this->item_member_design, $department_custom_field, $upload_images_array);
             $modal_title = 'Added to your cart : ' . $model['name'] . " with Quantity : " . $form['qty'];
             $js = [$form->js()->_selector('.xepan-commerce-tool-cart')->trigger('reload'), $form->js()->_selector("#" . $popup->name)->find('.modal-title')->text($modal_title), $form->js()->_selector("#" . $popup->name)->modal()];
             // add text after model popup render so used jquery here
             $form->js(true, $js)->execute();
             // $form->js(null,$js)->univ()->successMessage('Added into your cart ')->execute();
             // $form->js(null,$js)->execute();
         } else {
             //shipping price added on item amount if option setted from item list options
             if ($this->options['show_shipping_charge'] and $this->options['shipping_charge_with_item_amount']) {
                 $price_array['sale_amount'] = $price_array['sale_amount'] + $price_array['shipping_charge'];
                 $price_array['original_amount'] = $price_array['original_amount'] + $price_array['shipping_charge'];
             }
             $sale = $price_array['sale_amount'];
             $original = $price_array['original_amount'];
             $shipping = $price_array['shipping_charge'];
             if ($this->options['show_price']) {
                 $sale = $price_array['raw_sale_price'];
                 $original = $price_array['raw_original_price'];
             }
             // $unit = "";
             // if($model['qty_unit']){
             // 	if($this->options['show_price'])
             // 		$unit .= "per ";
             // 	else
             // 		$unit .= $form['qty'];
             // 	$unit .= " ".$model['qty_unit'];
             // }
             if ($defaultCurrency['icon']) {
                 $currency_icon = '<i class="' . $defaultCurrency['icon'] . '"></i>';
             } else {
                 $currency_icon = '<i>' . $defaultCurrency['name'] . '</i>';
             }
             // ." ".(($unit)?$unit:"")
             $sale = $sale . " " . $currency_icon;
             $original = $original . " " . $currency_icon;
             $js = [$form->js()->closest('.xshop-item')->find('.xepan-commerce-tool-item-sale-price')->html($sale), $form->js()->closest('.xshop-item')->find('.xepan-commerce-tool-item-shipping-charge')->html($shipping), $form->js()->_selector('.xepan-commerce-item-image')->reload(['commerce_item_id' => $model->id], null, [$this->app->url(null, ['custom_field' => json_encode($department_custom_field)]), 'cut_object' => $this->js()->_selector('.xepan-commerce-item-image')->attr('id')])];
             // throw new \Exception($this->options['show_original_price']);
             if ($this->options['show_original_price']) {
                 $js[] = $form->js()->closest('.xshop-item')->find('.xepan-commerce-tool-item-original-price')->html($original);
             } else {
                 $js[] = $form->js()->closest('.xshop-item')->find('.xepan-commerce-tool-item-original-price')->hide();
             }
             $form->js(null, $js)->execute();
         }
     }
     if (count($groups) > 1 or $this->options['show_multi_step_form']) {
         $this->js(true)->find('form')->_load('tool/formToWizard')->formToWizard(array("submitButton" => $addtocart_btn->js(true)->attr('id')));
     } else {
         $this->js(true)->find('form legend')->hide();
     }
     return parent::setModel($model);
 }