<script src="<?php echo base_url() ?>my-assets/js/admin_js/json/service_quotation.js.php"></script>
<script src="<?php echo base_url() ?>my-assets/js/admin_js/json/productquotation.js"></script>
<?php 
$user_type = $this->session->userdata('user_type');
        $user_id = $this->session->userdata('id');?>
<div class="row">
    <div class="col-sm-12">
        <div class="panel panel-bd lobidrag">
            <div class="panel-heading">
                <div class="panel-title">
                    <h4><?php echo display('add_quotation') ?> </h4>
                </div>
            </div>
            <?php echo form_open('quotation/quotation/bdtask_insert_quotation', array('class' => 'form-vertical', 'id' => 'insert_quotation')) ?>
            <div class="panel-body">
                <div class="form-group row">
                    <div class="col-sm-6">
                        <label for="customer" class="col-sm-4 col-form-label"><?php echo display('customer') ?> <i
                                class="text-danger">*</i></label>
                        <div class="col-sm-8">

                            <?php if ($user_type == 3) { ?>
                            <input type="text" name="cname" value="<?php echo $this->session->userdata('user_name') ?>"
                                class="form-control" readonly>
                            <input type="hidden" name="customer_id"
                                value="<?php echo $this->session->userdata('user_id') ?>" class="form-control">
                            <?php } else { ?>
                            <select name="customer_id" required class="form-control" onchange="get_customer_info(this.value)"
                                data-placeholder="<?php echo display('select_one'); ?>">
                                <option value=""></option>
                                <?php
                                            foreach ($customers as $customer) {
                                                ?>
                                <option value="<?php echo $customer['customer_id'] ?>">
                                    <?php echo $customer['customer_name'] ?>
                                </option>
                                <?php } ?>
                            </select>
                            <?php } ?>
                        </div>
                    </div>
                    
                    <div class="col-sm-6">
                        <label for="qdate" class="col-sm-4 col-form-label"><?php echo display('quotation_date') ?><i
                                class="text-danger">*</i> </label>
                        <div class="col-sm-8">
                            <input type="text" required name="qdate" class="form-control datepicker" id="qdate"
                                value="<?php echo date('Y-m-d') ?>">
                        </div>
                    </div>
                </div>

                <div class="form-group row">
                    <div class="col-sm-6">
                        <label for="address" class="col-sm-4 col-form-label"><?php echo display('address') ?> <i
                                class="text-danger"></i></label>
                        <div class="col-sm-8">
                            <input type="text" name="address" class="form-control" value="" id="address" readonly>
                        </div>
                    </div>
                    <div class="col-sm-6">
                        <label for="expiry_date" class="col-sm-4 col-form-label"><?php echo display('expiry_date') ?> <i
                                class="text-danger">*</i> </label>
                        <div class="col-sm-8">
                            <input type="text" required name="expiry_date" class="form-control datepicker" id="expiry_date"
                                value="<?php echo date('Y-m-d') ?>">
                        </div>
                    </div>
                </div>

                <div class="form-group row">
                    <div class="col-sm-6">
                        <label for="mobile" class="col-sm-4 col-form-label"><?php echo display('mobile') ?> <i
                                class="text-danger"></i></label>
                        <div class="col-sm-8">
                            <input type="text" name="mobile" class="form-control" value="" id="mobile" readonly>
                        </div>
                    </div>
                    


                </div>
                <div class="form-group row">
                    <div class="col-sm-12">
                        <label for="details" class="col-sm-2 col-form-label"><?php echo display('details') ?> <i
                                class="text-danger"></i></label>
                        <div class="col-sm-10">
                            <textarea name="details" class="form-control" id="details"></textarea>
                        </div>
                    </div>
                </div>

                <div class="row">
                    <div class="col-sm-12">
                        <div class="table-responsive margin-top10">
                            <table class="table table-bordered table-hover" id="normalinvoice">
                                <thead>
                                    <tr>
                                        <th class="text-center product_field"><?php echo display('item_information') ?>
                                            <i class="text-danger">*</i>
                                        </th>
                                        <th class="text-center"><?php echo display('item_description')?></th>
                                        <th class="text-center"><?php echo display('batch_no')?><i class="text-danger"> *</i></th>
                                        <th class="text-center"><?php echo display('available_qnty') ?></th>
                                        <th class="text-center"><?php echo display('unit') ?></th>
                                        <th class="text-center"><?php echo display('quantity') ?> <i
                                                class="text-danger">*</i></th>
                                        <th class="text-center invoice_fields"><?php echo display('rate') ?> <i
                                                class="text-danger">*</i></th>

                                        <?php if ($discount_type == 1) { ?>
                                        <th class="text-center invoice_fields">
                                            <?php echo display('discount_percentage') ?> %</th>
                                        <?php } elseif ($discount_type == 2) { ?>
                                        <th class="text-center invoice_fields"><?php echo display('discount') ?> </th>
                                        <?php } elseif ($discount_type == 3) { ?>
                                        <th class="text-center invoice_fields"><?php echo display('fixed_dis') ?> </th>
                                        <?php } ?>
                                        <th class="text-center invoice_fields"><?php echo display('dis_val') ?> </th>
                                        <th class="text-center invoice_fields"><?php echo display('vat').' %' ?> </th>
                                        <th class="text-center invoice_fields"><?php echo display('vat_val') ?> </th>

                                        <th class="text-center invoice_fields"><?php echo display('total') ?>
                                        </th>
                                        <th class="text-center"><?php echo display('action') ?></th>
                                    </tr>
                                </thead>
                                <tbody id="addinvoiceItem">
                                    <tr>
                                        <td class="product_field">
                                            <input type="text" required name="product_name" onkeypress="invoice_productList(1);"
                                                class="form-control productSelection"
                                                placeholder='<?php echo display('product_name') ?>' id="product_name_1"
                                                tabindex="5">

                                            <input type="hidden" class="autocomplete_hidden_value product_id_1"
                                                name="product_id[]" id="SchoolHiddenId" />

                                            <input type="hidden" class="baseUrl" value="<?php echo base_url(); ?>" />
                                        </td>
                                        <td>
                                            <input type="text" name="desc[]" class="form-control text-right "
                                                tabindex="6" />
                                        </td>
                                        <td class="invoice_fields">
                                            <select class="form-control" required id="serial_no_1"
                                                onchange="invoice_product_batch(1)" name="serial_no[]" tabindex="7">
                                                <option></option>
                                            </select>
                                        </td>
                                        <td>
                                            <input type="text" name="available_quantity[]"
                                                class="form-control text-right available_quantity_1" value="0"
                                                readonly="" />
                                        </td>
                                        <td>
                                            <input name="" id="" class="form-control text-right unit_1 valid"
                                                value="None" readonly="" aria-invalid="false" type="text">
                                        </td>
                                        <td>
                                            <input type="text" required name="product_quantity[]"
                                                onkeyup="quantity_calculate(1);" onchange="quantity_calculate(1);"
                                                class="total_qntt_1 form-control text-right" id="total_qntt_1"
                                                placeholder="0.00" min="0" tabindex="8" value="1" />
                                        </td>
                                        <td>
                                            <input type="text" required name="product_rate[]" id="price_item_1"
                                                class="price_item1 price_item form-control text-right" tabindex="9"
                                                onkeyup="quantity_calculate(1);" onchange="quantity_calculate(1);"
                                                placeholder="0.00" min="0" />
                                            <input type="hidden" name="supplier_price[]" id="supplier_price_1">
                                        </td>
                                        <!-- Discount -->
                                        <td>
                                            <input type="text" name="discount[]" onkeyup="quantity_calculate(1);"
                                                onchange="quantity_calculate(1);" id="discount_1"
                                                class="form-control text-right" min="0" tabindex="10"
                                                placeholder="0.00" />
                                            <input type="hidden" value="<?php echo $discount_type?>"
                                                name="discount_type" id="discount_type_1">

                                        </td>

                                        <td>
                                            <input type="text" name="discountvalue[]" id="discount_value_1"
                                                class="form-control text-right" min="0" tabindex="18" placeholder="0.00"
                                                readonly />
                                        </td>

                                        <!-- VAT  -->
                                        <td>
                                            <input type="text" name="vatpercent[]" onkeyup="quantity_calculate(1);"
                                                onchange="quantity_calculate(1);" id="vat_percent_1"
                                                class="form-control text-right" min="0" tabindex="19"
                                                placeholder="0.00" />

                                        </td>
                                        <td>
                                            <input type="text" name="vatvalue[]" id="vat_value_1"
                                                class="form-control text-right total_vatamnt" min="0" tabindex="20"
                                                placeholder="0.00" readonly />
                                        </td>
                                        <!-- VAT end -->


                                        <td>
                                            <input class="total_price form-control text-right" type="text"
                                                name="total_price[]" id="total_price_1" value="0.00"
                                                readonly="readonly" />
                                        </td>

                                        <td>
                                            
                                            <!-- Tax calculate end-->

                                            <!-- Discount calculate start-->
                                            <input type="hidden" id="total_discount_1" class="" />
                                            <input type="hidden" id="all_discount_1" class="total_discount dppr"
                                                name="discount_amount[]" />
                                            <!-- Discount calculate end -->


                                        </td>
                                    </tr>
                                </tbody>
                                <tfoot>
                                    <tr>

                                        <td class="text-right" colspan="11">
                                            <b><?php echo display('invoice_discount') ?>:</b>
                                        </td>
                                        <td class="text-right">
                                            <input type="text" onkeyup="quantity_calculate(1);"
                                                onchange="quantity_calculate(1);" id="invoice_discount"
                                                class="form-control text-right total_discount" name="invoice_discount"
                                                placeholder="0.00" tabindex="13" />
                                            <input type="hidden" id="txfieldnum">
                                        </td>
                                        <td><a id="add_invoice_item" class="btn btn-success" name="add-invoice-item"
                                                onClick="addInputField('addinvoiceItem');" tabindex="11"><i
                                                    class="fa fa-plus"></i></a></td>
                                    </tr>

                                    <tr>
                                        <td class="text-right" colspan="11">
                                            <b><?php echo display('total_discount') ?>:</b>
                                        </td>
                                        <td class="text-right">
                                            <input type="text" id="total_discount_ammount"
                                                class="form-control text-right" name="total_discount" value="0.00"
                                                readonly="readonly" />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="text-right" colspan="11">
                                            <b><?php echo display('ttl_val') ?>:</b>
                                        </td>
                                        <td class="text-right">
                                            <input type="text" id="total_vat_amnt" class="form-control text-right"
                                                name="total_vat_amnt" value="0.00" readonly="readonly" />
                                        </td>
                                    </tr>
                                    

                                    <tr>
                                        <td colspan="11" class="text-right"><b><?php echo display('grand_total') ?>:</b>
                                        </td>
                                        <td class="text-right">
                                            <input type="text" id="grandTotal" class="form-control text-right"
                                                name="grand_total_price" value="0.00" readonly="readonly" />
                                        </td>
                                    </tr>





                                </tfoot>
                            </table>
                        </div>


                    </div>
                </div>

                <hr>
                <div>
                    <button type="button" class="btn btn-primary"
                        id="service_quotation_div"><?php echo display('add_service_quotation')?></button>
                </div>

                <div class="row" id="quotation_service">
                    <div class="col-sm-12">

                        <div class="table-responsive margin-top10">
                            <table class="table table-bordered table-hover" id="serviceInvoice">
                                <thead>
                                    <tr>
                                        <th class="text-center product_field"><?php echo display('service_name') ?> <i
                                                class="text-danger">*</i></th>
                                        <th class="text-center"><?php echo display('quantity') ?> <i
                                                class="text-danger">*</i></th>
                                        <th class="text-center invoice_fields"><?php echo display('charge') ?> <i
                                                class="text-danger">*</i></th>

                                        <?php if ($discount_type == 1) { ?>
                                        <th class="text-center"><?php echo display('discount_percentage') ?> %</th>
                                        <?php } elseif ($discount_type == 2) { ?>
                                        <th class="text-center"><?php echo display('discount') ?> </th>
                                        <?php } elseif ($discount_type == 3) { ?>
                                        <th class="text-center"><?php echo display('fixed_dis') ?> </th>
                                        <?php } ?>
                                        <th class="text-center invoice_fields"><?php echo display('dis_val') ?> </th>
                                        <th class="text-center invoice_fields"><?php echo display('vat').' %' ?> </th>
                                        <th class="text-center invoice_fields"><?php echo display('vat_val') ?> </th>
                                        <th class="text-center product_field"><?php echo display('total') ?>
                                        </th>
                                        <th class="text-center"><?php echo display('action') ?></th>
                                    </tr>
                                </thead>
                                <tbody id="addservicedata">
                                    <tr>
                                        <td class="product_field">
                                            <input type="text" name="service_name" onkeypress="invoice_serviceList(1);"
                                                class="form-control serviceSelection"
                                                placeholder='<?php echo display('service_name') ?>' id="service_name"
                                                tabindex="7">

                                            <input type="hidden" class="autocomplete_hidden_value service_id_1"
                                                name="service_id[]" />

                                            <input type="hidden" class="baseUrl" value="<?php echo base_url(); ?>" />
                                        </td>

                                        <td>
                                            <input type="text" name="service_quantity[]"
                                                onkeyup="serviceCAlculation(1);" onchange="serviceCAlculation(1);"
                                                class="total_service_qty_1 form-control text-right"
                                                id="total_service_qty_1" placeholder="0.00" min="0" tabindex="8" />
                                        </td>
                                        <td>
                                            <input type="text" name="service_rate[]" id="service_rate_1"
                                                class="service_rate1 service_rate form-control text-right" tabindex="9"
                                                onkeyup="serviceCAlculation(1);" onchange="serviceCAlculation(1);"
                                                placeholder="0.00" min="0" />

                                        </td>
                                        <!-- Discount -->
                                        <td>
                                            <input type="text" name="sdiscount[]" onkeyup="serviceCAlculation(1);"
                                                onchange="serviceCAlculation(1);" id="sdiscount_1"
                                                class="form-control text-right common_servicediscount"
                                                placeholder="0.00" min="0">
                                            <input type='hidden' value='' name='discount_type' id='sdiscount_type_1'>
                                        </td>

                                        <td>
                                            <input type="text" name="service_discountvalue[]"
                                                id="service_discount_value_1" class="form-control text-right" min="0"
                                                tabindex="18" placeholder="0.00" readonly />
                                        </td>

                                        <!-- VAT  -->
                                        <td>
                                            <input type="text" name="service_vatpercent[]"
                                                onkeyup="serviceCAlculation(1);" onchange="serviceCAlculation(1);"
                                                id="service_vat_percent_1" class="form-control text-right" min="0"
                                                tabindex="19" placeholder="0.00" />

                                        </td>
                                        <td>
                                            <input type="text" name="service_vatvalue[]" id="service_vat_value_1"
                                                class="form-control text-right service_total_vatamnt" min="0"
                                                tabindex="20" placeholder="0.00" readonly />
                                        </td>
                                        <!-- VAT end -->


                                        <td>
                                            <input class="total_serviceprice form-control text-right" type="text"
                                                name="total_service_amount[]" id="total_service_amount_1" value="0.00"
                                                readonly="readonly" />
                                        </td>

                                        <td>
                                            
                                            <input type="hidden" id="totalServiceDicount_1"
                                                class="totalServiceDicount_1">

                                            <input type="hidden" id="all_service_discount_1"
                                                class="totalServiceDicount sedppr" name="sdiscount_amount[]">

                                        </td>
                                    </tr>
                                </tbody>
                                <tfoot>

                                    <tr>
                                        <td class="text-right" colspan="7">
                                            <b><?php echo display('service_discount') ?>:</b>
                                        </td>
                                        <td class="text-right">
                                            <input type="text" onkeyup="serviceCAlculation(1);"
                                                onchange="serviceCAlculation(1);" id="service_discount"
                                                class="form-control totalServiceDicount text-right"
                                                name="service_discount" placeholder="0.00" />
                                            <input type="hidden" id="sertxfieldnum">
                                        </td>
                                        <td><button type="button" id="add_service_item" class="btn btn-success"
                                                name="add-invoice-item" onClick="addService('addservicedata');"><i
                                                    class="fa fa-plus"></i></button></td>
                                    </tr>
                                    <tr>

                                        <td class="text-right" colspan="7">
                                            <b><?php echo display('totalServiceDicount') ?>:</b>
                                        </td>
                                        <td class="text-right">
                                            <input type="text" id="total_service_discount"
                                                class="form-control text-right" name="totalServiceDicount" value="0.00"
                                                readonly="readonly" />
                                        </td>

                                    </tr>
                                    <tr>
                                        <td class="text-right" colspan="7">
                                            <b><?php echo display('ttl_val') ?>:</b>
                                        </td>
                                        <td class="text-right">
                                            <input type="text" id="service_total_vat_amnt"
                                                class="form-control text-right" name="service_total_vat_amnt"
                                                value="0.00" readonly="readonly" />
                                        </td>
                                    </tr>

                                    <tr>
                                        <td colspan="7" class="text-right"><b><?php echo display('grand_total') ?>:</b>
                                        </td>
                                        <td class="text-right">
                                            <input type="text" id="serviceGrandTotal" class="form-control text-right"
                                                name="grand_total_service_amount" value="0.00" readonly="readonly" />
                                            <input type="hidden" id="is_quotation" value="" name="">
                                            <input type="hidden" name="" value="<?php echo $discount_type?>"
                                                id="discount_type">
                                        </td>
                                    </tr>



                                </tfoot>
                            </table>
                        </div>

                    </div>
                </div>

                <div class="form-group row">
                    <label for="example-text-input" class="col-sm-4 col-form-label"></label>
                    <div class="col-sm-6">

                        <input type="submit" id="add-quotation" class="btn btn-success btn-large" name="add-quotation"
                            value="<?php echo display('save') ?>" />

                    </div>
                </div>
            </div>
            <?php echo form_close() ?>
        </div>
    </div>
</div>

<script src="<?php echo base_url() ?>my-assets/js/admin_js/json/quotation.js"></script>