<?php $this->view("includes/Inc_pagehead");?>
<!-- Page Styles Goes Here-->

<style>
.m-invoice-2 .m-invoice__wrapper .m-invoice__body table thead tr th {
  color: #000000;
}
.m-invoice-2 .m-invoice__wrapper .m-invoice__body table tbody tr td {
  color: #404040;
}
.item_table td{
  padding: .75rem !important;
}
.item_table th{
  white-space: nowrap;
  padding: .75rem !important;
}
.table thead th {
  border-top: 2px solid #b7b7b7 !important;
}
.table thead th {
  border: 2px solid #b7b7b7;
}
.table tbody td {
  border: 2px solid #b7b7b7;
}
.payment-table tbody td{
  border-top: 2px solid #b7b7b7 !important;
}
.m-invoice-2 .m-invoice__wrapper .m-invoice__head .m-invoice__container.m-invoice__container--centered {
  width: 90%;
}
.m-invoice-2 .m-invoice__wrapper .m-invoice__body.m-invoice__body--centered {
  width: 90%;
}
.m-invoice-2 .m-invoice__wrapper .m-invoice__head .m-invoice__container.m-invoice__container--centered {
  width: 90%;
}
</style>


<style>

@media print {

  .table-bordered td{
    padding: .75rem !important;
  }
  .table-bordered th{
    white-space: nowrap;
    padding: .75rem !important;
  }
  .table-bordered .table thead th {
    border-top: 2px solid #f4f5f8 !important;
  }
  .m-invoice-2 .m-invoice__wrapper .m-invoice__head .m-invoice__container.m-invoice__container--centered {
    width: 97%;
  }
  .m-invoice-2 .m-invoice__wrapper .m-invoice__body.m-invoice__body--centered {
    width: 97%;
  }
  .m-invoice-2 .m-invoice__wrapper .m-invoice__body.m-invoice__body--centered {
    margin-left: 10px !important;
  }

  #print_view {
    margin-top: -20%;
  }
  #print, .print_hide_div
  {
    display: none !important;
  }
  body * {
    visibility: hidden;
  }
  .m-portlet__body * {
    visibility: visible;
    overflow: visible !important;
  }
  .letter_head_img{
    display: block !important;
  }
  body.m-content--skin-light2 {
    background-color: white !important;
  }
  .m-invoice-2 .m-invoice__wrapper .m-invoice__head .m-invoice__container.m-invoice__container--centered {
    width: 97% !important;
  }
  .m-invoice-2 .m-invoice__wrapper .m-invoice__head .m-invoice__container .m-invoice__items .m-invoice__item {
    display: table-cell;
}
}
.m-invoice-2 .m-invoice__wrapper .m-invoice__head .m-invoice__container .m-invoice__items .m-invoice__item {
  display: table-cell !important;
}
.col-sm-4 {
    -webkit-box-flex: 0;
    -ms-flex: 0 0 33.33333%;
    flex: 0 0 33.33333%;
    max-width: 33.33333%;
}
.col-sm-8 {
    -webkit-box-flex: 0;
    -ms-flex: 0 0 66.66667%;
    flex: 0 0 66.66667%;
    max-width: 66.66667%;
}
</style>
<?php $this->view("includes/Inc_navigation");?>
<div class="m-grid__item m-grid__item--fluid m-wrapper">
  <!-- BEGIN: Subheader -->
  <div class="m-subheader ">
    <div class="d-flex align-items-center">
      <div class="mr-auto">
        <h3 class="m-subheader__title m-subheader__title--separator">
          Stock Transfer Bill
        </h3>
        <ul class="m-subheader__breadcrumbs m-nav m-nav--inline">
          <li class="m-nav__item m-nav__item--home">
            <a href="#" class="m-nav__link m-nav__link--icon">
              <i class="m-nav__link-icon la la-home"></i>
            </a>
          </li>
          <li class="m-nav__separator">
            -
          </li>
          <li class="m-nav__item">
            <a href="<?php echo base_url().'dashboard'?>" class="m-nav__link">
              <span class="m-nav__link-text">
                Home
              </span>
            </a>
          </li>
          <li class="m-nav__separator">
            -
          </li>
          <li class="m-nav__item">
            <a href="<?php echo base_url().'stock/transfer_history' ?>" class="m-nav__link">
              <span class="m-nav__link-text">
                Stock Transfer Bill
              </span>
            </a>
          </li>


        </ul>
      </div>
      <div>

      </div>
    </div>
  </div>
  <!-- END: Subheader -->
  <div class="m-content">
    <div class="m-portlet m-portlet--full-height">
      <div class="m-portlet__head">
        <div class="m-portlet__head-caption">
          <div class="m-portlet__head-title">
            <h3 class="m-portlet__head-text">

            </h3>
          </div>
        </div>
        <div class="m-portlet__head-tools" >
          <!-- <a style="margin-left: 5px;margin-right: 5px" data-toggle="modal" href="#transfer_bill_payment_add_modal" class="btn m-btn--gradient-from-warning m-btn--gradient-to-danger  m-btn  m-btn--icon m-btn--air m-btn--pill">
          <span>
          <i class="la la-plus"></i>
          <span>
          Add Payment
        </span>
      </span>
    </a> -->
    <a style="margin-left: 5px;margin-right: 5px"id="btn_print" onclick="window.print()"class="btn m-btn--gradient-from-warning m-btn--gradient-to-danger  m-btn  m-btn--icon m-btn--air m-btn--pill">
      <span>
        <i class="la la-print"></i>
        <span>
          Print
        </span>
      </span>
    </a>
  </div>
