var table 

    
    var table_invoice     =`
                            <html>

                              <head>
                                  <meta http-equiv=Content-Type content="text/html; charset=unicode">
                                  <meta name=Generator content="Microsoft Word 15 (filtered)">
                                  <style>
                                      <!--
                                      /* Font Definitions */
                                      
                                      @font-face {
                                          font-family: "Cambria Math";
                                          panose-1: 2 4 5 3 5 4 6 3 2 4;
                                      }
                                      
                                      @font-face {
                                          font-family: Calibri;
                                          panose-1: 2 15 5 2 2 2 4 3 2 4;
                                      }
                                      
                                      @font-face {
                                          font-family: "Calibri Light";
                                          panose-1: 2 15 3 2 2 2 4 3 2 4;
                                      }
                                      
                                      @font-face {
                                          font-family: "Century Gothic";
                                          panose-1: 2 11 5 2 2 2 2 2 2 4;
                                      }
                                      
                                      @font-face {
                                          font-family: "Sakkal Majalla";
                                          panose-1: 2 0 0 0 0 0 0 0 0 0;
                                      }
                                      /* Style Definitions */
                                      
                                      p.MsoNormal,
                                      li.MsoNormal,
                                      div.MsoNormal {
                                          margin-top: 0in;
                                          margin-right: 0in;
                                          margin-bottom: 8.0pt;
                                          margin-left: 0in;
                                          line-height: 105%;
                                          font-size: 11.0pt;
                                          font-family: "Calibri", sans-serif;
                                      }
                                      
                                      h2 {
                                          mso-style-link: "Heading 2 Char";
                                          margin: 0in;
                                          margin-bottom: .0001pt;
                                          page-break-after: avoid;
                                          font-size: 8.0pt;
                                          font-family: "Calibri Light", sans-serif;
                                          color: #262626;
                                          font-weight: normal;
                                      }
                                      
                                      p.MsoHeader,
                                      li.MsoHeader,
                                      div.MsoHeader {
                                          mso-style-link: "Header Char";
                                          margin: 0in;
                                          margin-bottom: .0001pt;
                                          font-size: 8.0pt;
                                          font-family: "Calibri", sans-serif;
                                          color: #262626;
                                      }
                                      
                                      a:link,
                                      span.MsoHyperlink {
                                          color: blue;
                                          text-decoration: underline;
                                      }
                                      
                                      a:visited,
                                      span.MsoHyperlinkFollowed {
                                          color: purple;
                                          text-decoration: underline;
                                      }
                                      
                                      span.Heading2Char {
                                          mso-style-name: "Heading 2 Char";
                                          mso-style-link: "Heading 2";
                                          font-family: "Calibri Light", sans-serif;
                                          color: #262626;
                                      }
                                      
                                      p.msonormal0,
                                      li.msonormal0,
                                      div.msonormal0 {
                                          mso-style-name: msonormal;
                                          margin-right: 0in;
                                          margin-left: 0in;
                                          font-size: 12.0pt;
                                          font-family: "Times New Roman", serif;
                                      }
                                      
                                      span.HeaderChar {
                                          mso-style-name: "Header Char";
                                          mso-style-link: Header;
                                          font-family: "Calibri", sans-serif;
                                          color: #262626;
                                      }
                                      
                                      p.msopapdefault,
                                      li.msopapdefault,
                                      div.msopapdefault {
                                          mso-style-name: msopapdefault;
                                          margin-right: 0in;
                                          margin-bottom: 8.0pt;
                                          margin-left: 0in;
                                          line-height: 105%;
                                          font-size: 12.0pt;
                                          font-family: "Times New Roman", serif;
                                      }
                                      
                                      p.msochpdefault,
                                      li.msochpdefault,
                                      div.msochpdefault {
                                          mso-style-name: msochpdefault;
                                          margin-right: 0in;
                                          margin-left: 0in;
                                          font-size: 10.0pt;
                                          font-family: "Times New Roman", serif;
                                      }
                                      
                                      p.Slogan,
                                      li.Slogan,
                                      div.Slogan {
                                          mso-style-name: Slogan;
                                          margin-top: 0in;
                                          margin-right: 0in;
                                          margin-bottom: 3.0pt;
                                          margin-left: 0in;
                                          font-size: 7.0pt;
                                          font-family: "Calibri", sans-serif;
                                          color: #A6A6A6;
                                          letter-spacing: .2pt;
                                          font-style: italic;
                                      }
                                      
                                      p.ContactInfo,
                                      li.ContactInfo,
                                      div.ContactInfo {
                                          mso-style-name: "Contact Info";
                                          margin-top: 26.0pt;
                                          margin-right: 0in;
                                          margin-bottom: 0in;
                                          margin-left: 0in;
                                          margin-bottom: .0001pt;
                                          text-align: center;
                                          font-size: 8.0pt;
                                          font-family: "Calibri", sans-serif;
                                          color: #A6A6A6;
                                      }
                                      
                                      p.ThankYou,
                                      li.ThankYou,
                                      div.ThankYou {
                                          mso-style-name: "Thank You";
                                          margin: 0in;
                                          margin-bottom: .0001pt;
                                          text-align: center;
                                          font-size: 9.0pt;
                                          font-family: "Calibri", sans-serif;
                                          color: #262626;
                                          font-weight: bold;
                                          font-style: italic;
                                      }
                                      
                                      span.companyphones {
                                          mso-style-name: company_phones;
                                      }
                                      
                                      span.companyemail {
                                          mso-style-name: company_email;
                                      }
                                      
                                      span.invoiceno {
                                          mso-style-name: invoice_no;
                                      }
                                      
                                      span.invoicedate {
                                          mso-style-name: invoice_date;
                                      }
                                      
                                      span.deliverystatus {
                                          mso-style-name: delivery_status;
                                      }
                                      
                                      span.destination {
                                          mso-style-name: destination;
                                      }
                                      
                                      .MsoChpDefault {
                                          font-size: 10.0pt;
                                      }
                                      
                                      @page WordSection1 {
                                          size: 841.9pt 595.3pt;
                                          margin: .5in .5in .5in .5in;
                                      }
                                      
                                      div.WordSection1 {
                                          page: WordSection1;
                                      }
                                      
                                      -->
                                  </style>

                              </head>

                              <body lang=EN-US link=blue vlink=purple>

                                  <div class=WordSection1>

                                      <div align=center>
                              `;


    function edit_items(itemid){
      
      
      $("#edit_objid").val(itemid);
      

      $.ajax({
          url: "models/crul_product.php",
          type:"POST",
          dataType : "JSON",
          data: {"type":"get_edit","obj_id":itemid} ,
          complete:function(){
            //hideLoader();
          },
          beforeSend:function(){
            //showLoader("Deleting Product");
          },
          success: function(res) {

            if(res.is_success == true){
                // console.log(res.data[0].product_name)
                $("#edit_category_id_fk").val(res.data[0].category_id_fk).selectpicker('refresh');

                $("#edit_product_name").val(res.data[0].product_name);
                $("#edit_sell_price").val(res.data[0].sell_price);
                $("#edit_cost_price").val(res.data[0].cost_price);
                $("#edit_product_note").val(res.data[0].product_note);
               

                $('#edit_form_cont').modal('toggle');

            }else{

              swal({
                      title: Translation("خطأ"),
                      text: Translation(res.data),
                      confirmButtonColor: "#2196F3",
                      type: "error"
                  });

            }
            
          }
      });
      

    }


     function remove_image(itemid,path) {
     
        swal({
            title: Translation("هل انت متأكد؟!"),
            text: Translation("سوف لن تستطيع استرجاع المعلومات المرتبطة بهذا السجل في حالة المسح"),
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#EF5350",
            confirmButtonText: Translation("موافق: امسح!"),
            cancelButtonText: Translation("الغاء الامر"),
            closeOnConfirm: false,
            closeOnCancel: true
        },
        function(isConfirm){
            if (isConfirm) {
              $.ajax({
                url: "models/crul_product.php",
                type:"POST",
                dataType : "JSON",
                data: {"type":"remove_image","obj_id":itemid,img_path:path} ,
                complete:function(){
                  //hideLoader();
                },
                beforeSend:function(){
                  //showLoader("Deleting Product");
            },
                success: function(res) {
                  if(res.is_success == true){
                    swal({
                                title: Translation("حذف"),
                                text: Translation(res.data),
                                confirmButtonColor: "#66BB6A",
                                type: "success"
                            });
                    $(".datatable-column-search-inputs").DataTable().ajax.reload(null, false);
                    $("#img_"+itemid).html('')
                  }else{
                    swal({
                                title: Translation("خطأ"),
                                text: Translation(res.data),
                                confirmButtonColor: "#2196F3",
                                type: "error"
                            });
                  }
                }
            });
            }
        }); // /confirm
    }



    function show_files(itemid,id) {
        

           attach = `
                      <div class="col-lg-3 col-sm-6">
                        <div class="thumbnail">
                          <div class="thumb">
                            <img src="`+itemid+`" alt="">
                            <div class="caption-overflow">
                              <span>
                                <a href="`+itemid+`" data-popup="lightbox" class="btn border-white text-white btn-flat btn-icon btn-rounded"><i class="icon-plus3"></i></a>
                                
                              </span>
                            </div>
                          </div>

                          <div class="caption">
                            <h6 class="no-margin"><a href="#" class="text-default">`+Translation('رقم الملف')+` : `+1+`</a> <a href="#" onclick="remove_image(`+id+`,'`+itemid+`');" class="text-muted"><i class="icon-trash text-danger pull-right"></i></a></h6>
                          </div>
                        </div>
                      </div>` ;
                    $("#file_attach").html(attach);
                    $('#show_files').modal('toggle');


    }



    function delete_items(itemid) {
        swal({
            title: Translation("هل انت متأكد؟!"),
            text: Translation("سوف لن تستطيع استرجاع المعلومات المرتبطة بهذا السجل في حالة المسح"),
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#EF5350",
            confirmButtonText: Translation("موافق: امسح!"),
            cancelButtonText: Translation("الغاء الامر"),
            closeOnConfirm: false,
            closeOnCancel: true
        },
        function(isConfirm){
            if (isConfirm) {
              $.ajax({
                url: "models/crul_product.php",
                type:"POST",
                dataType : "JSON",
                data: {"type":"delete","obj_id":itemid} ,
                complete:function(){
                  //hideLoader();
                },
                beforeSend:function(){
                  //showLoader("Deleting Product");
            },
                success: function(res) {
                  if(res.is_success == true){
                    swal({
                                title: Translation("حذف"),
                                text: Translation(res.data),
                                confirmButtonColor: "#66BB6A",
                                type: "success"
                            });
                    $(".datatable-column-search-inputs").DataTable().ajax.reload(null, false);
                  }else{
                    swal({
                                title: Translation("خطأ"),
                                text: Translation(res.data),
                                confirmButtonColor: "#2196F3",
                                type: "error"
                            });
                  }
                }
            });
            }
        }); // /confirm
    }



  

    function get_Category(){

      $.ajax({
                      url : 'models/crul_category.php',
                      type : 'POST',
                      data : {type:'get'},
                      dataType : 'json',
                      success : function(response) {
                        console.log(response)
                          var attach ='<option value="" selected="selected">'+Translation('اسم الصنف')+'</option>';
                          
                            for(var i=response.length-1 ; i >= 0;i--){
                              
                              attach = attach + '<option value="'+response[i][0]+'">'+response[i][1]+'</option>';
                             

                            }
                            $("#category_id_fk").html(attach);
                            $("#edit_category_id_fk").html(attach);
                            $("#product_category_id_fk").html(attach);
                            $('#category_id_fk').selectpicker('refresh');
                            $("#edit_category_id_fk").selectpicker('refresh');
                            $("#product_category_id_fk").selectpicker('refresh');
                      },
                      complete: function() {
                             //  me.data('requestRunning', false);
                      }

                }); // submit ajax

    }


    function print_product(){
      $("#print_modal").modal('toggle');
    }


    function show_invoice(itm,printing=null,detail_show=null){

          
          var headers           ='';
          var attach            = "";
          var attach_other      = "";
          var footers           ="";
          var customer_details  = "";
          var print_attach      = "";

          // var arab        =$("#arabic_check").is(":checked");
          // var kurd        =$("#kurd_check").is(":checked");


          var today = new Date();
          var dd = today.getDate();
          var mm = today.getMonth()+1; //January is 0!
          var yyyy = today.getFullYear();

          if(dd<10) {
              dd = '0'+dd
          } 

          if(mm<10) {
              mm = '0'+mm
          } 

          today = yyyy + '/' + mm + '/' + dd;


          $.ajax({
                url : 'models/crul_product.php',
                type : 'POST',
                data : {type:'print', category_id : itm},
                dataType : 'json',
                success : function(response) {
                    // console.log(response)
                    
                        headers =`
                                  <table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0 width="92%" style='width:92.0%;border-collapse:collapse'>
                                      <tr style='height:.25in'>
                                          <td width="33%" nowrap colspan=3 style='width:33.44%;border:none;border-bottom:  solid windowtext 1.0pt;padding:0in 5.4pt 0in 5.4pt;height:.25in'>
                                              <p class=Slogan style='line-height:105%'><span style='font-family:"Century Gothic",sans-serif'>
                                              <img   width=86 height=77 src="`+COMPANY_LOGO+`"></span></p>
                                              <p class=Slogan style='line-height:105%'>
                                                <b><span style='font-size:9.0pt;  line-height:105%;font-family:"Century Gothic",sans-serif;color:#FFC000'>
                                                `+Translation('Oscar Company')+` 
                                                </span>
                                              </b></p>
                                              
                                          </td>
                                          <td width="59%" colspan=14 style='width:59.32%;border:none;border-bottom:  solid windowtext 1.0pt;padding:0in 0in 0in 0in;height:.25in'>
                                              <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                                <span style='font-size:36.0pt;  font-family:"Century Gothic",sans-serif;color:#A6A6A6'>        
                                                </span>
                                                <span style='font-size:36.0pt;font-family:"Century Gothic",sans-serif;color:#A8D08D'> </span>
                                                <span style='font-size:36.0pt;font-family:"Century Gothic",sans-serif;color:#FFC000'>
                                                `+Translation('PRODUCT LIST')+`
                                                </span></p>
                                          </td>
                                          <td width="7%" nowrap style='width:7.24%;border:none;border-bottom:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:.25in'>
                                              <p class=MsoNormal dir=RTL style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:right;direction:rtl;unicode-bidi:embed'>
                                                <span dir=LTR><img width=31 height=62 src="image/sys/image005.gif"></span></p>
                                          </td>
                                      </tr>
                                      <tr style='height:25.15pt' align="center">
                                          <td width="23%" nowrap colspan=3 style='width:23.78%;border:solid windowtext 1.0pt;   border-top:none;padding:0in 5.4pt 0in 5.4pt;height:25.15pt'>
                                              <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;   text-align:center'>
                                                <b><span style='font-size:12.0pt;line-height:105%'>
                                                `+Translation('List No.')+`
                                                </span> 
                                              </b>
                                              </p>
                                          </td>
                                          
                                          <td width="11%" colspan=12 style='width:11.66%;border-top:none;border-left:   none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   padding:0in 0in 0in 0in;height:25.15pt'>
                                              
                                          </td>
                                          
                                          <td width="21%" nowrap colspan=3 style='width:21.94%;border-top:none;  border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   padding:0in 5.4pt 0in 5.4pt;height:25.15pt'>
                                              <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;   text-align:center;line-height:normal'>
                                                <b><span style='font-size:12.0pt'>
                                                `+Translation('Date')+`
                                                </span> </b>
                                              </p>
                                          </td>
                                      </tr>
                                      <tr style='height:26.95pt' align="center">
                                          <td width="23%" nowrap colspan=3 style='width:23.78%;border:solid windowtext 1.0pt;   border-top:none;padding:0in 5.4pt 0in 5.4pt;height:26.95pt'>
                                           <input type="text" value="1" style="text-align:center; border: hidden;">
                                          </td>
                                          
                                          <td width="11%" colspan=12 style='width:11.66%;border-top:none;border-left:   solid windowtext 1.0pt;border-bottom:solid windowtext 1.0pt;border-right:  none;padding:0in 0in 0in 0in;height:26.95pt'>
                                              
                                          </td>
                                          
                                          <td width="21%" nowrap colspan=3 style='width:21.94%;border-top:none;   border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:26.95pt'>
                                              `+today+`
                                          </td>
                                      </tr>`;
                        
                        

                      customer_details = ``;

                      attach =  `

                                    <tr style='height:26.0pt'>
                                        <td width="7%" nowrap style='width:7.28%;border:solid windowtext 1.0pt; border-top:none;padding:0in 5.4pt 0in 5.4pt;height:26.0pt'>
                                            <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                              <b><span style='color:black'>`+Translation('Item No.')+`</span>
                                              </b>
                                            </p>
                                        </td>
                                        <td width="37%" nowrap colspan=5 style='width:37.14%;border-top:none;  border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:26.0pt'>
                                            <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                              <b><span style='color:black'>`+Translation('Product Name')+`</span> </b></p>
                                        </td>
                                        <td width="7%" nowrap colspan=3 style='width:7.52%;border:solid windowtext 1.0pt;  border-left:none;padding:0in 5.4pt 0in 5.4pt;height:26.0pt'>
                                            <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                              <b><span style='color:black'>`+Translation('Code')+`</span></b>
                                            </p>
                                        </td>
                                        <td width="9%" nowrap colspan=4 style='width:9.24%;border:solid windowtext 1.0pt;  border-left:none;padding:0in 5.4pt 0in 5.4pt;height:26.0pt'>
                                            <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                              <b><span style='color:black'>`+Translation('Origin')+`</span></b>
                                            </p>
                                        </td>
                                        <td width="6%" style='width:6.32%;border:solid windowtext 1.0pt;border-left: none;padding:0in 0in 0in 0in;height:26.0pt'>
                                            <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                              <b>`+Translation('Type')+`</b>
                                            </p>
                                        </td>
                                        <td width="10%" style='width:10.56%;border:solid windowtext 1.0pt;border-left:  none;padding:0in 5.4pt 0in 5.4pt;height:26.0pt'>
                                            <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                              <b><span style='color:black'>`+Translation('Notes')+`</span></b>
                                            </p>
                                        </td>
                                        <td width="12%" nowrap style='width:12.38%;border-top:none;border-left:none;   border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:26.0pt'>
                                            <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                              <b><span style='color:black'>`+Translation('Property')+`</span> </b>
                                            </p>
                                        </td>
                                        <td width="9%" nowrap colspan=2 style='width:9.56%;border:solid windowtext 1.0pt;  border-left:none;padding:0in 5.4pt 0in 5.4pt;height:26.0pt'>
                                            <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                              <b><span style='color:black'>`+Translation('Sample')+`</span></b>
                                            </p>
                                        </td>
                                    </tr>`;
                     
                      // show sell item details                       
                      for(var i=0 ; i < response.invoice.length;i++){                        

                         
                          var arab_name ="";
                          var arab_desc ="";
                          var kurd_name ="";
                          var kurd_desc ="";

                          var product_prop="";

                          switch (response.invoice[i].product_type){

                            case "PVC":
                              product_prop= `
                                      <p class=MsoNormal style='font-weight:bold; margin-bottom:0in;margin-bottom:.0001pt;line-height:  normal'>
                                        <span style='font-size:10.0pt;font-family:"Times New Roman",serif'>
                                        Total Length : `+response.invoice[i].total_length+` m
                                        </span>
                                      </p>

                                      <p class=MsoNormal style='font-weight:bold; margin-bottom:0in;margin-bottom:.0001pt;line-height:  normal'>
                                        <span style='font-size:10.0pt;font-family:"Times New Roman",serif'>
                                        Total Area : `+response.invoice[i].total_area+` m<sup>2</sup>
                                        </span>
                                      </p>

                                      <p class=MsoNormal style='font-weight:bold; margin-bottom:0in;margin-bottom:.0001pt;line-height:  normal'>
                                        <span style='font-size:10.0pt;font-family:"Times New Roman",serif'>
                                        Color : `+response.invoice[i].color+` 
                                        </span>
                                      </p>`;
                              break;

                            case "RAW Wood":
                              product_prop= `<p class=MsoNormal style='font-weight:bold; margin-bottom:0in;margin-bottom:.0001pt;line-height:  normal'>
                                        <span style='font-size:10.0pt;font-family:"Times New Roman",serif'>
                                        Width : `+response.invoice[i].width+` cm
                                        </span>
                                      </p>

                                      <p class=MsoNormal style='font-weight:bold; margin-bottom:0in;margin-bottom:.0001pt;line-height:  normal'>
                                        <span style='font-size:10.0pt;font-family:"Times New Roman",serif'>
                                        Height : `+response.invoice[i].height+` cm
                                        </span>
                                      </p>

                                      <p class=MsoNormal style='font-weight:bold; margin-bottom:0in;margin-bottom:.0001pt;line-height:  normal'>
                                        <span style='font-size:10.0pt;font-family:"Times New Roman",serif'>
                                        Thickness : `+response.invoice[i].thickness+` mm
                                        </span>
                                      </p>`;
                              break;

                            case "Glue":
                              product_prop= `<p class=MsoNormal style='font-weight:bold; margin-bottom:0in;margin-bottom:.0001pt;line-height:  normal'>
                                        <span style='font-size:10.0pt;font-family:"Times New Roman",serif'>
                                        Liters : `+response.invoice[i].liter+` L
                                        </span>
                                      </p>`;
                              break;

                            case "Paint":
                              product_prop= `<p class=MsoNormal style='font-weight:bold; margin-bottom:0in;margin-bottom:.0001pt;line-height:  normal'>
                                        <span style='font-size:10.0pt;font-family:"Times New Roman",serif'>
                                        Liters : `+response.invoice[i].liter+` L
                                        </span>
                                      </p>
                                      <p class=MsoNormal style='font-weight:bold; margin-bottom:0in;margin-bottom:.0001pt;line-height:  normal'>
                                        <span style='font-size:10.0pt;font-family:"Times New Roman",serif'>
                                        Color : `+response.invoice[i].color+`
                                        </span>
                                      </p>`;
                              break;

                            default:
                              product_prop= '';

                           }

                          attach = attach + ` 

                                              <tr style='height:15.0pt' align="center">
                                                  <td width="7%" nowrap style='width:7.28%;border:solid windowtext 1.0pt;  border-top:none;padding:0in 5.4pt 0in 5.4pt;height:15.0pt'>
                                                      <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:  normal'>
                                                        `+response.invoice[i].product_id+`
                                                      </p>
                                                  </td>
                                                  <td width="37%" align="left" nowrap colspan=5 style='width:37.14%;border:none;border-bottom:  solid windowtext 1.0pt;padding:0in 5.4pt 0in 5.4pt;height:15.0pt'>
                                                      <p class=MsoNormal style='font-weight:bold; margin-bottom:0in;margin-bottom:.0001pt;line-height:  normal'>
                                                        <span style='font-size:10.0pt;font-family:"Times New Roman",serif'>
                                                        `+response.invoice[i].product_name+`
                                                        </span>
                                                      </p>
                                                     
                                                      

                                                      
                                                  </td>
                                                  <td width="7%" colspan=3 style='width:7.52%;border-top:none;border-left:solid windowtext 1.0pt; border-bottom:solid windowtext 1.0pt;border-right:solid black 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:15.0pt'>
                                                      <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                                        <b>
                                                        <span style='color:black'>
                                                        `+response.invoice[i].product_code+`
                                                        </span></b>
                                                      </p>
                                                  </td>
                                                  <td width="9%" nowrap colspan=4 style='width:9.24%;border-top:none; border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid gray 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:15.0pt'>
                                                      
                                                        `+response.invoice[i].made_in+`
                                                      
                                                  </td>
                                                  <td width="6%" style='width:6.32%;border-top:none;border-left:none;  border-bottom:solid windowtext 1.0pt;border-right:solid gray 1.0pt;  padding:0in 0in 0in 0in;height:15.0pt'>
                                                      <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:  normal'>
                                                        <span style='font-size:10.0pt;font-family:"Times New Roman",serif'>
                                                        `+response.invoice[i].product_type+`
                                                        </span>
                                                      </p>
                                                  </td>
                                                  <td width="10%" style='width:10.56%;border-top:none;border-left:none;  border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:15.0pt'>
                                                      `+(response.invoice[i].product_note)+`
                                                  </td>
                                                  <td width="12%" nowrap style='width:12.38%;border-top:none;border-left:none;  border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:15.0pt'>
                                                      `+(product_prop)+`

                                                  </td>
                                                  <td width="9%" nowrap colspan=2 style='width:9.56%;border-top:none; border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt;height:15.0pt'>
                                                      <img width="100%" src="`+response.invoice[i].image_path+`">
                                                  </td>
                                              </tr>`;
                        
                        
                       
                      } // for i

                      if(printing != null){
                        print_attach = `
                                        <script>
                                          window.print();
                                          window.onload = function() { window.print(); }
                                        </script>
                                        `;
                      }else{
                        print_attach = "";
                      }

                      footers =`

                                <tr style='height:6.0pt'>
                                    <td width="100%" colspan=18 valign=top style='width:100.0%;padding:0in 5.4pt 0in 5.4pt;  height:6.0pt'>
                                        <p class=ThankYou style='line-height:105%'>
                                        `+Translation('Thank you for your business!')+`
                                        </p>
                                    </td>
                                </tr>
                                <tr style='height:6.0pt'>
                                    <td width="100%" colspan=18 valign=top style='width:100.0%;padding:0in 5.4pt 0in 5.4pt;  height:6.0pt'>
                                        <p class=ContactInfo style='margin-top:12.0pt;line-height:105%'>
                                        <span lang=AR-KW dir=RTL style='font-size:10.0pt;line-height:105%;font-family:"Sakkal Majalla";  color:#7F7F7F'>
                                        `+Translation('شارع ١٠٠م محلة نازناز, مقابل مطار أربيل الدولي, أربيل, عراق')+`
                                        </span><span dir=LTR></span><span lang=AR-KW><span dir=LTR></span> </span>
                                        </p>
                                    </td>
                                </tr>
                                <tr style='height:.25in'>
                                    <td width="42%" nowrap colspan=5 style='width:42.02%;padding:0in 5.4pt 0in 5.4pt;  height:.25in'>
                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center'>
                                        `+COMPANY_PHONE+`
                                        </p>
                                    </td>
                                    <td width="16%" nowrap colspan=7 style='width:16.1%;padding:0in 5.4pt 0in 5.4pt;  height:.25in'>
                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center'>
                                        <span style='color:black'>`+Translation('www.oscar.co')+`</span> </p>
                                    </td>
                                    <td width="41%" nowrap colspan=6 style='width:41.86%;padding:0in 5.4pt 0in 5.4pt;  height:.25in'>
                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center'>
                                        <span style='color:black'>`+COMPANY_EMAIL+`</span></p>
                                    </td>
                                </tr>
                                <tr>
                                    <td width="7%" style='width:7.28%;padding:0in 0in 0in 0in'></td>
                                    <td width="16%" style='width:16.5%;padding:0in 0in 0in 0in'></td>
                                    <td width="9%" style='width:9.66%;padding:0in 0in 0in 0in'></td>
                                    <td width="3%" style='width:3.26%;padding:0in 0in 0in 0in'></td>
                                    <td width="9%" colspan=4 style='width:9.22%;padding:0in 0in 0in 0in'></td>
                                    <td width="6%" style='width:6.02%;padding:0in 0in 0in 0in'></td>
                                    <td width="3%" style='width:3.56%;padding:0in 0in 0in 0in'></td>
                                    <td width="5%" colspan=3 style='width:5.68%;padding:0in 0in 0in 0in'></td>
                                    <td width="6%" style='width:6.32%;padding:0in 0in 0in 0in'></td>
                                    <td width="10%" style='width:10.56%;padding:0in 0in 0in 0in'></td>
                                    <td width="12%" style='width:12.38%;padding:0in 0in 0in 0in'></td>
                                    <td width="2%" style='width:2.32%;padding:0in 0in 0in 0in'></td>
                                    <td width="7%" style='width:7.24%;padding:0in 0in 0in 0in'></td>
                                </tr>
                                <tr>
                                    <td width="7%" style='width:7.28%;padding:0in 0in 0in 0in'></td>
                                    <td width="16%" style='width:16.5%;padding:0in 0in 0in 0in'></td>
                                    <td width="9%" style='width:9.66%;padding:0in 0in 0in 0in'></td>
                                    <td width="3%" style='width:3.26%;padding:0in 0in 0in 0in'></td>
                                    <td width="8%" colspan=3 style='width:8.4%;padding:0in 0in 0in 0in'></td>
                                    <td width="0%" style='width:.82%;padding:0in 0in 0in 0in'></td>
                                    <td width="6%" style='width:6.02%;padding:0in 0in 0in 0in'></td>
                                    <td width="3%" style='width:3.56%;padding:0in 0in 0in 0in'></td>
                                    <td width="1%" style='width:1.66%;padding:0in 0in 0in 0in'></td>
                                    <td width="4%" colspan=2 style='width:4.02%;padding:0in 0in 0in 0in'></td>
                                    <td width="6%" style='width:6.32%;padding:0in 0in 0in 0in'></td>
                                    <td width="10%" style='width:10.56%;padding:0in 0in 0in 0in'></td>
                                    <td width="12%" style='width:12.38%;padding:0in 0in 0in 0in'></td>
                                    <td width="2%" style='width:2.32%;padding:0in 0in 0in 0in'></td>
                                    <td width="7%" style='width:7.24%;padding:0in 0in 0in 0in'></td>
                                </tr>
                                <tr height=0>
                                    <td width=76 style='border:none'></td>
                                    <td width=105 style='border:none'></td>
                                    <td width=69 style='border:none'></td>
                                    <td width=23 style='border:none'></td>
                                    <td width=38 style='border:none'></td>
                                    <td width=17 style='border:none'></td>
                                    <td width=5 style='border:none'></td>
                                    <td width=6 style='border:none'></td>
                                    <td width=41 style='border:none'></td>
                                    <td width=27 style='border:none'></td>
                                    <td width=13 style='border:none'></td>
                                    <td width=7 style='border:none'></td>
                                    <td width=23 style='border:none'></td>
                                    <td width=25 style='border:none'></td>
                                    <td width=91 style='border:none'></td>
                                    <td width=128 style='border:none'></td>
                                    <td width=12 style='border:none'></td>
                                    <td width=45 style='border:none'></td>
                                </tr>
                            </table>

                        </div>

                    </div>

                </body>



                  
                     `+print_attach+`
                    </html>`;

                      

                     
                },
                complete: function() {
                       //  me.data('requestRunning', false);
                       HTML_VIEW = table_invoice + headers + customer_details + attach + attach_other + footers;
                       //  me.data('requestRunning', false);
                        window.open().document.write(HTML_VIEW);
                }

          }); // submit ajax


    }

    function hide_item(itemid) {
      
       swal({
           title: Translation("Are You Sure!"),
           text: Translation("You will Hide All the Products Related to this Category!"),
           type: "warning",
           showCancelButton: true,
           confirmButtonColor: "#EF5350",
           confirmButtonText: Translation("Yes, Hide it!"),
           cancelButtonText: Translation("Cancel"),
           closeOnConfirm: false,
           closeOnCancel: true
       },
       function(isConfirm){
           if (isConfirm) {
             $.ajax({
               url: "models/crul_product.php",
               type:"POST",
               dataType: "JSON",
               data: {"type":"hide","obj_id":itemid} ,
               complete:function(){
                // hideLoader();
               },
               beforeSend:function(){
                // showLoader("Deleting Category");
               },
               success: function(res) {
                 if(res.is_success == true){
                   
                   $(".datatable-column-search-inputs").DataTable().ajax.reload(null, false);
                      swal({
                               title: Translation("تمت العملية"),
                               text: Translation(res.data),
                               confirmButtonColor: "#2196F3",
                               type: "success"
                           });
                  }else{
                      swal({
                               title: Translation("خطأ"),
                               text: Translation(res.data),
                               confirmButtonColor: "#2196F3",
                               type: "error"
                           });
                  }
               }
           });
           }
       }); // /confirm
    }

    function show_item(itemid) {
      
       swal({
           title: Translation("Are You Sure!"),
           text: Translation("You will Show All the Products Related to this Category!"),
           type: "warning",
           showCancelButton: true,
           confirmButtonColor: "#EF5350",
           confirmButtonText: Translation("Yes, Show it!"),
           cancelButtonText: Translation("Cancel"),
           closeOnConfirm: false,
           closeOnCancel: true
       },
       function(isConfirm){
           if (isConfirm) {
             $.ajax({
               url: "models/crul_product.php",
               type:"POST",
               dataType: "JSON",
               data: {"type":"show","obj_id":itemid} ,
               complete:function(){
                // hideLoader();
               },
               beforeSend:function(){
                // showLoader("Deleting Category");
               },
               success: function(res) {
                 if(res.is_success == true){
                   
                   $(".datatable-column-search-inputs").DataTable().ajax.reload(null, false);
                      swal({
                               title: Translation("تمت العملية"),
                               text: Translation(res.data),
                               confirmButtonColor: "#2196F3",
                               type: "success"
                           });
                  }else{
                      swal({
                               title: Translation("خطأ"),
                               text: Translation(res.data),
                               confirmButtonColor: "#2196F3",
                               type: "error"
                           });
                  }
               }
           });
           }
       }); // /confirm
    }


   


