Ejemplo n.º 1
0
 public function generateResponse()
 {
     $article = new objects_Article();
     switch ($this->params['action']) {
         case 'add_article':
             $response = $article->save($this->params);
             if ($response['result'] === TRUE) {
                 $this->returnArray['messages']['success'][] = 'Товар был успешно добавлен.';
                 $this->addReturnParameters();
             } else {
                 $this->returnArray['messages']['danger'][] = $response['error'];
             }
             break;
         case 'edit_article':
             $response = $article->save($this->params, $this->params['id']);
             if ($response['result'] === TRUE) {
                 $this->returnArray['messages']['success'][] = 'Товар был успешно изменен.';
                 $this->addReturnParameters();
             } else {
                 $this->returnArray['messages']['danger'][] = $response['error'];
             }
             break;
         case 'delete_article':
             $response = $article->delete($this->params['id']);
             if ($response['result'] === TRUE) {
                 $this->returnArray['messages']['success'][] = 'Товар был успешно удален.';
                 $this->addReturnParameters();
             } else {
                 $this->returnArray['messages']['danger'][] = $response['error'];
             }
             break;
         case 'generate_form':
             $this->returnArray = $this->generateArticleForm();
             break;
         default:
             break;
     }
     return $this->returnArray;
 }
Ejemplo n.º 2
0
 public function generateDealForm()
 {
     $id = 0;
     $article_id = 0;
     $customer_id = 0;
     $amount = 0;
     $total_price = 0.0;
     $platform_name = '';
     $commented = FALSE;
     $extras = '';
     $status = 1;
     $action = 'add_deal';
     // If an existing id was passed then we need to edit an object.
     if (array_key_exists('id', $this->params) === TRUE && (int) $this->params['id'] > 0) {
         $id = (int) $this->params['id'];
         $action = 'edit_deal';
     }
     if (array_key_exists('row_data', $this->params) === TRUE) {
         if (array_key_exists('customer_id', $this->params['row_data']) === TRUE) {
             $customer_id = $this->params['row_data']['customer_id'];
         }
         if (array_key_exists('article_id', $this->params['row_data']) === TRUE) {
             $article_id = $this->params['row_data']['article_id'];
         }
         if (array_key_exists('amount', $this->params['row_data']) === TRUE) {
             $amount = $this->params['row_data']['amount'];
         }
         if (array_key_exists('total_price', $this->params['row_data']) === TRUE) {
             $total_price = $this->params['row_data']['total_price'];
         }
         if (array_key_exists('platform_name', $this->params['row_data']) === TRUE) {
             $platform_name = $this->params['row_data']['platform_name'];
         }
         if (array_key_exists('commented', $this->params['row_data']) === TRUE) {
             // If there is a success word in the span .
             if (strpos($this->params['row_data']['commented'], 'success') !== FALSE) {
                 $commented = TRUE;
             } else {
                 $commented = FALSE;
             }
         }
         if (array_key_exists('extras', $this->params['row_data']) === TRUE) {
             $extras = $this->params['row_data']['extras'];
         }
         if (array_key_exists('status', $this->params['row_data']) === TRUE) {
             // If there is a success word in the span .
             if (strpos($this->params['row_data']['status'], 'success') !== FALSE) {
                 $status = 2;
             } else {
                 if (strpos($this->params['row_data']['status'], 'warning') !== FALSE) {
                     $status = 1;
                 } else {
                     $status = 0;
                 }
             }
         }
     }
     $options = array();
     $options['id'] = 'add_button';
     $options['css_class'] = 'btn btn-default btn-add';
     $options['onclick'] = 'addDeal()';
     $options['content'] = 'Сохранить';
     $button = new html_elements_Button($options);
     $buttonHTML = '';
     $buttonHTML = $button->generateButtonHTML();
     $customer = new objects_Customer();
     $customersSelectFieldArray = $customer->getSelectFieldArray();
     if ($customersSelectFieldArray['result'] === FALSE) {
         $response['messages']['danger'] = $customersSelectFieldArray['error'];
         return $response;
     }
     $selectField = new html_elements_SelectField('input_customer_id', 'input_customer_id', 'form-control', $customer_id);
     $customersHTML = $selectField->generateHTML($customersSelectFieldArray['result']);
     $article = new objects_Article();
     $articlesSelectFieldArray = $article->getSelectFieldArray();
     if ($articlesSelectFieldArray['result'] === FALSE) {
         $response['messages']['danger'] = $articlesSelectFieldArray['error'];
         return $response;
     }
     $selectField = new html_elements_SelectField('input_article_id', 'input_article_id', 'form-control', $article_id);
     $articlesHTML = $selectField->generateHTML($articlesSelectFieldArray['result']);
     $checkbox = new html_elements_Checkbox('input_commented', 'input_commented', 'form-control', $commented);
     $commentedHTML = $checkbox->generateCheckboxHTML();
     $statusSelectFieldArray = array();
     $statusSelectFieldArray[] = array('id' => '0', 'sf_option' => 'Сделка не состоялась');
     $statusSelectFieldArray[] = array('id' => '1', 'sf_option' => 'В работе');
     $statusSelectFieldArray[] = array('id' => '2', 'sf_option' => 'Прошла успешно');
     $selectField = new html_elements_SelectField('input_status', 'input_status', 'form-control', $status);
     $statusHTML = $selectField->generateHTML($statusSelectFieldArray);
     $string = '
         <form class="form-horizontal" method="post" action="ajax.php">
             <div class="form-group">
                 <label for="input_customer_id" class="col-sm-2 control-label">Покупатель</label>
                 <div class="col-sm-6">' . $customersHTML . '</div>
             </div>
             <div class="form-group">
                 <label for="input_article_id" class="col-sm-2 control-label">Товар</label>
                 <div class="col-sm-6">' . $articlesHTML . '</div>
             </div>                        
             <div class="form-group">
                 <label for="input_amount" class="col-sm-2 control-label">Количество, шт.</label>
                 <div class="col-sm-6">
                     <input type="number" class="form-control" id="input_amount" name="input_amount" placeholder="Количество, шт." value=\'' . $amount . '\'>
                 </div>
             </div>
             <div class="form-group">
                 <label for="input_total_price" class="col-sm-2 control-label">Сумма</label>
                 <div class="col-sm-6">
                     <input type="number" class="form-control" id="input_total_price" name="input_total_price" placeholder="Сумма" value=\'' . $total_price . '\'>
                 </div>
             </div>
             <div class="form-group">
                 <label for="input_platform_name" class="col-sm-2 control-label">Платформа</label>
                 <div class="col-sm-6">
                     <input type="text" class="form-control" id="input_platform_name" name="input_platform_name" placeholder="Платформа" value=\'' . $platform_name . '\'>
                 </div>
             </div>
             <div class="form-group">
                 <label for="input_commented" class="col-sm-2 control-label">Отзыв</label>
                 <div class="col-sm-6">
                     ' . $commentedHTML . '
                 </div>
             </div>
             <div class="form-group">
                 <label for="input_extras" class="col-sm-2 control-label">Доп. информация</label>
                 <div class="col-sm-6">
                     <input type="text" class="form-control" id="input_extras" name="input_extras" placeholder="Доп. информация" value=\'' . $extras . '\'>
                 </div>
             </div>
             <div class="form-group">
                 <label for="input_status" class="col-sm-2 control-label">Статус</label>
                 <div class="col-sm-6">' . $statusHTML . '</div>
             </div>
             <div class="form-group">
                 <div class="col-sm-offset-2 col-sm-10">
                     ' . $buttonHTML . '
                 </div>
             </div>
         </form>';
     $script = '
             function addDeal() {
                 var customer_id = $(\'#input_customer_id\').val();
                 var article_id = $(\'#input_article_id\').val();
                 var amount = $(\'#input_amount\').val();
                 var total_price = $(\'#input_total_price\').val();
                 var platform_name = $(\'#input_platform_name\').val();
                 
                 if ($(\'#input_commented\').is(\':checked\')) {
                     var commented = 1;
                 } else {
                     var commented = 0;
                 }
                 
                 var status = $(\'#input_status\').val();
                 var extras = $(\'#input_extras\').val();
                 ajax_request(
                     {
                         "id": \'' . $id . '\',
                         "class_name": "ajax_accounting_AjaxDeal",
                         "action": \'' . $action . '\',
                         "customer_id": customer_id,
                         "article_id": article_id,
                         "amount": amount,
                         "total_price": total_price,
                         "platform_name": platform_name,
                         "commented": commented,
                         "status": status,
                         "extras": extras
                     }
                 );
 
             }';
     $response[0]['id'] = 'extra_content';
     $response[0]['html'] = $string;
     $response['script'] = $script;
     return $response;
 }