</div>
<div class="m-portlet__body m-portlet__body--no-padding" id="print_view">
  <?php if($this->config->item('company_letter_head')!=''){ ?>
    <!-- <img style="max-width: 1000px" src="<?php // echo base_url().'uploads/company/'.$this->config->item('company_letter_head')?>" /> -->
  <?php } ?>
  <div class="m-invoice-2" style="padding-bottom: 20px">
    <div  class="m-invoice__wrapper">
      <div class="m-invoice__head" >
        <div class="m-invoice__container m-invoice__container--centered">
          <div class="m-invoice__logo" style="padding-top: 3rem;">
            <a href="#">

            </a>
          </div>
          <div class="row">
            <div class="col-md-8" style="border-right: 1px solid #ebedf2;">

            </div>
            <div class="col-md-4">
              <div class="m-invoice__logo" style="padding-top: 0px;">
                <a href="#">

                  <h2>Bill No #<?php echo $bill_data->bill_id ?>
                    <br/>STOCK TRANSFER ESTIMATION</h2>
                  </a>
                </div>
              </div>
            </div>
            <div class="m-invoice__items" style="padding: 2rem 0 3rem 0;">
              <div class="m-invoice__item">
                <span class="m-invoice__subtitle">TRANSFER FROM </span>
                <span class="m-invoice__text"><strong><?php echo $bill_data->transferred_from_loc_name?><br/>
                  <?php if($bill_data->transferred_from_work_id!=0){ echo $bill_data->transferred_from_loc_address;} ?></strong></span>
                </div>
                <div class="m-invoice__item" style="text-align: right;">
                  <span class="m-invoice__subtitle">TRANSFER TO </span>
                  <span class="m-invoice__text"><strong><?php echo $bill_data->transferred_to_loc_name?><br/>
                    <?php if($bill_data->transferred_to_work_id!=0){ echo $bill_data->transferred_to_loc_address;} ?></strong></span>
                  </div>
                </div>
                <div class="m-invoice__items" style="padding: 2rem 0 3rem 0;">
                  <div class="m-invoice__item" style="text-align: left">
                    <span class="m-invoice__subtitle">TRANSFER DATE</span>
                    <span class="m-invoice__text"><strong><?php echo date('d-m-Y',strtotime($bill_data->bill_date))?></strong></span>
                  </div>
                  <div class="m-invoice__item" style="text-align: center">
                    <span class="m-invoice__subtitle">CREATED BY</span>
                    <span class="m-invoice__text"><strong><?php echo $bill_data->user_alias?></strong></span>
                  </div>
                  <div class="m-invoice__item" style="text-align: right">
                    <span class="m-invoice__subtitle">Vehicle No</span>
                    <span class="m-invoice__text"><strong><?php echo $bill_data->vehicle_no?></strong></span>
                  </div>
                </div>
              </div>
            </div>
            <div class="m-invoice__body m-invoice__body--centered" style="min-height: 200px">
              <div class="table-responsive">
                <table class="table m-table table-bordered item_table">
                  <thead>
                    <tr>
                      <th>Sl No</th>
                      <th style="text-align: left">Material Name</th>
                      <th>HSN</th>
                      <th>Unit</th>
                      <th>Unit Price</th>
                      <th>Transferred Qty</th>
                      <th>Total Amount</th>
                    </tr>
                  </thead>
                  <tbody>
                    <?php
                    $n = 1;
                    foreach($bill_items as $row):
                      ?>
                      <tr>
                        <td><?php echo $n++?></td>
                        <td style="text-align: left"><?php echo $row->material_name?></td>
                        <td><?php echo $row->item_code?></td>
                        <td><?php echo $row->unit_name?></td>
                        <td><?php echo $this->config->item('Currency_currency_format')." ".$this->config->item('currency_format')->formatCurrency($row->unit_price,$this->config->item('Currency_currency_shortname'));?></td>
                        <td><?php echo $row->transferred_qty?></td>
                        <td><?php echo $this->config->item('Currency_currency_format')." ".$this->config->item('currency_format')->formatCurrency($row->total_amount,$this->config->item('Currency_currency_shortname'));?></td>
                      </tr>
                      <?php
                    endforeach;
                    ?>
                    <tr>
                      <td colspan="6" style="text-align:center">TOTAL BILL AMOUNT</td>
                      <td><strong><?php echo $this->config->item('Currency_currency_format')." ".$this->config->item('currency_format')->formatCurrency($bill_data->total_bill_amount,$this->config->item('Currency_currency_shortname'));?></strong></td>
                    </tr>
                  </tbody>
                </table>
              </div>
            </div>

          </div>


        </div>
      </div>
    </div>
    <div class="modal fade" tabindex="-1" id="transfer_bill_payment_add_modal" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
      <div class="modal-dialog " role="document" style="max-width: 800px">
        <div class="modal-content">
          <div class="modal-header" style="background-color: #00c5dc;border-radius: 4px">
            <h5 class="modal-title" id="exampleModalLabel" style="color: #ffffff" >
              Add New Transaction                                            </h5>
              <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">
                  &times;
                </span>
              </button>
            </div>
            <form autocomplete="off" data-form-type="transfer_bill_payment_add" data-modal-id="transfer_bill_payment_add_modal" id="form_transfer_bill_payment_add" method="post" action="<?php echo base_url().'stock/create_transfer_bill_payment' ?>" enctype="multipart/form-data" class="m-form m-form--fit m-form--state m-form--label-align-right " >
              <div class="modal-body" id="form_transfer_bill_payment_add_body">
                <div class="m-form__content">
                  <div class="m-alert m-alert--icon alert alert-warning m--hide" role="alert" id="form_transfer_bill_payment_add_msg">
                    <div class="m-alert__icon">
                      <i class="la la-warning"></i>
                    </div>
                    <div class="m-alert__text">
                      Oh snap! Change a few things up and try submitting again.
                    </div>
                    <div class="m-alert__close">
                      <button type="button" class="close" data-close="alert" aria-label="Close"></button>
                    </div>
                  </div>
                </div>
                <div style="background: white;border: 4px solid #f7f7fa;padding: 0px;margin: 0px;padding-bottom: 0px">
                  <div class="m-section" style="margin: 0px 0 10px 0;">
                    <h3 class="m-section__heading" style="padding: 10px;margin: 0px">Transaction Details</h3>
                    <div class="row" style="padding-top: 15px" >
                      <div class="col-lg-4" >
                        <div class="form-group m-form__group" >
                          <label id="label_paid_amount_add_transfer_bill_payment" for="user_name">
                            Paid Amount
                          </label>
                          <div class="m-input-icon m-input-icon--right">
                            <input required type="text" name="paid_amount" id="paid_amount_add_transfer_bill_payment" value="" class="form-control m-input m-input--pill m-input--air form_transfer_bill_payment_add_fields" placeholder="Transaction Amount" aria-describedby="basic-addon1">
                            <span class="m-input-icon__icon m-input-icon__icon--right"><span><?php echo $this->config->item('Currency_currency_format'); ?></span></span>
                          </div>
                          <span class="m-form__help"></span>
                        </div>
                      </div>
                      <div class="col-lg-4">
                        <div class="form-group m-form__group" >
                          <label id="label_paid_date_add_transfer_bill_payment" for="user_name">
                            Paid Date
                          </label>
                          <div class="m-input-icon m-input-icon--right">
                            <input required data-date-format="dd-mm-yyyy" id="paid_date_add_transfer_bill_payment"  type="text" name="paid_date" class="form_transfer_bill_payment_add_fields form-control m-input m-input--pill m-input--air " placeholder="Transaction Date" >
                            <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-calendar"></i></span></span>
                          </div>
                          <span class="m-form__help"></span>
                        </div>
                      </div>
                      <div class="col-lg-4">
                        <div class="form-group m-form__group" >
                          <label id="label_debit_acc_add_transfer_bill_payment" for="user_name">
                            Paid From Acc
                          </label>
                          <div class="m-select2 m-select2--air m-select2--pill">
                            <select required id="debit_acc_add_transfer_bill_payment" name="debit_acc" style="width: 100%" class="form-control m-input form_transfer_bill_payment_add_select paid_amount_req_fields"  aria-describedby="basic-addon1">
                              <?php
                              foreach($this->config->item('account_heads') as $row):
                                $selected="";
                                if($row->acc_head_id==1){
                                  $selected="selected";
                                }
                                ?>
                                <option <?php echo $selected?> value="<?php echo $row->acc_head_id?>"><?php echo $row->acc_head_name?></option>
                                <?php
                              endforeach;
                              ?>
                            </select>
                          </div>
                          <span class="m-form__help"></span>
                        </div>
                      </div>
                    </div>
                    <div class="row" >
                      <div class="col-lg-4">
                        <div class="form-group m-form__group" >
                          <label for="user_name">
                            Payment Mode
                          </label>
                          <div class="m-select2 m-select2--air m-select2--pill">
                            <select required id="payment_mode_add_transfer_bill_payment" name="payment_mode" style="width: 100%" class="form-control m-input form_transfer_bill_payment_add_select paid_amount_req_fields"  aria-describedby="basic-addon1">
                              <option selected disabled>Select Payment Mode</option>
                              <?php
                              foreach($this->config->item('payment_modes') as $row):
                                ?>
                                <option value="<?php echo $row?>"><?php echo $row?></option>
                                <?php
                              endforeach;
                              ?>
                            </select>
                          </div>
                          <span class="m-form__help"></span>
                        </div>
                      </div>
                      <div class="col-lg-4" >
                        <div class="form-group m-form__group" >
                          <label for="user_name">
                            TR Reference No
                          </label>
                          <div class="m-input-icon m-input-icon--right">
                            <input type="text" name="reference_no"  class="form-control m-input m-input--pill m-input--air form_transfer_bill_payment_add_fields" placeholder="Reference No" aria-describedby="basic-addon1">
                            <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-edit"></i></span></span>
                          </div>
                          <span class="m-form__help"></span>
                        </div>
                      </div>
                      <div class="col-lg-4">
                        <div class="form-group m-form__group" >
                          <label for="user_name">
                            TR Reference Date
                          </label>
                          <div class="m-input-icon m-input-icon--right">
                            <input type="text" data-date-format="dd-mm-yyyy" name="reference_date" id="reference_date_add_transfer_bill_payment"  class="form-control m-input m-input--pill m-input--air form_transfer_bill_payment_add_fields" placeholder="Reference Date" aria-describedby="basic-addon1">
                            <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-tag"></i></span></span>
                          </div>
                          <span class="m-form__help"></span>
                        </div>
                      </div>
                    </div>
                    <div class="row">
                      <div class="col-lg-8" >
                        <div class="form-group m-form__group" >
                          <label for="user_name">
                            Transaction Remarks
                          </label>
                          <div class="m-input-icon m-input-icon--right">
                            <input type="text" name="tr_remarks" class="form-control m-input m-input--pill m-input--air form_transfer_bill_payment_add_fields" placeholder="Transaction Remarks" aria-describedby="basic-addon1">
                            <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-edit"></i></span></span>
                          </div>
                          <span class="m-form__help"></span>
                        </div>
                      </div>
                    </div>
                  </div>
                  <input type="hidden" name="tr_type" value="stock_transfer_bill_bill_transaction">
                  <input type="hidden" name="reference_id" value="<?php echo $bill_data->bill_id?>">
                  <input type="hidden" name="reference_type" value="stock_transfer_bill">
                </div>
              </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-secondary " data-dismiss="modal">
                  Close
                </button>
                <button type="submit" class="btn btn-primary form_submit_btn">
                  Submit
                </button>
              </div>
            </form>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