$(document).ready(function() {
  
    get_Category();
    // get_Items();

 




   

    $('#add_form').submit(function(event) {
      event.preventDefault();
            

      var category_id_fk            = $("#category_id_fk").val();
      
      var product_name              = $("#product_name").val();
      var product_type              = $("#product_type").val();
      var product_code              = $("#product_code").val();
      var barcode                   = $("#barcode").val();
      var made_in                   = $("#made_in").val();     
      var product_note              = $("#product_note").val();
      var color                     = $("#color").val();
      var image_path                = $("#image_path").val();
      var product_min_notification  = $("#product_min_notification").val();
      


      var Check1 = true;
      var Check2 = true;
      var Check3 = true;
      var Check4 = true;
      var Check5 = true;
      var Check6 = true;

      

      
      Check2 = Checks('product_name');
      Check3 = Checks('product_type');
      Check4 = Checks('product_code');
      
      var formData = new FormData(this);

      

      formData.append("type", 'create');



      if(Check1 && Check2 && Check3 && Check4 && Check5 && Check6){
            $("#submit_add_btn").attr('disabled',true);
            $.ajax({
                url: "models/crul_product.php",
                type:"POST",
                dataType : "JSON",
                data:formData,
                cache:false,
                contentType: false,
                processData: false
            })
            .done(function(res) {

                if(res.is_success == true){

                    $("#add_form")[0].reset();
                    $("#category_id_fk").val('').selectpicker('refresh');
                    $('.tokenfield').tokenfield();
                    $("#property_div").attr('style','display:none;');

                    
                    $(".datatable-column-search-inputs").DataTable().ajax.reload(null, false);
                    $("#add-form-cont").collapse('hide');
                    noty({
                            width: 200,
                            text: Translation(res.data),
                            type: 'success',
                            dismissQueue: true,
                            timeout: 3000,
                            layout: 'topRight',
                          });
                    
                    
                    $("#submit_add_btn").attr('disabled',true);
                    
                }else{
                    swal({
                        title: Translation("خطأ"),
                        text: Translation(res.data),
                        confirmButtonColor: "#66BB6A",
                        type: "warning"
                    });
                    //$("#add-form-cont").collapse('hide');
                }
                $("#submit_add_btn").attr('disabled',false);
            })
            .fail(function(err) {
                $("#submit_add_btn").attr('disabled',false);
                 swal({
                    title: Translation("خطأ"),
                    text: (err),
                    confirmButtonColor: "#66BB6A",
                    type: "error"
                });
                
            })
            .always(function() {
                console.log("complete");
            });
        }

    });



    // submit editable Visa Application form
    $('#edit_form').submit(function(event) {
              event.preventDefault();
              

              var Check1 = true;
              var Check2 = true;
              var Check3 = true;
              var Check4 = true;
              var Check5 = true;
              var Check6 = true;

              
              Check2 = Checks('edit_product_name');
              // Check3 = Checks('edit_sell_price');
             
              var formData = new FormData(this);

              formData.append("type", 'update');


              if(Check1 && Check2 && Check3 && Check4 && Check5 && Check6){

                  $.ajax({
                      url: "models/crul_product.php",
                      type:"POST",
                      dataType : "JSON",
                      data:formData,
                      cache:false,
                      contentType: false,
                      processData: false,
                      complete:function(){
                        
                      },
                      beforeSend:function(){
                        
                      },
                      success: function(res) {
                        if(res.is_success == false){
                          $('#edit_form_cont').modal('toggle');
                          $("#edit_form")[0].reset();
                          swal({
                              title: Translation("خطأ"),
                              text: Translation(res.data),
                              confirmButtonColor: "#66BB6A",
                              type: "warning"
                          });
                        }else{
                          $("#edit_form")[0].reset();
                          $(".datatable-column-search-inputs").DataTable().ajax.reload(null, false);

                          $('#edit_form_cont').modal('toggle');
                          noty({
                                          width: 200,
                                          text: Translation(res.data), //'Product Successfully Update',
                                          type: 'success',
                                          dismissQueue: true,
                                          timeout: 3000,
                                          layout: 'topRight',
                                    });
                        }
                      }
                  });
                }
    });


    $('#print_form').on('submit', function(e){

        e.preventDefault();

        var name        = $("#product_category_id_fk").val();

       
        
        
        show_invoice(name)


    });
});


