<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<script>
var currencies = <?php echo json_encode($currencies); ?>;
var doc_type = 'invoice';
var settings = <?= json_encode($settings); ?>;
var invoice_settings = <?= json_encode($invoice_settings); ?>;
var doc_rates = {};
</script>
<div class="panel_s<?php if (!isset($proforma) || (isset($proforma) && count($proformas_to_merge) == 0 && (isset($proforma) && !isset($proforma_from_project) && count($expenses_to_bill) == 0 || $proforma->status == proformas_model::STATUS_CANCELLED))) {
			echo ' hide';
		} ?>" id="proforma_top_info">
		<div class="panel-body">
      <div class="row">
         <div id="merge" class="col-md-6">
            <?php
              if(isset($proforma)){
                 $this->load->view('admin/proformas/merge_proforma', array('proformas_to_merge'=>$proformas_to_merge));
              }
            ?>
         </div>
         <!--  When invoicing from project area the expenses are not visible here because you can select to bill expenses while trying to invoice project -->
				 <?php if (!isset($proforma_from_project)) { ?>
	         <div id="expenses_to_bill" class="col-md-6">
	 					<?php if (isset($proforma) && $proforma->status != proformas_model::STATUS_CANCELLED) {
	 						$this->load->view('admin/proformas/bill_expenses', ['expenses_to_bill' => $expenses_to_bill]);
	 					} ?>
	         </div>
	 			<?php } ?>
      </div>
   </div>
</div>








