hbsprogram.com

thủ thuật wordpress ,vps và mình thích thì mình viết thôi

1 SQL

Bước đầu ở đây xác định kho hàng còn thiếu trường người quản lý,tỉnh, quận .Vào trong mysql thêm các trường sau vào :

ALTER TABLE `sma_warehouses` ADD `nguoiquanly` VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT 'tên người quản lý' AFTER `price_group_id`, ADD `tinh` VARCHAR(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT 'tỉnh ' AFTER `nguoiquanly`, ADD `huyen` VARCHAR(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT 'huyên' AFTER `tinh`;

2 Php

Trong mục views của phần settings chỉnh sửa 2 phần add_warehouse.php và edit_warehouse.php

<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-2x">&times;</i>
            </button>
            <h4 class="modal-title" id="myModalLabel"><?php echo lang('add_warehouse'); ?></h4>
        </div>
        <?php $attrib = array('data-toggle' => 'validator', 'role' => 'form');
        echo admin_form_open_multipart("system_settings/add_warehouse", $attrib); ?>
        <div class="modal-body">
            <p><?= lang('enter_info'); ?></p>

            <div class="form-group">
                <label class="control-label" for="code"><?php echo $this->lang->line("code"); ?></label>
                <?php echo form_input('code', '', 'class="form-control" id="code" required="required"'); ?>
            </div>
            <div class="form-group">
                <label class="control-label" for="name"><?php echo $this->lang->line("name"); ?></label>
                <?php echo form_input('name', '', 'class="form-control" id="name" required="required"'); ?>
            </div>
            <div class="form-group">
                <label class="control-label" for="price_group"><?php echo $this->lang->line("price_group"); ?></label>
                <?php
                $pgs[''] = lang('select').' '.lang('price_group');
                foreach ($price_groups as $price_group) {
                    $pgs[$price_group->id] = $price_group->name;
                }
                echo form_dropdown('price_group', $pgs, $Settings->price_group, 'class="form-control tip select" id="price_group" style="width:100%;"');
                ?>
            </div>
            <div class="form-group">
                <label class="control-label" for="email"><?php echo $this->lang->line("Người quản lý"); ?></label>
                <?php echo form_input('nguoiquanly', '', 'class="form-control" id="nguoiquanly"'); ?>
            </div>
            
            <div class="form-group">
                <label class="control-label" for="phone"><?php echo $this->lang->line("phone"); ?></label>
                <?php echo form_input('phone', '', 'class="form-control" id="phone"'); ?>
            </div>
            <div class="form-group">
                <label class="control-label" for="email"><?php echo $this->lang->line("email"); ?></label>
                <?php echo form_input('email', '', 'class="form-control" id="email"'); ?>
            </div>
            

            <div class="form-group">
                <label for="tinh">Tỉnh </label>                        
                <input type="text" name="tinh" value="" class="form-control" id="tinh">
            </div>

            <div class="form-group">
                <label for="tinh">Quận Huyện,Thành Phố </label>                        
                <input type="text" name="huyen" value="" class="form-control" id="huyen">
            </div>
            
            <div class="form-group">
                <label class="control-label" for="address"><?php echo $this->lang->line("Địa chỉ chi tiết"); ?></label>
                <?php echo form_input('address', '', 'class="form-control" id="address" required="required"'); ?>
            </div>
            <div class="form-group">
                <?= lang("warehouse_map", "image") ?>
                <input id="image" type="file" data-browse-label="<?= lang('browse'); ?>" name="userfile" data-show-upload="false" data-show-preview="false"
                       class="form-control file">
            </div>
        </div>
        <div class="modal-footer">
            <?php echo form_submit('add_warehouse', lang('add_warehouse'), 'class="btn btn-primary"'); ?>
        </div>
    </div>
    <?php echo form_close(); ?>
</div>
<script type="text/javascript" src="<?= $assets ?>js/custom.js"></script>
<?= $modal_js ?>
<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-2x">&times;</i>
            </button>
            <h4 class="modal-title" id="myModalLabel"><?php echo lang('edit_warehouse'); ?></h4>
        </div>
        <?php $attrib = array('data-toggle' => 'validator', 'role' => 'form');
        echo admin_form_open_multipart("system_settings/edit_warehouse/" . $id, $attrib); ?>
        <div class="modal-body">
            <p><?= lang('enter_info'); ?></p>

            <div class="form-group">
                <label class="control-label" for="code"><?php echo $this->lang->line("code"); ?></label>
                <?php echo form_input('code', $warehouse->code, 'class="form-control" id="code" required="required"'); ?>
            </div>
            <div class="form-group">
                <label class="control-label" for="name"><?php echo $this->lang->line("name"); ?></label>
                <?php echo form_input('name', $warehouse->name, 'class="form-control" id="name" required="required"'); ?>
            </div>
            <div class="form-group">
                <label class="control-label" for="price_group"><?php echo $this->lang->line("price_group"); ?></label>
                <?php
                $pgs[''] = lang('select').' '.lang('price_group');
                foreach ($price_groups as $price_group) {
                    $pgs[$price_group->id] = $price_group->name;
                }
                echo form_dropdown('price_group', $pgs, $warehouse->price_group_id, 'class="form-control tip select" id="price_group" style="width:100%;"');
                ?>
            </div>
            
            <div class="form-group">
                <label class="control-label" for="nguoiquanly"><?php echo $this->lang->line("Người quản lý"); ?></label>
                <?php echo form_input('nguoiquanly', $warehouse->nguoiquanly, 'class="form-control" id="nguoiquanly"'); ?>
            </div>
            <div class="form-group">
                <label class="control-label" for="phone"><?php echo $this->lang->line("phone"); ?></label>
                <?php echo form_input('phone', $warehouse->phone, 'class="form-control" id="phone"'); ?>
            </div>
            <div class="form-group">
                <label class="control-label" for="email"><?php echo $this->lang->line("email"); ?></label>
                <?php echo form_input('email', $warehouse->email, 'class="form-control" id="email"'); ?>
            </div>
            <div class="form-group">
                <label class="control-label" for="address"><?php echo $this->lang->line("Tỉnh"); ?></label>
                <?php echo form_input('tinh', $warehouse->tinh, 'class="form-control" id="tinh" required="required"'); ?>
            </div>
             <div class="form-group">
                <label class="control-label" for="address"><?php echo $this->lang->line("Quận Huyện,Thành Phố"); ?></label>
                <?php echo form_input('huyen', $warehouse->huyen, 'class="form-control" id="huyen" required="required"'); ?>
            </div>
            
            <div class="form-group">
                <label class="control-label" for="address"><?php echo $this->lang->line("address"); ?></label>
                <?php echo form_input('address', $warehouse->address, 'class="form-control" id="address" required="required"'); ?>
            </div>
            <div class="form-group">
                <?= lang("warehouse_map", "image") ?>
                <input id="image" type="file" data-browse-label="<?= lang('browse'); ?>" name="userfile" data-show-upload="false" data-show-preview="false"
                       class="form-control file">
            </div>
        </div>
        <div class="modal-footer">
            <?php echo form_submit('edit_warehouse', lang('edit_warehouse'), 'class="btn btn-primary"'); ?>
        </div>
    </div>
    <?php echo form_close(); ?>
</div>
<script type="text/javascript" src="<?= $assets ?>js/custom.js"></script>
<?= $modal_js ?>

Trong mục controller :

function add_warehouse()
  {
      $this->load->helper('security');
      $this->form_validation->set_rules('code', lang("code"), 'trim|is_unique[warehouses.code]|required');
      $this->form_validation->set_rules('name', lang("name"), 'required');
      $this->form_validation->set_rules('address', lang("address"), 'required');
      $this->form_validation->set_rules('userfile', lang("map_image"), 'xss_clean');

      if ($this->form_validation->run() == true) {
          if ($_FILES['userfile']['size'] > 0) {

              $this->load->library('upload');

              $config['upload_path'] = 'assets/uploads/';
              $config['allowed_types'] = 'gif|jpg|png|jpeg';
              $config['max_size'] = $this->allowed_file_size;
              $config['max_width'] = '2000';
              $config['max_height'] = '2000';
              $config['overwrite'] = FALSE;
              $config['encrypt_name'] = TRUE;
              $config['max_filename'] = 25;
              $this->upload->initialize($config);

              if (!$this->upload->do_upload()) {
                  $error = $this->upload->display_errors();
                  $this->session->set_flashdata('message', $error);
                  admin_redirect("system_settings/warehouses");
              }

              $map = $this->upload->file_name;

              $this->load->helper('file');
              $this->load->library('image_lib');
              $config['image_library'] = 'gd2';
              $config['source_image'] = 'assets/uploads/' . $map;
              $config['new_image'] = 'assets/uploads/thumbs/' . $map;
              $config['maintain_ratio'] = TRUE;
              $config['width'] = 76;
              $config['height'] = 76;

              $this->image_lib->clear();
              $this->image_lib->initialize($config);

              if (!$this->image_lib->resize()) {
                  echo $this->image_lib->display_errors();
              }
          } else {
              $map = NULL;
          }
          $data = array('code' => $this->input->post('code'),
              'name' => $this->input->post('name'),
              'nguoiquanly' => $this->input->post('nguoiquanly'),
              'phone' => $this->input->post('phone'),
              'email' => $this->input->post('email'),
              'tinh' => $this->input->post('tinh'),
              'huyen' => $this->input->post('huyen'),
              'address' => $this->input->post('address'),
              'price_group_id' => $this->input->post('price_group'),
              'map' => $map,
          );
      } elseif ($this->input->post('add_warehouse')) {
          $this->session->set_flashdata('error', validation_errors());
          admin_redirect("system_settings/warehouses");
      }

      if ($this->form_validation->run() == true && $this->settings_model->addWarehouse($data)) {
          $this->session->set_flashdata('message', lang("warehouse_added"));
          admin_redirect("system_settings/warehouses");
      } else {
          $this->data['error'] = (validation_errors() ? validation_errors() : $this->session->flashdata('error'));
          $this->data['price_groups'] = $this->settings_model->getAllPriceGroups();
          $this->data['modal_js'] = $this->site->modal_js();
          $this->load->view($this->theme . 'settings/add_warehouse', $this->data);
      }
  }

  function edit_warehouse($id = NULL)
  {
      $this->load->helper('security');
      $this->form_validation->set_rules('code', lang("code"), 'trim|required');
      $wh_details = $this->settings_model->getWarehouseByID($id);
      if ($this->input->post('code') != $wh_details->code) {
          $this->form_validation->set_rules('code', lang("code"), 'required|is_unique[warehouses.code]');
      }
      $this->form_validation->set_rules('address', lang("address"), 'required');
      $this->form_validation->set_rules('map', lang("map_image"), 'xss_clean');

      if ($this->form_validation->run() == true) {
          $data = array('code' => $this->input->post('code'),
              'name' => $this->input->post('name'),
              'nguoiquanly' => $this->input->post('nguoiquanly'),
              'phone' => $this->input->post('phone'),
              'email' => $this->input->post('email'),
              'tinh' => $this->input->post('tinh'),
              'huyen' => $this->input->post('huyen'),
              'address' => $this->input->post('address'),
              'price_group_id' => $this->input->post('price_group'),
          );

          if ($_FILES['userfile']['size'] > 0) {

              $this->load->library('upload');

              $config['upload_path'] = 'assets/uploads/';
              $config['allowed_types'] = 'gif|jpg|png|jpeg';
              $config['max_size'] = $this->allowed_file_size;
              $config['max_width'] = '2000';
              $config['max_height'] = '2000';
              $config['overwrite'] = FALSE;
              $config['encrypt_name'] = TRUE;
              $config['max_filename'] = 25;
              $this->upload->initialize($config);

              if (!$this->upload->do_upload()) {
                  $error = $this->upload->display_errors();
                  $this->session->set_flashdata('message', $error);
                  admin_redirect("system_settings/warehouses");
              }

              $data['map'] = $this->upload->file_name;

              $this->load->helper('file');
              $this->load->library('image_lib');
              $config['image_library'] = 'gd2';
              $config['source_image'] = 'assets/uploads/' . $data['map'];
              $config['new_image'] = 'assets/uploads/thumbs/' . $data['map'];
              $config['maintain_ratio'] = TRUE;
              $config['width'] = 76;
              $config['height'] = 76;

              $this->image_lib->clear();
              $this->image_lib->initialize($config);

              if (!$this->image_lib->resize()) {
                  echo $this->image_lib->display_errors();
              }
          }
      } elseif ($this->input->post('edit_warehouse')) {
          $this->session->set_flashdata('error', validation_errors());
          admin_redirect("system_settings/warehouses");
      }

      if ($this->form_validation->run() == true && $this->settings_model->updateWarehouse($id, $data)) { //check to see if we are updateing the customer
          $this->session->set_flashdata('message', lang("warehouse_updated"));
          admin_redirect("system_settings/warehouses");
      } else {
          $this->data['error'] = (validation_errors() ? validation_errors() : $this->session->flashdata('error'));

          $this->data['warehouse'] = $this->settings_model->getWarehouseByID($id);
          $this->data['price_groups'] = $this->settings_model->getAllPriceGroups();
          $this->data['id'] = $id;
          $this->data['modal_js'] = $this->site->modal_js();
          $this->load->view($this->theme . 'settings/edit_warehouse', $this->data);
      }
  }

Trong phần Sale Controller :

 public function add_delivery($id = null) {
        $this->sma->checkPermissions();
        $sale = $this->sales_model->getInvoiceByID($id);
        if ($this->input->get('id')) {
            $id = $this->input->get('id');
        }
        if ($sale->sale_status != 'completed') {
            $this->session->set_flashdata('error', lang('status_is_x_completed'));
            $this->sma->md();
        }
    
        if ($delivery = $this->sales_model->getDeliveryBySaleID($id)) {
             
            $this->edit_delivery($delivery->id);
        } else {
            if ($this->input->post('add_delivery')) {
                if ($this->Owner || $this->Admin) {
                    $date = $this->sma->fld(trim($this->input->post('date')));
                } else {
                    $date = date('Y-m-d H:i:s');
                }
                // giao hàng tiết kiệm 	
                $token = $this->Settings->apightk;
                // get key ghtk
                $sale_reference_no = $this->input->post('sale_reference_no');
                $grand_total = $this->input->post('grand_total');
                $sotienthanhtoantruoc = $this->input->post('sotienthanhtoantruoc');
                $sotiencanlay = $grand_total - $sotienthanhtoantruoc;
                $tensp = $this->input->post('tensp');
                $name = $this->input->post('customer');
                $phone = $this->input->post('phone');
                $tinh = $this->input->post('tinh');
                $huyen = $this->input->post('huyen');
                $address = $this->input->post('address');
                $note = $this->sma->clear_tags($this->input->post('note'));
                $cannang = $this->input->post('cannang');
                $giaoquavanchuyen = (int) $this->input->post('giaoquavanchuyen');
                $is_freeship = (int) $this->input->post('is_freeship');
                // get thông tin kho hàng để cho sang quản trị 
                $warehouse_id1 = (int) $this->session->userdata('warehouse_id');
                if ($warehouse_id1 == 0) {
                    // mặc định kho trung liêt
                    $warehouse_id1 = 6;
                }
                $data_khohang = $this->site->getWarehouseByID($warehouse_id1);
                $nguoiquanly = (string) $data_khohang->nguoiquanly;
                $phone_ql = (string) $data_khohang->phone;
                $tinh_ql = (string) $data_khohang->tinh;
                $huyen_ql = (string) $data_khohang->huyen;
                $address_ql = (string) $data_khohang->address;
if ($giaoquavanchuyen == 1){
                $order = <<<HTTP_BODY
{
    "products": [{
        "name": "$tensp",
        "weight": $cannang,
        "quantity": 1
    }],
    "order": {
        "id": "$sale_reference_no",
        "pick_name": "$nguoiquanly",
        "pick_address": "$address_ql",
        "pick_province": "$tinh_ql",
        "pick_district": "$huyen_ql",
        "pick_tel": "$phone_ql",
        "tel": "$phone",
        "name": "$name",
        "address": "$address",
        "province": "$tinh",
        "district": "$huyen",
        "is_freeship": "$is_freeship",
        "pick_money": $sotiencanlay,
        "note": "$note",
        "value": $sotiencanlay,
        "transport": "fly"
    }
}
HTTP_BODY;
$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_URL => "https://services.giaohangtietkiem.vn/services/shipment/order",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => $order,
    CURLOPT_HTTPHEADER => array(
        "Content-Type: application/json",
        "Token: $token",
        "Content-Length: " . strlen($order),
    ),
));
            $response = curl_exec($curl);
            curl_close($curl);
            $data_reponser = json_decode($response);
            // check trường hợp lỗi khi lên đơn nếu sai 
            if (!$data_reponser->success)
            {
                $loi = $data_reponser->message;
                $this->session->set_flashdata('message', $loi .' . Vui lòng báo với admin hoặc gọi số 0838105009 và gửi đoạn lỗi này cho admin');
                admin_redirect("sales/deliveries");
            }
            
            $info_order = $data_reponser->order;
            // mã đơn hàng $info_order->label;
                        $id_donhang = '';
            $id_donhang= substr($info_order->label,-9,9);
            $fee =(int)$info_order->fee;
            $shipping = $fee;
            $do_reference_no = $id_donhang;
            //$this->db->update('deliveries', array('do_reference_no' => $do_reference_no), array('sale_id' => $id));
            $this->db->update('sales', array('shipping' => $shipping), array('id' => $id));
}
            
            $this->form_validation->set_rules('sale_reference_no', lang("sale_reference_no"), 'required');
            $this->form_validation->set_rules('customer', lang("customer"), 'required');
            $this->form_validation->set_rules('address', lang("address"), 'required');
            $dlDetails = array(
                    'date' => $date,
                    'sale_id' => $this->input->post('sale_id'),
                    //'do_reference_no' => $this->input->post('do_reference_no') ? $this->input->post('do_reference_no') : $this->site->getReference('do'),
                    'do_reference_no' => $do_reference_no != ''  ? $do_reference_no : $this->site->getReference('do'),
                    'sale_reference_no' => $this->input->post('sale_reference_no'),
                    'customer' => $this->input->post('customer'),
                    'address' => $this->input->post('address'),
                    'status' => $this->input->post('status'),
                    'delivered_by' => $this->input->post('delivered_by'),
                    'received_by' => $this->input->post('received_by'),
                    'note' => $this->sma->clear_tags($this->input->post('note')),
                    'created_by' => $this->session->userdata('user_id'),
                );
                if ($_FILES['document']['size'] > 0) {
                    $this->load->library('upload');
                    $config['upload_path'] = $this->digital_upload_path;
                    $config['allowed_types'] = $this->digital_file_types;
                    $config['max_size'] = $this->allowed_file_size;
                    $config['overwrite'] = false;
                    $config['encrypt_name'] = true;
                    $this->upload->initialize($config);
                    if (!$this->upload->do_upload('document')) {
                        $error = $this->upload->display_errors();
                        $this->session->set_flashdata('error', $error);
                        redirect($_SERVER["HTTP_REFERER"]);
                    }
                    $photo = $this->upload->file_name;
                    $data['attachment'] = $photo;
                }
            } elseif ($this->input->post('add_delivery')) {
                $this->session->set_flashdata('error', validation_errors());
                redirect($_SERVER["HTTP_REFERER"]);
            }
            if ($this->form_validation->run() == true && $this->sales_model->addDelivery($dlDetails)) {
                
                $this->session->set_flashdata('message', lang("delivery_added"));
                admin_redirect("sales/deliveries");
            } else {
                
                $this->data['error'] = (validation_errors() ? validation_errors() : $this->session->flashdata('error'));
                $this->data['customer'] = $this->site->getCompanyByID($sale->customer_id);
                $this->data['address'] = $this->site->getAddressByID($sale->address_id);
                $this->data['inv'] = $sale;
                // chuyển id vận chuyển sang giao nhận
                $this->data['do_reference_no'] = $sale->id_vanchuyen; //$this->site->getReference('do');
                $this->data['modal_js'] = $this->site->modal_js();
                //$this->page_construct('sales/add_delivery', $this->data);
        $this->load->view($this->theme . 'sales/add_delivery', $this->data);
            }
        }
    }