<!-- end:: Body -->
<!-- begin::Footer -->

<?php $this->view("includes/Inc_footer");?>
<!-- end::Footer -->

<!-- end:: Page -->

<?php $this->view("includes/Inc_sidebar");?>
<?php $this->view("includes/Inc_scripts");?>
<!--begin::Page Snippets -->
<?php $this->view("modules/include_scripts/bill_scripts");?>


<script>
//    Toggle Sidebar
// $("#m_aside_left_minimize_toggle").addClass("m-brand__toggler--active");
// $("#body").addClass("m-brand--minimize m-aside-left--minimize");

$("#stock_menu").addClass('m-menu__item--active m-menu__item--open');
$("#stock_menu_2").addClass('m-menu__item--active');

</script>

<script>
$("#debit_acc_add_transfer_bill_payment").select2({
  placeholder: "Select TR Account",
  dropdownParent: $("#form_transfer_bill_payment_add")
})
$("#payment_mode_add_transfer_bill_payment").select2({
  placeholder: "Select TR Mode",
  dropdownParent: $("#form_transfer_bill_payment_add")
})
$("#paid_date_add_transfer_bill_payment,#reference_date_add_transfer_bill_payment").datepicker( {
  todayHighlight:!0, orientation:"bottom left", templates: {
    leftArrow: '<i class="la la-angle-left"></i>', rightArrow: '<i class="la la-angle-right"></i>'
  },
  endDate: '+0d',
  <?php if($this->session->userdata('user_role_id')>2 && $this->config->item('User_calendar_date_restriction_enabled')==1){ ?>
    startDate: '<?php echo $this->config->item('User_calendar_date_restriction_start_days');?>d'
    <?php } ?>
  })

  $('#payment_view_table').DataTable({
    "scrollX" : true,
    scrollX:!0, scrollCollapse:!0,
    dom:"<'row'<'col-sm-6 text-left'><'col-sm-6 text-right'f>>\n\t\t\t<'row'<'col-sm-12'tr>>\n\t\t\t<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7 dataTables_pager'lp>>", // horizobtal scrollable datatable
    "paging":   false,
    "ordering": false,
    "info":     false,
    searching: false
  });
  $(".form_submit_btn").click(function (e) {
    e.preventDefault();
    var a = $(this),
    l = $(this).closest("form"),
    action = l.attr('action');
    var form_id = l.attr('id');
    l.validate({
      rules: {
        "paid_amount": {
          required: !0,
          min: 0,
          number: !0
        }
      }, invalidHandler: function (e, r) {
        var i = $("#" + form_id + "_msg");
        i.removeClass("m--hide").show(), mUtil.scrollTo(i, -200)
      }, submitHandler: function (e) {
      }
    }), l.valid() && (a.addClass("m-loader m-loader--right m-loader--light").attr("disabled", !0),
    l.ajaxSubmit({
      url: action,
      success: function (e, t, r, s) {
        var modal_id = l.attr('data-modal-id');
        var form_type = l.attr('data-form-type');
        $("#" + form_id + "_msg").addClass("m--hide");
        // Block UI
        mApp.blockPage({
          overlayColor: "#000000",
          type: "loader",
          state: "success",
          message: "Please wait..."
        }), setTimeout(function () {
          mApp.unblockPage()
        }, 2e3);
        var obj = $.parseJSON(e);
        if (obj.status == 1) {
          a.removeClass("m-loader m-loader--right m-loader--light").attr("disabled", !1);
          $("#"+modal_id).modal('toggle');
          toastr[obj.flashdata_type](obj.flashdata_msg, obj.flashdata_title);
          location.reload();
        } else {
          a.removeClass("m-loader m-loader--right m-loader--light").attr("disabled", !1);
          toastr[obj.flashdata_type](obj.flashdata_msg, obj.flashdata_title);
        }
        if (obj == null) {
          setTimeout(function () {
            a.removeClass("m-loader m-loader--right m-loader--light").attr("disabled", !1);
            toastr["warning"]("Your Attempt is Timed Out. Please Try Again.", "Timed Out");
          }, 2e4)
        }
      },error: function() {
        a.removeClass("m-loader m-loader--right m-loader--light").attr("disabled", !1);
        toastr["error"]("Sorry. There Has Been Some Error Occurred. Please Try Again.", "Error");
      }
    })
  )
});

</script>