<div class="panel_s invoice accounting-template">
   <div class="additional"></div>
   <div class="panel-body">
		 <?php if (isset($proforma)) { ?>
			 <?php echo format_proforma_status($proforma->status); ?>
			 <hr class="hr-panel-heading" />
		 <?php } ?>
		 <?php hooks()->do_action('before_render_proforma_template'); ?>
		 <?php if (isset($proforma)) {
			 echo form_hidden('merge_current_proforma', $proforma->id);
		 } ?>
      <div class="row">
         <div class="col-md-4">
            <div class="f_client_id">
              <div class="form-group select-placeholder">
                <label for="clientid" class="control-label"><?php echo _l('proforma_select_customer'); ?></label>
                <select id="clientid" name="clientid" data-live-search="true" data-width="100%" class="ajax-search<?php if(isset($proforma) && empty($proforma->clientid)){echo ' customer-removed';} ?>" data-none-selected-text="<?php echo _l('dropdown_non_selected_tex'); ?>">
               <?php $selected = (isset($proforma) ? $proforma->clientid : '');
                 if($selected == ''){
                   $selected = (isset($customer_id) ? $customer_id: '');
                 }
                 if($selected != ''){
                    $rel_data = get_relation_data('customer',$selected);
                    $rel_val = get_relation_values($rel_data,'customer');
                    echo '<option value="'.$rel_val['id'].'" selected>'.$rel_val['name'].'</option>';
                 } ?>
                </select>
              </div>
            </div>

            <div class="row m0">
               <div class="col-md-12 p2">
               <hr class="hr-10" />
                  <a href="#" class="edit_shipping_billing_info" data-toggle="modal" data-target="#billing_and_shipping_details"><i class="fal fa-pencil-square-o"></i></a>
									<?php include_once(APPPATH . 'views/admin/proformas/billing_and_shipping_template.php'); ?>
               </div>
               <div class="col-md-6  p2">
                  <p class="bold"><?php echo _l('proforma_bill_to'); ?></p>
						<address>
                     <span class="billing_street">
                     <?php $billing_street = (isset($proforma) ? $proforma->billing_street : '--'); ?>
                     <?php $billing_street = ($billing_street == '' ? '--' : $billing_street); ?>
                     <?php echo $billing_street; ?></span><br>
			            <span class="billing_city">
                     <?php $billing_city = (isset($proforma) ? $proforma->billing_city : '--'); ?>
                     <?php $billing_city = ($billing_city == '' ? '--' : $billing_city); ?>
                     <?php echo $billing_city; ?></span>,
			            <span class="billing_state">
			            <?php $billing_state = (isset($proforma) ? get_state_name($proforma->billing_state) : '--'); ?>
                     <?php $billing_state = ($billing_state == '' ? '--' : $billing_state); ?>
                     <?php echo $billing_state; ?></span>
			            <br />
			            <span class="billing_country">
                     <?php $billing_country = (isset($proforma) ? get_country_short_name($proforma->billing_country) : '--'); ?>
                     <?php $billing_country = ($billing_country == '' ? '--' : $billing_country); ?>
                     <?php echo $billing_country; ?></span>,
			            <span class="billing_zip">
                     <?php $billing_zip = (isset($proforma) ? $proforma->billing_zip : '--'); ?>
                     <?php $billing_zip = ($billing_zip == '' ? '--' : $billing_zip); ?>
                     <?php echo $billing_zip; ?></span>
			         </address>
               </div>
               <div class="col-md-6 p2">
                  <p class="bold"><?php echo _l('ship_to'); ?></p>
							<address>
                        <span class="shipping_street">
                        <?php $shipping_street = (isset($proforma) ? $proforma->shipping_street : '--'); ?>
                        <?php $shipping_street = ($shipping_street == '' ? '--' : $shipping_street); ?>
                        <?php echo $shipping_street; ?></span><br>
			              <span class="shipping_city">
                        <?php $shipping_city = (isset($proforma) ? $proforma->shipping_city : '--'); ?>
                        <?php $shipping_city = ($shipping_city == '' ? '--' : $shipping_city); ?>
                        <?php echo $shipping_city; ?></span>,
			              <span class="shipping_state">
                        <?php $shipping_state = (isset($proforma) ? get_state_name($proforma->shipping_state) : '--'); ?>
                        <?php $shipping_state = ($shipping_state == '' ? '--' : $shipping_state); ?>
                        <?php echo $shipping_state; ?></span>
			              <br />
			              <span class="shipping_country">
                        <?php $shipping_country = (isset($proforma) ? get_country_short_name($proforma->shipping_country) : '--'); ?>
                        <?php $shipping_country = ($shipping_country == '' ? '--' : $shipping_country); ?>
                        <?php echo $shipping_country; ?></span>,
			               <span class="shipping_zip">
                        <?php $shipping_zip = (isset($proforma) ? $proforma->shipping_zip : '--'); ?>
                        <?php $shipping_zip = ($shipping_zip == '' ? '--' : $shipping_zip); ?>
                        <?php echo $shipping_zip; ?></span>
			            </address>
                  </div>
               </div>


         </div>
         <div class="col-md-4">
            <div class="">
               <div class="">
                  <?php $value = (isset($proforma) ? _d($proforma->date) : _d(date('Y-m-d')));
                  $date_attrs = array();
                  if(isset($proforma) && $proforma->recurring > 0 && $proforma->last_recurring_date != null) {
                    $date_attrs['disabled'] = true;
                  }
                  $date_attrs['readonly'] = true;
                  $date_attrs['data-date-end-date'] = "+1d";
                  ?>
                  <?php echo render_date_input('date','proforma_add_edit_date',$value,$date_attrs); ?>

               </div>
               <div class="">
                  <?php
                  $value = '';
                  if(isset($proforma)){
                    $value = _d($proforma->duedate);
                  } else {
                    if(get_option('proforma_due_after') != 0){
                        $value = _d(date('Y-m-d', strtotime('+' . get_option('proforma_due_after') . ' DAY', strtotime(date('Y-m-d')))));
                    }
                  }
                   ?>
                  <?php echo render_date_input('duedate','proforma_add_edit_duedate',$value); ?>
               </div>
               <div class="">
                  <!--inv num-->
                  <?php
                  $this->load->model('proformas_model');
                  $series = $this->proformas_model->get_series();
                  $default = $this->proformas_model->get_seria();

                  $nextnum = 1;
                  if($default){
                    $nextnum = ((int)$default['current_number']+1);
                  }

                  $next_proforma_number = get_option('next_proforma_number');
                  $format = get_option('proforma_number_format');

                  if(isset($proforma)){
                     $format = $proforma->number_format;
                  }

                  $prefix = get_option('proforma_prefix');

                  if ($format == 1) {
                    $__number = $next_proforma_number;
                    if(isset($proforma)){
                      $__number = $proforma->number;
                      $prefix = '<span id="prefix">' . $proforma->prefix . '</span>';
                    }
                  } else if($format == 2) {
                    if(isset($proforma)){
                      $__number = $proforma->number;
                      $prefix = $proforma->prefix;
                      $prefix = '<span id="prefix">'. $prefix . '</span><span id="prefix_year">' .date('Y',strtotime($proforma->date)).'</span>/';
                    } else {
                     $__number = $next_proforma_number;
                     $prefix = $prefix.'<span id="prefix_year">'.date('Y').'</span>/';
                   }
                  } else if($format == 3) {
                     if(isset($proforma)){
                      $yy = date('y',strtotime($proforma->date));
                      $__number = $proforma->number;
                      $prefix = '<span id="prefix">'. $proforma->prefix . '</span>';
                    } else {
                     $yy = date('y');
                     $__number = $next_proforma_number;
                   }
                  } else if($format == 4) {
                     if(isset($proforma)){
                      $yyyy = date('Y',strtotime($proforma->date));
                      $mm = date('m',strtotime($proforma->date));
                      $__number = $proforma->number;
                      $prefix = '<span id="prefix">'. $proforma->prefix . '</span>';
                    } else {
                     $yyyy = date('Y');
                     $mm = date('m');
                     $__number = $next_proforma_number;
                   }
                  }

                  $_is_draft = (isset($proforma) && $proforma->status == Invoices_model::STATUS_DRAFT) ? true : false;
                  $_proforma_number = str_pad($__number, get_option('number_padding_prefixes'), '0', STR_PAD_LEFT);
                  $isedit = isset($proforma) ? 'true' : 'false';
                  $data_original_number = isset($proforma) ? $proforma->number : 'false';

          if(isset($proforma)){
            $this->load->model('proformas_model');
                $series = $this->proformas_model->get_series();
                $default = $this->proformas_model->get_seria();
                $nextnum = 1;
                if($default){
                  $nextnum = ((int)$default['current_number']+1);
                }


                /*if(!empty($series)){
                  echo '<select name="s_prefix" id="select_seria" class="form-control" style="height: 30px !important; flex: 1;">';
                  foreach ($series as $key => $value) { ?>
                      <option value="<?= $value['name'] ?>" <?= $value['default'] == '1'?"selected":""; ?>>
                        <?= strtoupper($value['name']).' '.((int)$data_original_number); ?>
                      </option>
                  <?php }
                  echo '</select>';
                }*/
              ?>
              <div class="form-group">
                <label for="number">
                   <?php echo _l('proforma_add_edit_number'); ?>
                   <i class="fal fa-question-circle" data-toggle="tooltip" data-title="<?php echo _l('proforma_number_not_applied_on_draft') ?>" data-placement="top"></i>
                </label>
                 <div class="input-group">
                    <span class="input-group-addon"><?= $proforma->prefix; ?></span>
                    <input type="text" name="number" class="form-control" value="<?php echo ($_is_draft) ? 'DRAFT' : format_proforma_number($proforma->id,true); ?>" disabled="">
                  </div>
              </div>

              <?php /*<input type="text" name="number" class="form-control"
              value="<?php echo ($_is_draft) ? 'DRAFT' : $proforma->prefix.' '.$data_original_number; ?>" readonly data-isedit="<?php echo $isedit; ?>"
              data-original-number="<?php echo $data_original_number; ?>" <?php echo ($_is_draft) ? 'disabled' : 'disabled' ?> style="height: 30px !important; flex: 1;"> */ ?>
            <?php

              /* ?>
            <div class="form-group">
               <label for="number">
                  <?php echo _l('proforma_add_edit_number'); ?>
                  <i class="fal fa-question-circle" data-toggle="tooltip" data-title="<?php echo _l('proforma_number_not_applied_on_draft') ?>" data-placement="top"></i>
               </label>
               <div class="input-group">
                  <span class="input-group-addon">
                  <?php if(isset($proforma)){ /* ?>
                    <a href="#" onclick="return false;" data-toggle="popover" data-container='._transaction_form' data-html="true" data-content="<label class='control-label'><?php echo _l('settings_sales_proforma_prefix'); ?></label><div class='input-group'><input name='s_prefix' type='text' class='form-control' value='<?php echo $proforma->prefix; ?>'></div><button type='button' onclick='save_sales_number_settings(this); return false;' data-url='<?php echo admin_url('proformas/update_number_settings/'.$proforma->id); ?>' class='btn btn-info btn-block mtop15'><?php echo _l('submit'); ?></button>">
                    <i class="fal fa-cog"></i>
                    </a>
                  <?php * / }
                    echo strtoupper($proforma->prefix);
                  ?>
                  </span>
                  <?php / *
                  <input type="text" name="number" class="form-control" value="<?php echo ($_is_draft) ? 'DRAFT' : $_proforma_number; ?>" data-isedit="<?php echo $isedit; ?>" data-original-number="<?php echo $data_original_number; ?>" <?php echo ($_is_draft) ? 'disabled' : 'disabled' ?>>
                  * / ?>
                  <input type="text" name="number" class="form-control" value="<?php echo ($_is_draft) ? $_proforma_number : $_proforma_number; ?>" data-isedit="<?php echo $isedit; ?>" data-original-number="<?php echo $data_original_number; ?>" <?php echo ($_is_draft) ? 'disabled' : 'disabled' ?>>

                  <?php if($format == 3) { ?>
                  <span class="input-group-addon">
                     <span id="prefix_year" class="format-n-yy"><?php echo $yy; ?></span>
                  </span>
                  <?php } else if($format == 4) { ?>
                   <span class="input-group-addon">
                     <span id="prefix_month" class="format-mm-yyyy"><?php echo $mm; ?></span>
                     /
                     <span id="prefix_year" class="format-mm-yyyy"><?php echo $yyyy; ?></span>
                  </span>
                  <?php } ?>
               </div>
            </div>
            */ ?>

            <?php }
            else{

              $this->load->model('proformas_model');
                  $series = $this->proformas_model->get_series();
                  $default = $this->proformas_model->get_seria();
                  $nextnum = 1;
                  if($default){
                    $nextnum = ((int)$default['current_number']+1);
                  }

                  ?>
                  <label for="number" class="d-block">
                     <?php echo _l('proforma_add_edit_number'); ?>
                  </label>
                  <?php


                  echo '<div style=" display: flex; justify-content: center; flex-wrap: wrap; align-content: space-between; width: 100%; ">';

                  if(!empty($series)){
                    echo '<select name="s_prefix" id="select_seria" class="form-control" style="height: 30px !important; flex: 1;">';
                    foreach ($series as $key => $value) { ?>
                        <option value="<?= $value['name'] ?>" <?= $value['default'] == '1'?"selected":""; ?>>
                          <?= strtoupper($value['name']).''. sales_number_format(((int)$value['current_number']+1), 1, null, null); ?>
                        </option>
                    <?php }
                    echo '</select>';
                  }
                ?>

                <input type="hidden" name="number" class="form-control"
                value="<?php echo ($_is_draft) ? 'DRAFT' : $nextnum; ?>" data-isedit="<?php echo $isedit; ?>"
                data-original-number="<?php echo $data_original_number; ?>" <?php echo ($_is_draft) ? 'disabled' : 'disabled' ?> style="height: 30px !important; flex: 1;">
              </div>
              <?php
            }
               ?>

                  <!--@end inv num-->
               </div>
            </div>
         </div>
         <div class="col-md-4">
            <div class="row m0">
               <div class="col-md-12 p2">
            <!--currency-->
            <?php
               $currency_attr = array('data-show-subtext'=>true);
               $currency_attr = apply_filters_deprecated('proforma_currency_disabled', [$currency_attr], '2.3.0', 'proforma_currency_attributes');

               foreach($currencies as $currency){
                if($currency['isdefault'] == 1){
                  $currency_attr['data-base'] = $currency['id'];
                }
                if(isset($proforma)){
                 if($currency['id'] == $proforma->currency){
                  $selected = $currency['id'];
                }
               } else {
                if($currency['isdefault'] == 1){
                  $selected = $currency['id'];
                }
               }
               }
               $currency_attr = hooks()->apply_filters('proforma_currency_attributes',$currency_attr);
               ?>
            <?php echo render_select('currency', $currencies, array('id','name','symbol'), 'proforma_add_edit_currency', $selected, $currency_attr); ?>
            <!--@end currency-->
               </div>
               <div class="col-md-12 p2">
                  <!--proforma language-->
                  <?php
                  $languages = [
                     [
                     'id'=>1,
                     'name'=>'Română'
                     ]
                  ];
                  $selected = 1;
                  echo render_select('invoice_language', $languages, array('id','name'), 'invoice_add_edit_language', $selected); ?>
                  <!--@end proforma language-->
               </div>
               <div class="col-md-12 p2">
                  <!--proforma project-->
                  <?php
            if(!isset($proforma_from_project)){ ?>
            <div class="form-group select-placeholder projects-wrapper<?php if((!isset($proforma)) || (isset($proforma) && !customer_has_projects($proforma->clientid))){ echo ' hide';} ?>">
               <label for="project_id"><?php echo _l('project'); ?></label>
              <div id="project_ajax_search_wrapper">
                   <select name="project_id" id="project_id" class="projects ajax-search" data-live-search="true" data-width="100%" data-none-selected-text="<?php echo _l('dropdown_non_selected_tex'); ?>">
                   <?php
                     if(isset($proforma) && $proforma->project_id != 0){
                        echo '<option value="'.$proforma->project_id.'" selected>'.get_project_name_by_id($proforma->project_id).'</option>';
                     }
                   ?>
               </select>
               </div>
            </div>
            <?php } ?>
                  <!--@end proforma project-->
               </div>
            </div>


         </div>
      </div>





   </div>



	 <div class="panel-body mtop10 collapse in" id="inv_advanced_settings">

      <div class="row">
         <div class="col-md-4">


               <!--payment modes -->
               <div class="form-group mbot15 select-placeholder">
                  <label for="allowed_payment_modes" class="control-label"><?php echo _l('proforma_add_edit_allowed_payment_modes'); ?></label>
                  <br />
                  <?php if(count($payment_modes) > 0){ ?>
                  <select class="selectpicker"
                  data-toggle="<?php echo $this->input->get('allowed_payment_modes'); ?>"
                  name="allowed_payment_modes[]"
                  data-actions-box="true"
                  multiple="true"
                  data-width="100%"
                  data-title="<?php echo _l('dropdown_non_selected_tex'); ?>">
                  <?php foreach($payment_modes as $mode){
                 // echo '<pre>';var_dump($mode);die;
                     $selected = '';
                     if(isset($proforma)){
                       if($proforma->allowed_payment_modes){
                        $inv_modes = unserialize($proforma->allowed_payment_modes);
                        if(is_array($inv_modes)) {
                         foreach($inv_modes as $_allowed_payment_mode){
                           if($_allowed_payment_mode == $mode['id']){
                             $selected = ' selected';
                           }
                         }
                       }
                     }
                     } else {
                     if((int)$mode['selected_by_default'] === 1){
                        $selected = ' selected';
                     }
                     }
                     ?>
                     <option value="<?php echo $mode['id']; ?>"<?php echo $selected; ?>><?php echo $mode['name']; ?></option>
                  <?php } ?>
                  </select>
                  <?php } else { ?>
                  <p><?php echo _l('proforma_add_edit_no_payment_modes_found'); ?></p>
                  <a class="btn btn-info" href="<?php echo admin_url('paymentmodes'); ?>">
                  <?php echo _l('new_payment_mode'); ?>
                  </a>
                  <?php } ?>
               </div>
               <!--@end payment modes -->



               <!--recurring -->
               <div class="form-group select-placeholder"<?php if(isset($proforma) && !empty($proforma->is_recurring_from)){ ?> data-toggle="tooltip" data-title="<?php echo _l('create_recurring_from_child_error_message', [_l('proforma_lowercase'),_l('proforma_lowercase'), _l('proforma_lowercase')]); ?>"<?php } ?>>
                     <label for="recurring" class="control-label">
                     <?php echo _l('proforma_add_edit_recurring'); ?>
                     </label>
                     <select class="selectpicker"
                     data-width="100%"
                     name="recurring"
                     data-none-selected-text="<?php echo _l('dropdown_non_selected_tex'); ?>"
                     <?php
                     // The problem is that this invoice was generated from previous recurring invoice
                     // Then this new invoice you set it as recurring but the next invoice date was still taken from the previous invoice.
                     if(isset($proforma) && !empty($proforma->is_recurring_from)){echo 'disabled';} ?>
                     >
                        <?php for($i = 0; $i <=12; $i++){ ?>
                        <?php
                           $selected = '';
                           if(isset($proforma)){
                             if($proforma->custom_recurring == 0){
                              if($proforma->recurring == $i){
                                $selected = 'selected';
                              }
                            }
                           }else{
                              if(isset($_GET['recurring'])){
                                 if($i == 1){
                                   $selected = 'selected';
                                }
                              }
                            }
                           if($i == 0){
                            $reccuring_string =  _l('proforma_add_edit_recurring_no');
                           } else if($i == 1){
                            $reccuring_string = _l('proforma_add_edit_recurring_month',$i);
                           } else {
                            $reccuring_string = _l('proforma_add_edit_recurring_months',$i);
                           }
                           ?>
                        <option value="<?php echo $i; ?>" <?php echo $selected; ?>><?php echo $reccuring_string; ?></option>
                        <?php } ?>
                        <option value="custom" <?php if(isset($proforma) && $proforma->recurring != 0 && $proforma->custom_recurring == 1){echo 'selected';} ?>><?php echo _l('recurring_custom'); ?></option>
                     </select>
                  </div>

                  <div class="recurring_custom <?php if((isset($proforma) && $proforma->custom_recurring != 1) || (!isset($proforma))){echo 'hide';} ?>">
                     <div class="col-md-6">
                        <?php $value = (isset($proforma) && $proforma->custom_recurring == 1 ? $proforma->recurring : 1); ?>
                        <?php echo render_input('repeat_every_custom','',$value,'number',array('min'=>1)); ?>
                     </div>
                     <div class="col-md-6">
                        <select name="repeat_type_custom" id="repeat_type_custom" class="selectpicker" data-width="100%" data-none-selected-text="<?php echo _l('dropdown_non_selected_tex'); ?>">
                           <option value="day" <?php if(isset($proforma) && $proforma->custom_recurring == 1 && $proforma->recurring_type == 'day'){echo 'selected';} ?>><?php echo _l('invoice_recurring_days'); ?></option>
                           <option value="week" <?php if(isset($proforma) && $proforma->custom_recurring == 1 && $proforma->recurring_type == 'week'){echo 'selected';} ?>><?php echo _l('invoice_recurring_weeks'); ?></option>
                           <option value="month" <?php if(isset($proforma) && $proforma->custom_recurring == 1 && $proforma->recurring_type == 'month'){echo 'selected';} ?>><?php echo _l('invoice_recurring_months'); ?></option>
                           <option value="year" <?php if(isset($proforma) && $proforma->custom_recurring == 1 && $proforma->recurring_type == 'year'){echo 'selected';} ?>><?php echo _l('invoice_recurring_years'); ?></option>
                        </select>
                     </div>
                  </div>
                  <div id="cycles_wrapper" class="<?php if(!isset($proforma) || (isset($proforma) && $proforma->recurring == 0)){echo ' hide';}?>">
                     <div class="">
                        <?php $value = (isset($proforma) ? $proforma->cycles : 0); ?>
                        <div class="form-group recurring-cycles">
                          <label for="cycles"><?php echo _l('recurring_total_cycles'); ?>
                            <?php if(isset($proforma) && $proforma->total_cycles > 0){
                              echo '<small>' . _l('cycles_passed', $proforma->total_cycles) . '</small>';
                            }
                            ?>
                          </label>
                          <div class="input-group">
                            <input type="number" class="form-control"<?php if($value == 0){echo ' disabled'; } ?> name="cycles" id="cycles" value="<?php echo $value; ?>" <?php if(isset($proforma) && $proforma->total_cycles > 0){echo 'min="'.($proforma->total_cycles).'"';} ?>>
                            <div class="input-group-addon">
                              <div class="checkbox">
                                <input type="checkbox"<?php if($value == 0){echo ' checked';} ?> id="unlimited_cycles">
                                <label for="unlimited_cycles"><?php echo _l('cycles_infinity'); ?></label>
                              </div>
                            </div>
                          </div>
                        </div>
                     </div>
                  </div>
               <!--@end recurring -->


         </div>
         <div class="col-md-4">
                  <?php
                        $i = 0;
                        $selected = '';
                        foreach($staff as $member){
                         if(isset($proforma)){
                           if($proforma->sale_agent == $member['staffid']) {
                             $selected = $member['staffid'];
                           }
                         }
                         $i++;
                        }
                        echo render_select('sale_agent',$staff,array('staffid',array('firstname','lastname')),'sale_agent_string',$selected);
                        ?>


               <?php $value = (isset($proforma) ? $proforma->adminnote : ''); ?>
               <?php echo render_textarea('adminnote','proforma_add_edit_admin_note',$value); ?>

         </div>
         <div class="col-md-4">

					 <?php if($settings['vat_payer'] == 1){ ?>
						<div class="form-group select-placeholder">
									<label for="discount_type" class="control-label"><?php echo _l('discount_type'); ?></label>
									<select name="discount_type" class="selectpicker" data-width="100%" data-none-selected-text="<?php echo _l('dropdown_non_selected_tex'); ?>">

										<?php  if(isset($proforma)){ ?>
										 <option value="" selected><?php echo _l('no_discount'); ?></option>
										 <option value="before_tax" <?php if(isset($proforma)){ if($proforma->discount_type == 'before_tax'){ echo 'selected'; }} ?>><?php echo _l('discount_type_before_tax'); ?></option>
										 <option value="after_tax" <?php if(isset($proforma)){if($proforma->discount_type == 'after_tax'){echo 'selected';}} ?>><?php echo _l('discount_type_after_tax'); ?></option>
									 <?php }else{ ?>
										 <option value="" selected><?php echo _l('no_discount'); ?></option>
										 <option value="before_tax" selected><?php echo _l('discount_type_before_tax'); ?></option>
										 <option value="after_tax"><?php echo _l('discount_type_after_tax'); ?></option>
									 <?php } ?>
									</select>
						</div>
					<?php }else{ ?>
					 <div class="form-group select-placeholder">
								 <label for="discount_type" class="control-label"><?php echo _l('discount_type'); ?></label>
								 <select name="discount_type" class="selectpicker" data-width="100%" data-none-selected-text="<?php echo _l('dropdown_non_selected_tex'); ?>">

									 <?php  if(isset($proposal)){ ?>
										<option value="" selected><?php echo _l('no_discount'); ?></option>
										<option value="before_tax" <?php if(isset($proforma)){ if($proforma->discount_type == 'before_tax'){ echo 'selected'; }} ?>><?php echo _l('discount_type_no_tax'); ?></option>
									<?php }else{ ?>
										<option value="" selected><?php echo _l('no_discount'); ?></option>
										<option value="before_tax" selected><?php echo _l('discount_type_before_tax'); ?></option>
									<?php } ?>
								 </select>
					 </div>
				 <?php } ?>

         </div>




         <div class="col-md-12">
            <div class="form-group">
                  <label for="tags" class="control-label"><i class="fal fa-tag" aria-hidden="true"></i> <?php echo _l('tags'); ?></label>
                  <input type="text" class="tagsinput" id="tags" name="tags" value="<?php echo (isset($proforma) ? prep_tags_input(get_tags_in($proforma->id,'invoice')) : ''); ?>" data-role="tagsinput">
               </div>
         </div>
      </div>




   </div>












   <div class="panel-body mtop10">
      <div class="row">
         <div class="col-md-4">
            <?php $this->load->view('admin/invoice_items/item_select'); ?>
         </div>
         <?php if(!isset($proforma_from_project) && isset($billable_tasks)){
          ?>
         <div class="col-md-3">
            <div class="form-group select-placeholder input-group-select form-group-select-task_select popover-250">
              <div class="input-group input-group-select">
               <select name="task_select" data-live-search="true" id="task_select" class="selectpicker no-margin _select_input_group" data-width="100%" data-none-selected-text="<?php echo _l('bill_tasks'); ?>">
                  <option value=""></option>
                  <?php foreach($billable_tasks as $task_billable){ ?>
                  <option value="<?php echo $task_billable['id']; ?>"<?php if($task_billable['started_timers'] == true){ ?>disabled class="text-danger important" data-subtext="<?php echo _l('proforma_task_billable_timers_found'); ?>" <?php } else {
                     $task_rel_data = get_relation_data($task_billable['rel_type'],$task_billable['rel_id']);
                     $task_rel_value = get_relation_values($task_rel_data,$task_billable['rel_type']);
                     ?>
                     data-subtext="<?php echo $task_billable['rel_type'] == 'project' ? '' : $task_rel_value['name']; ?>" <?php } ?>><?php echo $task_billable['name']; ?></option>
                  <?php } ?>
               </select>
                <div class="input-group-addon input-group-addon-bill-tasks-help">
                  <?php
                    if(isset($proforma) && !empty($proforma->project_id)) {
                       $help_text = _l('showing_billable_tasks_from_project') . ' ' . get_project_name_by_id($proforma->project_id);
                    } else {
                       $help_text = _l('proforma_task_item_project_tasks_not_included');
                    }
                    echo '<span class="pointer popover-invoker" data-container=".form-group-select-task_select"
                      data-trigger="click" data-placement="top" data-toggle="popover" data-content="'.$help_text.'">
                      <i class="fal fa-question-circle"></i></span>';
                  ?>
                </div>
               </div>
            </div>
         </div>
         <?php } ?>
         <?php /*<div class="col-md-<?php if(!isset($invoice_from_project)){ echo 5; }else {echo 8;} ?> text-right show_quantity_as_wrapper">
            <div class="mtop10">
               <span><?php echo _l('show_quantity_as'); ?> </span>
               <div class="radio radio-primary radio-inline">
                  <input type="radio" value="1" id="sq_1" name="show_quantity_as" data-text="<?php echo _l('proforma_table_quantity_heading'); ?>" <?php if(isset($proforma) && $proforma->show_quantity_as == 1){echo 'checked';}else if(!isset($hours_quantity) && !isset($qty_hrs_quantity)){echo'checked';} ?>>
                  <label for="sq_1"><?php echo _l('quantity_as_qty'); ?></label>
               </div>
               <div class="radio radio-primary radio-inline">
                  <input type="radio" value="2" id="sq_2" name="show_quantity_as" data-text="<?php echo _l('proforma_table_hours_heading'); ?>" <?php if(isset($proforma) && $proforma->show_quantity_as == 2 || isset($hours_quantity)){echo 'checked';} ?>>
                  <label for="sq_2"><?php echo _l('quantity_as_hours'); ?></label>
               </div>
               <div class="radio radio-primary radio-inline">
                  <input type="radio" value="3" id="sq_3" name="show_quantity_as" data-text="<?php echo _l('proforma_table_quantity_heading'); ?>/<?php echo _l('proforma_table_hours_heading'); ?>" <?php if(isset($proforma) && $proforma->show_quantity_as == 3 || isset($qty_hrs_quantity)){echo 'checked';} ?>>
                  <label for="sq_3"><?php echo _l('proforma_table_quantity_heading'); ?>/<?php echo _l('proforma_table_hours_heading'); ?></label>
               </div>
            </div>
         </div> */ ?>
      </div>
      <?php if(isset($proforma_from_project)){ echo '<hr class="no-mtop" />'; } 
   
      if(isset($proforma)){
         $this->load->view('admin/invoice_items/item_table_editable',['invoice'=>$proforma, 'docType' => 'proforma']);
      }else{
         $this->load->view('admin/invoice_items/item_table_editable');
      }
      ?>









      <div class="col-md-8 col-md-offset-4">
         <table class="table text-right">
            <tbody>
               <tr id="subtotal">
                  <td><span class="bold"><?php echo _l('proforma_subtotal'); ?> :</span>
                  </td>
                  <td class="subtotal">
                  </td>
               </tr>
               <tr id="discount_area">
                  <td>
                     <div class="row">
                        <div class="col-md-7">
                           <span class="bold">
                            <?php echo _l('proforma_discount'); ?>
                         </span>
                        </div>
                        <div class="col-md-5">
                            <div class="input-group" id="discount-total">

                                <input type="number" value="<?php echo (isset($proforma) ? $proforma->discount_percent : 0); ?>" class="form-control pull-left input-discount-percent<?php if(isset($proforma) && !is_sale_discount($proforma,'percent') && is_sale_discount_applied($proforma)){echo ' hide';} ?>" min="0" max="100" name="discount_percent">

                                <input type="number" data-toggle="tooltip" data-title="<?php echo _l('numbers_not_formatted_while_editing'); ?>" value="<?php echo (isset($proforma) ? $proforma->discount_total : 0); ?>" class="form-control pull-left input-discount-fixed<?php if(!isset($proforma) || (isset($proforma) && !is_sale_discount($proforma,'fixed'))){echo ' hide';} ?>" min="0" name="discount_total">

                                <div class="input-group-addon">
                                  <div class="dropdown">
                                    <a class="dropdown-toggle" href="#" id="dropdown_menu_tax_total_type" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
                                      <span class="discount-total-type-selected">
                                        <?php if(!isset($proforma) || isset($proforma) && (is_sale_discount($proforma,'percent') || !is_sale_discount_applied($proforma))) {
                                          echo '%';
                                        } else {
                                          echo _l('discount_fixed_amount');
                                        }
                                        ?>
                                      </span>
                                      <span class="caret"></span>
                                    </a>
                                    <ul class="dropdown-menu" id="discount-total-type-dropdown" aria-labelledby="dropdown_menu_tax_total_type">
                                      <li>
                                        <a href="#" class="discount-total-type discount-type-percent<?php if(!isset($proforma) || (isset($proforma) && is_sale_discount($proforma,'percent')) || (isset($proforma) && !is_sale_discount_applied($proforma))){echo ' selected';} ?>">%</a>
                                      </li>
                                      <li><a href="#" class="discount-total-type discount-type-fixed<?php if(isset($proforma) && is_sale_discount($proforma,'fixed')){echo ' selected';} ?>">
                                          <?php echo _l('discount_fixed_amount'); ?>
                                        </a>
                                      </li>
                                    </ul>
                                  </div>
                                </div>
                            </div>
                        </div>
                     </div>
                  </td>
                  <td class="discount-total"></td>
               </tr>
               <!--<tr>
                  <td>
                     <div class="row">
                        <div class="col-md-7">
                           <span class="bold"><?php echo _l('proforma_adjustment'); ?></span>
                        </div>
                        <div class="col-md-5">
                           <input type="number" data-toggle="tooltip" data-title="<?php echo _l('numbers_not_formatted_while_editing'); ?>" value="<?php if(isset($proforma)){echo $proforma->adjustment; } else { echo 0; } ?>" class="form-control pull-left" name="adjustment">
                        </div>
                     </div>
                  </td>
                  <td class="adjustment"></td>
               </tr>-->
               <tr>
                  <td><span class="bold"><?php echo _l('proforma_total'); ?> :</span>
                  </td>
                  <td class="total">
                  </td>
               </tr>
            </tbody>
         </table>
      </div>
      <div id="removed-items"></div>
      <div id="billed-tasks"></div>
      <div id="billed-expenses"></div>
      <?php echo form_hidden('task_id'); ?>
      <?php echo form_hidden('expense_id'); ?>
   </div>
   <div class="row">
      <div class="col-md-12 mtop15">
         <div class="panel-body bottom-transaction">
           <div id="currency_display">

           </div>


            <?php
            if(isset($settings['vat_on_collection'])){
            if($settings['vat_on_collection'] == 1){
              echo '<p>'._l('proforma_notice_vat_on_collection').'</p>';
            }}


             $value = (isset($proforma) ? $proforma->clientnote : get_option('predefined_clientnote_invoice')); ?>
            <?php echo render_textarea('clientnote','invoice_add_edit_client_note',$value,array(),array(),'mtop15'); ?>
            <?php $value = (isset($proforma) ? $proforma->terms : get_option('predefined_terms_invoice')); ?>
            <?php echo render_textarea('terms','terms_and_conditions',$value,array(),array(),'mtop15'); ?>


            <?php if(is_invoices_overdue_reminders_enabled()){ ?>
               <div class="form-group">
                  <div class="checkbox checkbox-danger">
                     <input type="checkbox" <?php if(isset($proforma) && $proforma->cancel_overdue_reminders == 1){echo 'checked';} ?> id="cancel_overdue_reminders" name="cancel_overdue_reminders">
                     <label for="cancel_overdue_reminders"><?php echo _l('cancel_overdue_reminders_invoice') ?></label>
                  </div>
               </div>
               <?php } ?>





               <?php $rel_id = (isset($proforma) ? $proforma->id : false); ?>
               <?php
                  if(isset($custom_fields_rel_transfer)) {
                      $rel_id = $custom_fields_rel_transfer;
                  }
               ?>
               <?php echo render_custom_fields('invoice',$rel_id); ?>








            <div class="btn-bottom-toolbar text-right">
                <?php if(!isset($proforma)){ ?>
                <button class="btn-tr btn btn-default mleft10 text-right invoice-form-submit save-as-draft transaction-submit invoiceSave">
                <?php echo _l('save_as_draft'); ?>
                </button>
                <?php } ?>
              <div class="btn-group dropup">
                <button type="button" class="btn-tr btn btn-info invoice-form-submit transaction-submit invoiceSave"><?php echo _l('submit'); ?></button>
                <button type="button" class="btn btn-info dropdown-toggle invoiceSave" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                  <span class="caret"></span>
                </button>
                <ul class="dropdown-menu dropdown-menu-right width200">
                  <li>
                    <a href="#" class="invoice-form-submit save-and-send transaction-submit">
                      <?php echo _l('save_and_send'); ?>
                    </a>
                  </li>
                  <?php if(!isset($proforma)) { ?>
                  <li>
                    <a href="#" class="invoice-form-submit save-and-send-later transaction-submit">
                      <?php echo _l('save_and_send_later'); ?>
                    </a>
                  </li>
                  <li>
                      <a href="#" class="invoice-form-submit save-and-record-payment transaction-submit">
                        <?php echo _l('save_and_record_payment'); ?>
                      </a>
                  </li>
                <?php } ?>
                </ul>
              </div>
             </div>
         </div>
        <div class="btn-bottom-pusher"></div>
      </div>
   </div>
</div>




<script>

</script>