Trong phần view add_delivery.php

<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>

<div class="modal-dialog modal-lg">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-2x">&times;</i>
            </button>
            <h4 class="modal-title" id="myModalLabel"><?php echo lang('add_delivery'); ?></h4>
        </div>
        <?php $attrib = array('data-toggle' => 'validator', 'role' => 'form');
        echo admin_form_open_multipart("sales/add_delivery/" . $inv->id, $attrib);
        ?>
        <div class="modal-body">
            <p><?= lang('enter_info'); ?></p>
<?php //var_dump($this->session->userdata())  ?>
            <div class="row">
                <div class="col-md-6">
                        <?php if ($Owner || $Admin) { ?>
                        <div class="form-group">
                            <?= lang("date", "date"); ?>
                        <?= form_input('date', (isset($_POST['date']) ? $_POST['date'] : ""), 'class="form-control datetime" id="date" required="required"'); ?>
                        </div>
                    <?php } ?>
                        <?php if ($this->Owner || $this->Admin) { ?>
                        <div class="form-group">
                            <?= lang("Mã vận chuyển", "Mã vận chuyển"); ?>
                        <?= form_input('do_reference_no', (isset($_POST['do_reference_no']) ? $_POST['do_reference_no'] : $do_reference_no), 'class="form-control tip" id="do_reference_no"'); ?>
                        </div>
<?php } ?>	
                    <div class="form-group">
                         <label for="tinh">Giao qua bên vận chuyển</label>    
                         <?php
                            $giaoquavanchuyen = array('1' => lang('Giao qua'), '0' => lang('Không giao'));
                         ?>
                        <?= form_dropdown('giaoquavanchuyen', $giaoquavanchuyen, '', 'class="form-control" id="giaoquavanchuyen" required="required" style="width:100%;"'); ?>
                    </div>
                    
                    <div class="form-group">
                        <?= lang("sale_reference_no", "sale_reference_no"); ?>