$('#add_new_category_form').on('submit', function(e){

    e.preventDefault();

    block = $(this).parent();
      // \block

   var name        = $("#objname").val();
    var cat_desc    = $("#category_description").val();

    var Check1 = true;
    var Check2 = true;

    if(name =='') {
       $("#objname").closest('.form-group').removeClass('has-success');
       $("#objname").closest('.form-group').addClass('has-error');
       Check1 = false;
       noty({
                width: 200,
                text: Translation("الرجاء قم بادخال اسم الفئة"),
                type: 'error',
                dismissQueue: true,
                timeout: 3000,
                layout: 'top',
          });
    }else{
       $("#objname").closest('.form-group').removeClass('has-error');
       $("#objname").closest('.form-group').addClass('has-success');
    }

  

    if(Check1 && Check2){
      $("#submit_add_cat_btn").attr('disabled',true);
        $.ajax({
            url: "models/crul_category.php",
            type:"POST",
            dataType : "JSON",
            data : {name:name,category_description:cat_desc,type:'create'}
        })
        .done(function(res) {
          //alert(res);
          if(res.is_success == true){
                  $("#add_new_category_form")[0].reset();
                  $(".datatable-column-search-inputs").DataTable().ajax.reload(null, false);
                  $('#add_new_category').modal('toggle');
                  $('#category_id').selectpicker('refresh');
                  get_Category();
              noty({
                              width: 200,
                              text: Translation(res.data),
                              type: 'success',
                              dismissQueue: true,
                              timeout: 3000,
                              layout: 'topRight',
                        });
          }else{
              swal({
                  title: Translation("خطأ"),
                  text: Translation(res.data),
                  confirmButtonColor: "#66BB6A",
                  type: "error"
              });
          }
          $("#submit_add_cat_btn").attr('disabled',false);
        })
        .fail(function(err) {
           swal({
              title:  Translation("خطأ"),
              text:   Translation(err),
              confirmButtonColor: "#66BB6A",
              type: "error"
            });
           $("#submit_add_cat_btn").attr('disabled',false);
        })
        .always(function() {
            console.log("complete");
        });
    }


});




