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);
      get_Zone();
      get_Sub_Zone();
      get_Quarter();
      get_Street();

      $.ajax({
          url: "models/crul_pharmacy.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_city_id_fk").val(res.data[0].city_id_fk).selectpicker('refresh');
                $("#edit_zone_id_fk").val(res.data[0].zone_id_fk).selectpicker('refresh');
                $("#edit_sub_zone_id_fk").val(res.data[0].sub_zone_id_fk).selectpicker('refresh');
                $("#edit_quarter_id_fk").val(res.data[0].quarter_id_fk).selectpicker('refresh');
                $("#edit_street_id_fk").val(res.data[0].street_id_fk).selectpicker('refresh');

                // $('.set-multiple-values').selectpicker('val', ['NV','AZ']);
                var ids =['','','','','','','','','','','','','','','','','','','','','','','','',
                          '','','','','','','','','','','','','','','','','','','','','','','',
                          '','','','','','','','','','','','','','','','','','','','','','','',
                          '','','','','','','','','','','','','','','','','','','','','','','',
                          '','','','','','','','','','','','','','','','','','','','','','','',
                          '','','','','','','','','','','','','','','','','','','','','','',''];

                var data = res.data[0].doctor_id_fk;
                var tags = data.split(';');
                var attach = ``;
                for(var i=0; i<tags.length; i++){
                  // attach =  attach + `'`+tags[i]+`',`;
                  ids[i] =  tags[i];
                }

                attach1 = attach.slice(0,-1);
                


                $("#edit_doctor_id_fk").selectpicker('val',[ids[0],
                                                            ids[1],
                                                            ids[2],
                                                            ids[3],
                                                            ids[4],
                                                            ids[5],
                                                            ids[6],
                                                            ids[7],
                                                            ids[8],
                                                            ids[9],
                                                            ids[10],
                                                            ids[11],
                                                            ids[12],
                                                            ids[13],
                                                            ids[14],
                                                            ids[15],
                                                            ids[16],
                                                            ids[17],
                                                            ids[18],
                                                            ids[19],
                                                            ids[20],
                                                            ids[21],
                                                            ids[22],
                                                            ids[23],
                                                            ids[24],
                                                            ids[25],
                                                            ids[26],
                                                            ids[27],
                                                            ids[28],
                                                            ids[29],
                                                            ids[30],
                                                            ids[31],
                                                            ids[32],
                                                            ids[33],
                                                            ids[34],
                                                            ids[35],
                                                            ids[36],
                                                            ids[37],
                                                            ids[38],
                                                            ids[39],
                                                            ids[40],
                                                            ids[41],
                                                            ids[42],
                                                            ids[43],
                                                            ids[44],
                                                            ids[45],
                                                            ids[46],
                                                            ids[47],
                                                            ids[48],
                                                            ids[49],
                                                            ids[50],

                                                            ]);

                // $("#edit_doctor_id_fk").val(attach1).selectpicker('refresh');

                $("#edit_pharmacy_name").val(res.data[0].pharmacy_name);
                $("#edit_pharmacy_address").val(res.data[0].pharmacy_address);
                $("#edit_pharmer_name").val(res.data[0].pharmer_name);
                $("#edit_pharmacy_phone").val(res.data[0].pharmacy_phone);
                $("#edit_pharmacy_type").val(res.data[0].pharmacy_type);
                $("#edit_pharmacy_note").val(res.data[0].pharmacy_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_pharmacy.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_pharmacy.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_City(){

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

                            }
                            $("#city_id_fk").html(attach);
                            $("#edit_city_id_fk").html(attach);
                            $('#city_id_fk').selectpicker('refresh');
                            $("#edit_city_id_fk").selectpicker('refresh');

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

                }); // submit ajax

    }

    function get_Zone(id=0){

      $.ajax({
                      url : 'models/crul_zone.php',
                      type : 'POST',
                      data : {
                                id:id,
                                type:'get_with_id'},
                      dataType : 'json',
                      success : function(response) {
                        console.log(response)
                          var attach ='<option value="" selected="selected">'+Translation('Select Zone')+'</option>';
                          
                            for(var i=response.length-1 ; i >= 0;i--){
                              
                              attach = attach + '<option value="'+response[i][0]+'">'+response[i][1]+'</option>';
                             

                            }
                            $("#zone_id_fk").html(attach);
                            $("#edit_zone_id_fk").html(attach);
                            $('#zone_id_fk').selectpicker('refresh');
                            $("#edit_zone_id_fk").selectpicker('refresh');

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

                }); // submit ajax

    }

    function get_Sub_Zone(id=0){

      $.ajax({
                      url : 'models/crul_sub_zone.php',
                      type : 'POST',
                      data : {

                              id:id,
                              type:'get_with_id'},
                      dataType : 'json',
                      success : function(response) {
                        console.log(response)
                          var attach ='<option value="" selected="selected">'+Translation('Select Sub Zone')+'</option>';
                          
                            for(var i=response.length-1 ; i >= 0;i--){
                              
                              attach = attach + '<option value="'+response[i][0]+'">'+response[i][1]+'</option>';
                             

                            }
                            $("#sub_zone_id_fk").html(attach);
                            $("#edit_sub_zone_id_fk").html(attach);
                            $('#sub_zone_id_fk').selectpicker('refresh');
                            $("#edit_sub_zone_id_fk").selectpicker('refresh');

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

                }); // submit ajax

    }

    function get_Quarter(id=0){

      $.ajax({
                      url : 'models/crul_quarter.php',
                      type : 'POST',
                      data : {

                              id:id,
                              type:'get_with_id'},
                      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>';
                             

                            }
                            $("#quarter_id_fk").html(attach);
                            $("#edit_quarter_id_fk").html(attach);
                            $('#quarter_id_fk').selectpicker('refresh');
                            $("#edit_quarter_id_fk").selectpicker('refresh');

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

                }); // submit ajax

    }

    function get_Street(id=0){

      $.ajax({
                      url : 'models/crul_street.php',
                      type : 'POST',
                      data : {

                              id:id,
                              type:'get_with_id'},
                      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>';
                             

                            }
                            $("#street_id_fk").html(attach);
                            $("#edit_street_id_fk").html(attach);
                            $('#street_id_fk').selectpicker('refresh');
                            $("#edit_street_id_fk").selectpicker('refresh');

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

                }); // submit ajax

    }

    function get_Doctor(id=0){

      $.ajax({
                url : 'models/crul_doctor.php',
                type : 'POST',
                data : {
                          id:id,
                          type:'get_with_id'},
                dataType : 'json',
                success : function(response) {
                    var attach ='';
                    
                    for(var i=response.length-1 ; i >= 0;i--){
                        
                        attach = attach + '<option value="'+response[i].doctor_id+'">'+response[i].doctor_name+'</option>';
                       

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

            }); // submit ajax

    }

    function get_Doctor_edit(id=0){

      $.ajax({
                url : 'models/crul_doctor.php',
                type : 'POST',
                data : {
                          id:id,
                          type:'get_with_id'},
                dataType : 'json',
                success : function(response) {
                    var attach ='';
                    
                    for(var i=response.length-1 ; i >= 0;i--){
                        
                        attach = attach + '<option value="'+response[i].doctor_id+'">'+response[i].doctor_name+'</option>';
                       

                    }
                      $("#edit_doctor_id_fk").html(attach);
                      $("#edit_doctor_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


    }


   


$(document).ready(function() {
  
    get_City();
    get_Doctor_edit();
    // get_Items();
    $('#doctor_id_fk').selectpicker('refresh');

  
    $("#city_id_fk").on('change',function(e){    
      var ID   = $(this).val();
      get_Zone(ID);
      get_Doctor(ID);

    });

     

  $("#zone_id_fk").on('change',function(e){    
      var ID   = $(this).val();
      get_Sub_Zone(ID);
  });

  $("#sub_zone_id_fk").on('change',function(e){    
      var ID   = $(this).val();
      get_Quarter(ID);
  });

  $("#quarter_id_fk").on('change',function(e){    
      var ID   = $(this).val();
      get_Street(ID);
  });


  $("#edit_city_id_fk").on('change',function(e){    
      var ID   = $(this).val();
      get_Zone(ID);
  });

  $("#edit_zone_id_fk").on('change',function(e){    
      var ID   = $(this).val();
      get_Sub_Zone(ID);
  });

  $("#edit_sub_zone_id_fk").on('change',function(e){    
      var ID   = $(this).val();
      get_Quarter(ID);
  });

  $("#edit_quarter_id_fk").on('change',function(e){    
      var ID   = $(this).val();
      get_Street(ID);
  });

  $("#delete_city_id_fk").on('change',function(e){    
      var ID   = $(this).val();
      get_Zone(ID);
  });

  $("#delete_zone_id_fk").on('change',function(e){    
      var ID   = $(this).val();
      get_Sub_Zone(ID);
  });

  $("#delete_sub_zone_id_fk").on('change',function(e){    
      var ID   = $(this).val();
      get_Quarter(ID);
  });

  $("#delete_quarter_id_fk").on('change',function(e){    
      var ID   = $(this).val();
      get_Street(ID);
  });




   

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

     


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

      

    
      
      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_pharmacy.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();
                    $("#city_id_fk").val('').selectpicker('refresh');
                    $("#zone_id_fk").val('').selectpicker('refresh');
                    $("#sub_zone_id_fk").val('').selectpicker('refresh');
                    $("#quarter_id_fk").val('').selectpicker('refresh');
                    $("#street_id_fk").val('').selectpicker('refresh');
                    
                    $('#doctor_id_fk').selectpicker('deselectAll');

                    
                    $('.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;

              
              
              var formData = new FormData(this);

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


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

                  $.ajax({
                      url: "models/crul_pharmacy.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',
                                    });
                        }
                      }
                  });
                }
    });



    $('#delete_form').submit(function(event) {
      event.preventDefault(); 
      
      var formData = new FormData(this);

      

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



      $("#submit_delete_btn").attr('disabled',true);
      $.ajax({
          url: "models/crul_pharmacy.php",
          type:"POST",
          dataType : "JSON",
          data:formData,
          cache:false,
          contentType: false,
          processData: false
      })
      .done(function(res) {

          if(res.is_success == true){

              $("#delete_form")[0].reset();
              $("#city_id_fk").val('').selectpicker('refresh');
              $("#zone_id_fk").val('').selectpicker('refresh');
              $("#sub_zone_id_fk").val('').selectpicker('refresh');
              $("#quarter_id_fk").val('').selectpicker('refresh');
              $("#street_id_fk").val('').selectpicker('refresh');
               
              $(".datatable-column-search-inputs").DataTable().ajax.reload(null, false);
              $("#delete-cont").collapse('hide');
              noty({
                      width: 200,
                      text: Translation(res.data),
                      type: 'success',
                      dismissQueue: true,
                      timeout: 3000,
                      layout: 'topRight',
                    });
              
              
              $("#submit_delete_btn").attr('disabled',true);
              
          }else{
              swal({
                  title: Translation("خطأ"),
                  text: Translation(res.data),
                  confirmButtonColor: "#66BB6A",
                  type: "warning"
              });
              //$("#add-form-cont").collapse('hide');
          }
          $("#submit_delete_btn").attr('disabled',false);
      })
      .fail(function(err) {
          $("#submit_delete_btn").attr('disabled',false);
           swal({
              title: Translation("خطأ"),
              text: (err),
              confirmButtonColor: "#66BB6A",
              type: "error"
          });
          
      })
      .always(function() {
          console.log("complete");
      });
      

    });


    $('#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_cid = getQueryVariable("cid");
  var query_zid = getQueryVariable("zid");
  var query_sid = getQueryVariable("sid");
   
  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_pharmacy.php",
        "data": function(d){
          d.type = "load";
          if(query_id !='not'){
            d.id =query_id ;
          }
          if(query_sid !='not'){
            d.sid =query_sid ;
          }
          if(query_zid !='not'){
            d.zid =query_zid ;
          }
          if(query_cid !='not'){
            d.cid =query_cid ;
          }

          if(PROFILE_TYPE < 3){
            d.city_id =CITY_ID ;
          }
        }
        },
        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": 13,
              "data": null,
              "render": function (data,type,row) {

                    if(IS_VIEW==0){

                      var btn= ``;

                      if(PROFILE_TYPE > 2){
                        btn = `<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 icon-2x'></i>
                                  </a>
                              </li>`
                      }


                            return  `<ul class='icons-list text-center'>
                                        
                                        <li class='text-pink-600'>
                                            <a  onclick="show_files('`+row[13]+`',`+row[0]+`)" class='text-teal-400' data-popup='tooltip' data-original-title='`+Translation('عرض صور المادة')+`'>
                                                <i class='icon-images2 icon-2x'></i>
                                            </a>
                                        </li>
                                        
                                        <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 icon-2x'></i>
                                            </a>
                                        </li>

                                       ${btn}

                                    </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="label label-info">`+tags[i]+`</label>`;
                        }
                        return  attach;
                      
                      }else{
                        return data;
                      }
                   
                      
                   
                },
                "targets": 6
            },
            
            {
               "render": function(data, type, row){

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

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

                        }


               },
               "targets": 1
            },

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


                  if(data ==0 ){
                     status=  `<span class="label label-success btn-block ">By Hand</span>`;
                  }else if(data ==1){
                     status = '<span class="label bg-orange-400  btn-block ">By Doctor</span>';
                  }else if(data ==2){
                     status = '<span class="label bg-danger  btn-block ">Mixed</span>';
                  }else{
                      status = '<span class="label bg-purple  btn-block ">'+data+'</span>';
                  }
                  return  status;


               },
               "targets": 4
            },
           
            
            
            
            // {
            //     "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[7]+`',`+row[0]+`)"> <img height="100" src="`+data +`" class="img-rounded img-">  </a>`;

            //           }
                   
                      
                   
            //     },
            //     "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>`); 
          }

          if(PROFILE_TYPE >4){


            

            $("div.datatable-header").append(`<a data-toggle="collapse"
                                      style="margin-left:10px;"
                                      data-target="#delete-cont"
                                      href="javascript:;"
                                      aria-controls="delete-cont"
                                      aria-expanded="false"
                                      class="btn btn-danger"
                                      id="delete_Btn">
                                        <i class="icon-trash"></i> `+Translation('حذف')+`
                                    </a>`); 

            
          }

       


            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'
    });


});