<?= form_input('sale_reference_no', (isset($_POST['sale_reference_no']) ? $_POST['sale_reference_no'] : $inv->reference_no), 'class="form-control tip" id="sale_reference_no" required="required" readonly'); ?>
                    </div>
                    <input type="hidden" value="<?php echo $inv->id; ?>" name="sale_id"/>

                    <div class="form-group">
                        <?= lang("customer", "customer"); ?>
<?php echo form_input('customer', (isset($_POST['customer']) ? $_POST['customer'] : $customer->name), 'class="form-control" id="customer" required="required" '); ?>
                    </div>
                    <div class="form-group">
                        <label for="tinh">Điện thoại</label>                        
                        <input type="text" name="phone" value="<?= $customer->phone ?>" class="form-control" id="phone">
                    </div>
                    <div class="form-group">
                        <label for="tinh">Tỉnh </label>                        
                        <input type="text" name="tinh" value="<?= $customer->city ?>" class="form-control" id="tinh">
                    </div>

                    <div class="form-group">
                        <label for="tinh">Quận Huyện,Thành Phố </label>                        
                        <input type="text" name="huyen" value="<?= $customer->state ?>" class="form-control" id="huyen">
                    </div>

                    <div class="form-group">
                        <?= lang("address", "address"); ?>
                        <?php
                        /* cũ
                          $av = (isset($_POST['address']) ? $_POST['address']
                          : (empty($address)
                          ? ($customer->address . ", " . $customer->state. ", " . $customer->city . " " . $customer->postal_code . " " . $customer->country . "<br>".lang('tel').": " . $customer->phone . "<br> Email: " . $customer->email)
                          : ($address->line1.'<br>'.$address->line2.'<br>'.$address->city.' '.$address->city.'<br>'.$address->postal_code.' '.$address->country.'<br>'.lang('tel').': '.$address->phone)
                          )
                          );
                         */
                        $av = (isset($_POST['address']) ? $_POST['address'] : (empty($address) ? ($customer->address ) : ($address->line1 . '<br>' . $address->line2)
                                )
                                );
                        echo form_input('address', $av, 'class="form-control" id="address" required="required"');
                        ?>
                    </div>


                </div>

                <div class="col-md-6">
                    <div class="form-group">
                        <?= lang('status', 'status'); ?>
                        <?php
                        if ($this->Owner || $this->Admin) {
                            $opts = array('packing' => lang('packing'), 'delivering' => lang('delivering'), 'delivered' => lang('delivered'));
                        } else {
                            $opts = array('packing' => lang('packing'));
                        }
                        ?>
                        <?= form_dropdown('status', $opts, '', 'class="form-control" id="status" required="required" style="width:100%;"'); ?>
                    </div>
                    <div class="form-group">
                        <label for="grand_total">Tổng tiền đơn hàng là </label>                        
                        <input type="number" name="grand_total" value="<?= (int) $inv->grand_total ?>" class="form-control" id="grand_total">
                    </div>
                    <div class="form-group">
                        <label for="sotienthanhtoantruoc">Số tiền thanh toán trước </label>                        
                        <input type="number" name="sotienthanhtoantruoc" value="0" class="form-control" id="sotienthanhtoantruoc">
                    </div>
                    <div class="form-group">
                        <label for="tensp">Tên sản phẩm sang bên GHTK</label>                        
                        <input type="text" name="tensp" value="Mô hình lắp ráp 3d" class="form-control" id="tensp">
                    </div>
                    <div class="form-group">
                        <label for="tinh">Cân nặng (kg) </label>                        
                        <input type="text" name="cannang" value="0.5" class="form-control" id="cannang">
                    </div>
                    <div class="form-group">
                         <label for="tinh">Phí ship</label>    
                         <?php
                            $freeship = array('1' => lang('shop trả'), '0' => lang('Khách trả'));
                         ?>
                        <?= form_dropdown('is_freeship', $freeship, '', 'class="form-control" id="is_freeship" required="required" style="width:100%;"'); ?>
                    </div>
                    <div class="form-group">