$(function() {
//var singleSelect = $('.datatable-column-search-inputs').DataTable();
    
   // for image uploader

   // Modal template
    var modalTemplate = '<div class="modal-dialog modal-lg" role="document">\n' +
        '  <div class="modal-content">\n' +
        '    <div class="modal-header">\n' +
        '      <div class="kv-zoom-actions btn-group">{toggleheader}{fullscreen}{borderless}{close}</div>\n' +
        '      <h6 class="modal-title">{heading} <small><span class="kv-zoom-title"></span></small></h6>\n' +
        '    </div>\n' +
        '    <div class="modal-body">\n' +
        '      <div class="floating-buttons btn-group"></div>\n' +
        '      <div class="kv-zoom-body file-zoom-content"></div>\n' + '{prev} {next}\n' +
        '    </div>\n' +
        '  </div>\n' +
        '</div>\n';

    // Buttons inside zoom modal
    var previewZoomButtonClasses = {
        toggleheader: 'btn btn-default btn-icon btn-xs btn-header-toggle',
        fullscreen: 'btn btn-default btn-icon btn-xs',
        borderless: 'btn btn-default btn-icon btn-xs',
        close: 'btn btn-default btn-icon btn-xs'
    };

    // Icons inside zoom modal classes
    var previewZoomButtonIcons = {
        prev: '<i class="icon-arrow-left32"></i>',
        next: '<i class="icon-arrow-right32"></i>',
        toggleheader: '<i class="icon-menu-open"></i>',
        fullscreen: '<i class="icon-screen-full"></i>',
        borderless: '<i class="icon-alignment-unalign"></i>',
        close: '<i class="icon-cross3"></i>'
    };

    // File actions
    var fileActionSettings = {
        zoomClass: 'btn btn-link btn-xs btn-icon',
        zoomIcon: '<i class="icon-zoomin3"></i>',
        dragClass: 'btn btn-link btn-xs btn-icon',
        dragIcon: '<i class="icon-three-bars"></i>',
        removeClass: 'btn btn-link btn-icon btn-xs',
        removeIcon: '<i class="icon-trash"></i>',
        indicatorNew: '<i class="icon-file-plus text-slate"></i>',
        indicatorSuccess: '<i class="icon-checkmark3 file-icon-large text-success"></i>',
        indicatorError: '<i class="icon-cross2 text-danger"></i>',
        indicatorLoading: '<i class="icon-spinner2 spinner text-muted"></i>'
    };




    //
    // AJAX upload
    //

    $(".file-input-ajax").fileinput({
        uploadUrl: "http://localhost", // server upload action
        uploadAsync: true,
        maxFileCount: 8,
        allowedFileExtensions: ["jpg", "gif", "png", "jpeg"],
          maxFileSize: 3000,
        initialPreview: [],
        fileActionSettings: {
            removeIcon: '<i class="icon-bin"></i>',
            removeClass: 'btn btn-link btn-xs btn-icon',
            uploadIcon: '<i class="icon-upload"></i>',
            uploadClass: 'btn btn-link btn-xs btn-icon',
            zoomIcon: '<i class="icon-zoomin3"></i>',
            zoomClass: 'btn btn-link btn-xs btn-icon',
            indicatorNew: '<i class="icon-file-plus text-slate"></i>',
            indicatorSuccess: '<i class="icon-checkmark3 file-icon-large text-success"></i>',
            indicatorError: '<i class="icon-cross2 text-danger"></i>',
            indicatorLoading: '<i class="icon-spinner2 spinner text-muted"></i>',
        },
        layoutTemplates: {
            icon: '<i class="icon-file-check"></i>',
            modal: modalTemplate
        },
        initialCaption: "No file selected",
        previewZoomButtonClasses: previewZoomButtonClasses,
        previewZoomButtonIcons: previewZoomButtonIcons
    });





   // end image uploader



   // Setting datatable defaults
    $.extend( $.fn.dataTable.defaults, {
        autoWidth: false,
        columnDefs: [{ 
            orderable: false,
            width: '100px',
            targets: [ 10 ]
        }],
        dom: '<"datatable-header"fBl><"datatable-scroll"t><"datatable-footer"ip>',
        language: {
            search: '<span>'+Translation('بحث')+':</span> _INPUT_',
            searchPlaceholder: Translation('بحث عن')+'...',
            lengthMenu: '<span>'+Translation('عرض')+':</span> _MENU_',
            paginate: { 'first': 'First', 'last': 'Last', 'next': '&'+Left_Arraw+'arr;', 'previous': '&'+Right_Arraw+'arr;' }
        },
        drawCallback: function () {
            $(this).find('tbody tr').slice(-3).find('.dropdown, .btn-group').addClass('dropup');
        },
        preDrawCallback: function() {
            $(this).find('tbody tr').slice(-3).find('.dropdown, .btn-group').removeClass('dropup');
        }
    });


    

    // Individual column searching with text inputs
    $('.datatable-column-search-inputs tfoot td').not(':last-child').each(function () {
        var title = $('.datatable-column-search-inputs thead th').eq($(this).index()).text();
        $(this).html('<input type="text" class="form-control input-sm" placeholder="'+Translation('بحث عن')+' '+title+'" />');
    });
    

  
    
  var query_id = getQueryVariable("id");
  var query_tp = getQueryVariable("tp");
   
  var table = $('.datatable-column-search-inputs').DataTable({
        // rowReorder: {
        //     selector: 'tr'
        // },

        // fixedHeader: true,
        keys: {
            className: 'focus focus-success'
        },

        buttons: {            
            buttons: [
                {
                    extend: 'copyHtml5',
                    className: 'btn btn-default',
                    exportOptions: {
                        columns: [ 0, ':visible' ]
                    }
                },
                {
                    extend: 'excelHtml5',
                    className: 'btn btn-default',
                    exportOptions: {
                        columns: ':visible'
                    }
                },
                {
                    extend: 'pdfHtml5',
                    className: 'btn btn-default',
                    exportOptions: {
                        columns: ':visible'
                    }
                },
                {
                    extend: 'print',
                    className: 'btn btn-default',
                    exportOptions: {
                        columns: ':visible'
                    }
                },
                {
                    extend: 'colvis',
                    text: '<i class="icon-three-bars"></i> <span class="caret"></span>',
                    className: 'btn bg-blue btn-icon'
                }
                
                
                
            ]
        },
        lengthMenu: [
            [  10, 25, 50, 100,-1 ],
            [  '10', '25', '50', '100','All' ]
        ],

        

        "processing": true,
        "serverSide": true,
        "ajax": {
        "url" : "models/crul_product.php",
        "data": function(d){
          d.type = "load";
          if(query_id !='not'){
            d.id =query_id ;
          }
          if(query_tp !='not'){
            d.tp =query_tp ;
          }
        }
        },
        drawCallback: function() {
                  $('[data-popup=tooltip]').tooltip();
                  $('[data-popup=popover-custom]').popover({
                    template: '<div class="popover  border-teal-400"><div class="arrow"></div><h3 class="popover-title bg-teal-400"></h3><div class="popover-content"></div></div>'
                  });

            },

        "columnDefs": [
          
          { 
              "targets": 8,
              "data": null,
              "render": function (data,type,row) {

                    if(IS_VIEW==0){

                            if(row[7]==0){
                                var status= `<li class='text-danger-600'>
                                                <a  class='text-warning' onclick="hide_item(`+row[0]+`)" data-popup='tooltip' data-original-title='`+Translation('Hide Product')+`'>
                                                    <i class='icon-eye-blocked'></i>
                                                </a>
                                            </li>`;
                            }else{
                                var status= `<li class='text-danger-600'>
                                                    <a  class='text-success-400' onclick="show_item(`+row[0]+`)" data-popup='tooltip' data-original-title='`+Translation('Show Product')+`'>
                                                        <i class='icon-eye'></i>
                                                    </a>
                                                </li>`;
                            }


                            return  `<ul class='icons-list text-center'>
                                        
                                        <li class='text-pink-600'>
                                            <a  onclick="show_files('`+row[6]+`',`+row[0]+`)" class='text-teal-400' data-popup='tooltip' data-original-title='`+Translation('عرض صور المادة')+`'>
                                                <i class='icon-images2'></i>
                                            </a>
                                        </li>
                                        ${status}
                                        <li class='text-primary-600'>
                                            <a  class='text-primary-400' onclick="edit_items(`+row[0]+`)" data-popup='tooltip' data-original-title='`+Translation('تعديل')+`'>
                                                <i class='icon-pencil7'></i>
                                            </a>
                                        </li>

                                        <li class='text-danger-600'>
                                            <a  class='text-danger-400' onclick="delete_items(`+row[0]+`)" data-popup='tooltip' data-original-title='`+Translation('حذف')+`'>
                                                <i class='icon-trash'></i>
                                            </a>
                                        </li>

                                    </ul>`;
                    }else{
                      return '';
                    }
                        }
          },


            

          // {
          //       "render": function(data, type, row){

          //             if(data != null && data !='' && data != undefined){
                        
          //               var tags = data.split('; ');
          //               var attach = ``;
          //               for(var i=0; i<tags.length; i++){
          //                 attach =  attach + `<label class="badge badge-info">`+tags[i]+`</label>`;
          //               }
          //               return  attach;
                      
          //             }else{
          //               return data;
          //             }
                   
                      
                   
          //       },
          //       "targets": 2
          //   },
            
            {
               "render": function(data, type, row){

                        if(data == null){
                          return  `<a href='index.php?p=product&id=`+row[8]+`'  data-popup='tooltip' data-original-title='`+Translation('عرض جميع المواد التابعة لهذا الفئة')+`'>General</a>`;

                        }else{
                          return  `<a href='index.php?p=product&id=`+row[8]+`'  data-popup='tooltip' data-original-title='`+Translation('عرض جميع المواد التابعة لهذا الفئة')+`'>`+data+`</a>`;

                        }


               },
               "targets": 5
            },

            
            {
               "render": function(data, type, row){


                        return  currency_format_display(data);


               },
               "targets": 2
            },

            {
               "render": function(data, type, row){


                        return  currency_format_display(data);


               },
               "targets": 3
            },
           
            
            
            
            {
                "render": function(data, type, row){

                      if(data == null || data ==''){
                        
                        return  ` <img  src="assets/images/placeholder.jpg" class=" text-center img-rounded img-lg">   `;
                      }else{
                        return  `<a  onclick="show_files('`+row[6]+`',`+row[0]+`)"> <img height="100" src="`+data +`" class="img-rounded img-">  </a>`;

                      }
                   
                      
                   
                },
                "targets": 6
            },

            {
             "render": function(data, type, row){

                   if(data ==0){
                     status = '<span class="label bg-success  btn-block ">'+Translation('Show')+'  </span>';
                   }else {
                     status = '<span class="label bg-violet  btn-block ">'+Translation('Hidden')+'  </span>';
                   }
                      // return  `<a href='index.php?p=invoice&id=`+row[0]+`'  data-popup='tooltip' data-original-title='Show All Invoices for this Customer'>`+data+`</a>`;
                      return  status;


             },
             "targets": 7
          },

           
            
        ],
        "fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {


            if(   aData[9] == 0 ){
                $(nRow).children().each(function (index, td) {
                    $(this).addClass('warning-active');
                });
            }
        },
        "order": [[0,'desc']],
        "displayLength": 25,


        initComplete: function () {
         
        // $("div.datatable-header").append(`<a  style="margin-left:15px;" class="btn bg-info-400"  id="headerBtn" onclick="add_item()"> <i class="icon-file-pdf position-right"></i> Add Category </a>`);   
         if(IS_VIEW==0){


            $("div.datatable-header").append(`<a data-toggle="collapse"
                                      style="margin-left:10px;"
                                      data-target="#add-form-cont"
                                      href="javascript:;"
                                      aria-controls="add-form-cont"
                                      aria-expanded="false"
                                      class="btn btn-primary"
                                      id="add_Item_Btn">
                                        <i class="`+CURRENT_BTN_ICON+`"></i> `+Translation(CURRENT_BTN)+`
                                    </a>`); 
        }

        $("div.datatable-header").append(`&nbsp;<div class="btn-group">
                          <button id="print_product" type="button"
                          class="btn bg-purple-400 btn-labeled " onclick="print_product();"><b><i class="icon-printer2">
                          </i></b> <span id="inv_filter">`+Translation('طباعة المواد')+`</span> </button>
                          
                      </div>`);
 
          //   invoce_filter_btn_label(); 


            this.api().columns().every( function() {
                var column = this;
                

            });
        }
    });

    
    table.columns().every( function () {
        var that = this;
        $('input', this.footer()).on('keyup change', function () {
            that.search(this.value).draw();
        });
    });

    // high light row and column
    var lastIdx = null;
     
    $('.datatable-highlight tbody').on('mouseover', 'td', function() {
        var chk_inx =table.cell(this).index();
        if(chk_inx != undefined && chk_inx !=null && chk_inx !='' ){ // because child row
          var colIdx = table.cell(this).index().column;

          if (colIdx !== lastIdx) {
              $(table.cells().nodes()).removeClass('active');
              $(table.column(colIdx).nodes()).addClass('active');
          }
        }
        
    }).on('mouseleave', function() {
        $(table.cells().nodes()).removeClass('active');
    });

    // end highlight row and column

    //child row
    // Add event listener for opening and closing details
    $('.datatable-column-search-inputs tbody').on('click', 'td.details-control', function () {
        var tr = $(this).closest('tr');
        
        var row = table.row( tr );
 
        if ( row.child.isShown() ) {
            // This row is already open - close it
            row.child.hide();
            tr.removeClass('shown');
            $(this).html('<i class="icon-add text-success"></i>');
        }
        else {
            // Open this row
            row.child( format(row.data()) ).show();
            tr.addClass('shown');
            $(this).html('<i class="icon-subtract text-danger"></i>');

        }
    } );
   
    // Single row selection
    
    $('.datatable-column-search-inputs tbody').on('click', 'tr', function() {
        if ($(this).hasClass('success')) {
            $(this).removeClass('success');
        }
        else {
            table.$('tr.success').removeClass('success');
            $(this).addClass('success');
        }
    });


         // change filter to top
    $('.datatable-column-search-inputs tfoot tr').insertAfter($('.datatable-column-search-inputs thead tr'))


    $('.dataTables_length select').select2({
        minimumResultsForSearch: Infinity,
        width: 'auto'
    });


});