<?php // lang("delivered_by", "delivered_by");  ?>
<?php // form_input('delivered_by', (isset($_POST['delivered_by']) ? $_POST['delivered_by'] : ''), 'class="form-control" id="delivered_by" value="GHTK"');  ?>
                    </div>

                    <div class="form-group">
<?php // lang("received_by", "received_by");  ?>
<?php // form_input('received_by', (isset($_POST['received_by']) ? $_POST['received_by'] : ''), 'class="form-control" id="received_by"');  ?>
                    </div>

                    <div class="form-group">
<?= lang("attachment", "attachment") ?>
                        <input id="attachment" type="file" data-browse-label="<?= lang('browse'); ?>" name="document" data-show-upload="false" data-show-preview="false" class="form-control file">
                    </div>

                    <div class="form-group">
<?= lang("note", "note"); ?>
<?php echo form_textarea('note', (isset($_POST['note']) ? $_POST['note'] : ""), 'class="form-control" id="note"'); ?>
                    </div>
                </div>
            </div>

        </div>
        <div class="modal-footer">
<?php echo form_submit('add_delivery', lang('add_delivery'), 'class="btn btn-primary"'); ?>
        </div>
    </div>
            <?php echo form_close(); ?>
</div>
<script type="text/javascript" src="<?= $assets ?>js/custom.js"></script>
<script type="text/javascript" charset="UTF-8">
    $.fn.datetimepicker.dates['sma'] = <?= $dp_lang ?>;
</script>
<?= $modal_js ?>
<script type="text/javascript" charset="UTF-8">
    $(document).ready(function () {
        $.fn.datetimepicker.dates['sma'] = <?= $dp_lang ?>;
        $("#date").datetimepicker({
            format: site.dateFormats.js_ldate,
            fontAwesome: true,
            language: 'sma',
            weekStart: 1,
            todayBtn: 1,
            autoclose: 1,
            todayHighlight: 1,
            startView: 2,
            forceParse: 0
        }).datetimepicker('update', new Date());
    });
</script>