var table 
    var HTML_VIEW_PAY = '';
    var print_page =  `
                        <script>
                          window.print();
                          window.onload = function() { window.print(); }
                        </script>
                        `;
    var HTML_Table = `
                      <!DOCTYPE html>
                      <html lang="ar" dir="rtl">
                      <head>
                        <meta charset="utf-8">
                        <meta http-equiv="X-UA-Compatible" content="IE=edge">
                        <style>

                          .print {  
                            -webkit-print-color-adjust: exact !important;
                          }
                          
                          .table0_td {
                            
                            border:none;
                            padding:0in 0pt 0in 0pt;
                            height:9.95pt
                            
                          }
                          
                          .table0_td1 {
                            
                            border:none;
                            border-bottom:solid #984806 1.0pt;
                            padding:0in 0pt 0in 0pt;
                            height:9.95pt
                            
                          }
                          
                          
                          
                          .table1_td {
                            
                            border:solid #984806 1.0pt;
                            border-left-color: white;
                            background:#984806;
                            padding:0pt 0pt 0pt 0pt;
                            height:.1in
                            
                          }
                          
                          .last_td {
                            border-left-color: #984806 !important;
                          }
                          
                          .table1_td1 {
                            
                            border:solid #984806 1.0pt;
                            border-top:none;
                            background:white;
                            padding:0pt 0pt 0pt 0pt;
                            height:.1in
                            
                          }
                          
                          .table2_td {
                            
                            border:solid #984806 1.0pt;
                            border-left-color: white;
                            background:#984806;
                            padding:0pt 0pt 0pt 0pt;
                            height:.1in;
                            
                          }
                          
                          .td_head {
                            text-align: center;
                            
                            color : white;
                            height: .3in;
                          }
                          
                          .td_body {
                            text-align: center;
                            
                            color : black;
                            height: .2in;
                            border:solid #984806 1.0pt;
                          }
                          
                          #inv_table tr:nth-child(odd) {
                            background-color: #FDE9D9;
                          }
                          
                          @font-face {
                            font-family: "Noto Kufi Arabic";
                            src: url(assets/custom_font/NotoKufiArabic-Regular.ttf) format("truetype");
                            }
                          
                          .badge {
                            display: inline-block;
                            min-width: 10px;
                            padding: 3px 7px;
                            font-size: 12px;
                            font-weight: 500;
                            color: #fff;
                            line-height: 1.5384616;
                            vertical-align: middle;
                            white-space: nowrap;
                            text-align: center;
                            background-color: #999999;
                            border-radius: 10px;
                          } 
                          
                          .badge {
                            padding: 1px 1px 1px 1px;
                            font-size: 10px;
                            letter-spacing: 0px;
                            vertical-align: baseline;
                            
                          }
                          
                          .bg-orange-400 {
                            background-color: #FFA726;
                            border-color: #FFA726;
                            color: #fff;
                          }
                          
                          .col-sm-4 {
                            width: 33.33333333%;
                          }
                          
                          .col-sm-3 {
                            width: 25%;
                          }

                        </style>

                      </head>

                      <body class="print" style=" font-family: 'Noto Kufi Arabic', Times, serif;">
                        <div align=center>
                      `;

    var table_invoice     =`
                            <html>

                              <head>
                                  <meta http-equiv=Content-Type content="text/html; charset=utf-8">
                                  <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;
                                      }
                                      /* 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;
                                      }
                                      
                                      
                                      
                                      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: 595.3pt 841.9pt;
                                          margin: .3in .3in .3in .3in;
                                      }
                                      
                                      div.WordSection1 {
                                          page: WordSection1;
                                      }
                                      
                                      -->

                                      .print {  
                                      
                                      }

                                      @media print {
                                        -webkit-print-color-adjust: exact !important;  
                                        body {-webkit-print-color-adjust: exact !important;}  
                                      }

                                      body {-webkit-print-color-adjust: exact !important;}
                                  </style>

                              </head>

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

                                  <div class=WordSection1>

                                      <div align=center>
                            `;
   


    var table_stickers = `

                          <html>

                            <head>
                                <meta http-equiv=Content-Type content="text/html; charset=utf-8">
                                <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;
                                    }
                                    /* Style Definitions */
                                    
                                    p.MsoNormal,
                                    li.MsoNormal,
                                    div.MsoNormal {
                                        margin-top: 0in;
                                        margin-right: 0in;
                                        margin-bottom: 8.0pt;
                                        margin-left: 0in;
                                        line-height: 107%;
                                        font-size: 11.0pt;
                                        font-family: "Calibri", sans-serif;
                                    }
                                    
                                    .MsoPapDefault {
                                        margin-bottom: 8.0pt;
                                        line-height: 107%;
                                    }
                                    
                                    @page WordSection1 {
                                        size: 841.9pt 595.3pt;
                                        margin: .5in .5in .5in .5in;
                                    }
                                    
                                    div.WordSection1 {
                                        page: WordSection1;
                                    }
                                    
                                    -->
                                </style>

                            </head>

                            <body lang=EN-US>

                                <div class=WordSection1>

                                    <div align=center>`;


    
   




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

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

          $.ajax({
                url : 'models/crul_review.php',
                type : 'POST',
                data : {type:'show_invoice', id : itm},
                dataType : 'json',
                success : function(response) {
                    // console.log(response)
                    
                        headers =`
                                  <table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0 width="96%" style='width:96.0%;border-collapse:collapse'>
                                      <tr>
                                          <td width=705 colspan=9 style='width:528.6pt;border:solid windowtext 1.5pt;  padding:0in 5.4pt 0in 5.4pt'>
                                              <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'><b><span style='font-size:14.0pt'>
                                              ORDER FORM
                                              </span></b></p>
                                          </td>
                                      </tr>
                                      <tr>
                                          <td width=119 colspan=2 style='width:89.25pt;border-top:none;border-left:  solid windowtext 1.5pt;border-bottom:solid windowtext 1.0pt;border-right:  solid windowtext 1.0pt;padding:0in 5.4pt 0in 5.4pt'>
                                              <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'><b>
                                              C. Company
                                              </b></p>
                                          </td>
                                          <td width=168 colspan=2 style='width:1.75in;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'>
                                              <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'><b>
                                             `+response.invoice[0].customer_company+`
                                              </b></p>
                                          </td>
                                          <td width=102 style='width:76.5pt;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'>
                                              <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'><b>
                                              ORDER DATE
                                              </b></p>
                                          </td>
                                          <td width=138 colspan=2 style='width:103.5pt;border-top:none;border-left:  none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.5pt;  padding:0in 5.4pt 0in 5.4pt'>
                                              <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'><b>
                                              `+response.invoice[0].invoice_date+`
                                              </b></p>
                                          </td>
                                          <td width=178 colspan=2 rowspan=3 style='width:133.35pt;border-top:none;  border-left:none;border-bottom:solid windowtext 1.5pt;border-right:solid windowtext 1.5pt;  padding:0in 5.4pt 0in 5.4pt'>
                                              
                                              <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'><b><span style='font-size:16.0pt'>
                                              `+response.invoice[0].invoice_barcode1+`
                                              </span></b></p>
                                              <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'><b><span style='font-size:16.0pt'>
                                              `+response.invoice[0].invoice_number+`
                                              </span></b></p>

                                          </td>
                                      </tr>
                                      <tr>
                                          <td width=119 colspan=2 style='width:89.25pt;border-top:none;border-left:  solid windowtext 1.5pt;border-bottom:solid windowtext 1.0pt;border-right:  solid windowtext 1.0pt;padding:0in 5.4pt 0in 5.4pt'>
                                              <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'><b>
                                              اسم المشتري :
                                              </b></p>
                                          </td>
                                          <td width=168 colspan=2 style='width:1.75in;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'>
                                              <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'><b>
                                              `+response.invoice[0].author+`
                                              </b></p>
                                          </td>
                                          <td width=102 style='width:76.5pt;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'>
                                              <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'><b>
                                              Delivery Date
                                              </b></p>
                                          </td>
                                          <td width=138 colspan=2 style='width:103.5pt;border-top:none;border-left:  none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.5pt;  padding:0in 5.4pt 0in 5.4pt'>
                                              <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'><b>
                                             `+response.invoice[0].delivery_time+`
                                              </b></p>
                                          </td>
                                      </tr>
                                      <tr>
                                          <td width=119 colspan=2 style='width:89.25pt;border-top:none;border-left:  solid windowtext 1.5pt;border-bottom:solid windowtext 1.5pt;border-right:  solid windowtext 1.0pt;padding:0in 5.4pt 0in 5.4pt'>
                                              <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'><b>
                                              Customer
                                              </b></p>
                                          </td>
                                          <td width=168 colspan=2 style='width:1.75in;border-top:none;border-left:none;  border-bottom:solid windowtext 1.5pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt'>
                                              <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'><b>
                                              `+response.invoice[0].customer_full_name+`
                                              </b></p>
                                          </td>
                                          <td width=102 style='width:76.5pt;border-top:none;border-left:none;  border-bottom:solid windowtext 1.5pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt'>
                                              <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'><b>
                                              Prepare
                                              </b></p>
                                          </td>
                                          <td width=138 colspan=2 style='width:103.5pt;border-top:none;border-left:  none;border-bottom:solid windowtext 1.5pt;border-right:solid windowtext 1.5pt;  padding:0in 5.4pt 0in 5.4pt'>
                                              <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'><b>
                                              &nbsp;
                                              </b></p>
                                          </td>
                                      </tr>
                                      <tr>
                                          <td width=41 style='width:30.75pt;border:none;border-bottom:solid windowtext 1.5pt;  padding:0in 5.4pt 0in 5.4pt'>
                                              <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                              &nbsp;</p>
                                          </td>
                                          <td width=78 style='width:58.5pt;border:none;border-bottom:solid windowtext 1.5pt;  padding:0in 5.4pt 0in 5.4pt'>
                                              <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>&nbsp;</p>
                                          </td>
                                          <td width=102 style='width:76.5pt;border:none;border-bottom:solid windowtext 1.5pt;  padding:0in 5.4pt 0in 5.4pt'>
                                              <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>&nbsp;</p>
                                          </td>
                                          <td width=66 style='width:49.5pt;border:none;border-bottom:solid windowtext 1.5pt;  padding:0in 5.4pt 0in 5.4pt'>
                                              <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>&nbsp;</p>
                                          </td>
                                          <td width=102 style='width:76.5pt;border:none;border-bottom:solid windowtext 1.5pt;  padding:0in 5.4pt 0in 5.4pt'>
                                              <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>&nbsp;</p>
                                          </td>
                                          <td width=72 style='width:.75in;border:none;border-bottom:solid windowtext 1.5pt;  padding:0in 5.4pt 0in 5.4pt'>
                                              <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>&nbsp;</p>
                                          </td>
                                          <td width=66 style='width:49.5pt;border:none;border-bottom:solid windowtext 1.5pt;  padding:0in 5.4pt 0in 5.4pt'>
                                              <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>&nbsp;</p>
                                          </td>
                                          <td width=72 style='width:.75in;border:none;border-bottom:solid windowtext 1.5pt;  padding:0in 5.4pt 0in 5.4pt'>
                                              <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>&nbsp;</p>
                                          </td>
                                          <td width=106 style='width:79.35pt;border:none;border-bottom:solid windowtext 1.5pt;  padding:0in 5.4pt 0in 5.4pt'>
                                              <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>&nbsp;</p>
                                          </td>
                                      </tr>`;
                        
                        

                        customer_details = ``;



                      attach =  `
                                  <tr>
                                      <td width=41 style='width:30.75pt;border-top:none;border-left:solid windowtext 1.5pt;  border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt'>
                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'><b>
                                          No
                                          </b></p>
                                      </td>
                                      <td width=78 style='width:58.5pt;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'>
                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'><b>
                                          HEIGHT
                                          </b></p>
                                      </td>
                                      <td width=102 style='width:76.5pt;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'>
                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'><b>
                                          WIDTH
                                          </b></p>
                                      </td>
                                      <td width=66 style='width:49.5pt;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'>
                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'><b>
                                          QNTY
                                          </b></p>
                                      </td>
                                      <td width=102 style='width:76.5pt;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'>
                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'><b>
                                          COMMENT
                                          </b></p>
                                      </td>
                                      <td width=72 style='width:.75in;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'>
                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'><b>
                                          MODEL
                                          </b></p>
                                      </td>
                                      <td width=66 style='width:49.5pt;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'>
                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'><b>
                                          COLOR
                                          </b></p>
                                      </td>
                                      <td width=72 style='width:.75in;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'>
                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'><b>
                                          Notes
                                          </b></p>
                                      </td>
                                      <td width=106 style='width:79.35pt;border-top:none;border-left:none;  border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.5pt;  padding:0in 5.4pt 0in 5.4pt'>
                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'><b>
                                          Current Stage
                                          </b></p>
                                      </td>
                                  </tr>`;
                      
                      var total_areas = '';
                      // show sell item details  
                      var total_qty = 0;

                      var is_splited = false;  // to split between tac_isik and wood rows

                      for(var i=0 ; i < response.invoice.length;i++){                        

                          var areas         = '';

                          var itm_H         = '';
                          var itm_W         = '';

                          var m_name        ='';
                          var quty          ='';
                        
                          var m_code        = '';

                          var c_code        = '';
                          var bar_code      = '';
                          var bar_code_img  = '';

                          
                          

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

                            case '0':
                                  var start_stage   = "Not Determined Yet";
                              break;

                            case '1':
                                  var start_stage   = "In Reviewing Stage";
                              break;

                            case '2':
                                  var start_stage   = "CNC Stage";
                              break;
                            case '3':
                                  var start_stage   = "Cleaning Wood Stage";
                              break;
                            case '4':
                                  var start_stage   = "Glue Stage";
                              break;
                            case '5':
                                  var start_stage   = "Check Point Stage";
                              break;
                            case '6':
                                  var start_stage   = "PVC Stage";
                              break;
                            case '7':
                                  var start_stage   = "Control Stage";
                              break;
                            
                            case '8':
                                  var start_stage   = "Packaging Stage";
                              break;
                            
                            case '9':
                                  var start_stage   = "Delivery In Factory";
                              break;
                            
                            case '10':
                                  var start_stage   = "Delivery In Shop";
                              break;

                          }



                          var row_bg_color = ' border: 1px solid black;';

                          if(response.invoice[i].model_color !=''){

                            row_bg_color = `background-color:`+response.invoice[i].model_color+' !important; border: 1px solid black;';
                        
                          }


                         
                          quty              = parseInt(response.invoice[i].sell_item_quantity);
                          m_code            = response.invoice[i].model_code;
                          c_code            = response.invoice[i].product_code_color;
                          bar_code          = response.invoice[i].sell_item_barcode;
                          bar_code_img      = response.invoice[i].item_barcode;



                          total_qty = +total_qty + +(response.invoice[i].sell_item_quantity);

                          if(response.invoice[i].model_type !="TAC" && response.invoice[i].model_type !="ISIK"){
                            areas =  response.invoice[i].sell_item_height_production * response.invoice[i].sell_item_width_production * response.invoice[i].sell_item_quantity / 1000000; 
                            total_areas = +total_areas + +areas; 

                            areas = areas.toFixed(5);


                            itm_H  = response.invoice[i].sell_item_height_production;
                            itm_W  = response.invoice[i].sell_item_width_production;


                            m_name = response.invoice[i].model_name;
                           
                           
                             if(m_name.toLowerCase() =="empty"){

                              areas         = '';
                              
                              itm_H         = '';
                              itm_W         = '';
                              quty          = '';
                              m_code        = '';
                              c_code        = '';
                              bar_code      = '';
                              bar_code_img  = '';

                              total_qty = total_qty - (response.invoice[i].sell_item_quantity);

                             }


                          }else{
                           areas = response.invoice[i].model_type;

                          }

                          if(response.invoice[i].model_type !="TAC" && response.invoice[i].model_type !="ISIK"){
                           


                              attach = attach + `
                                                <tr >
                                                    <td width=41 style='width:30.75pt;border-top:none;border-left:solid windowtext 1.5pt;  border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt'>
                                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                                        `+(i+1)+`
                                                        </p>
                                                    </td>
                                                    <td width=78 style='width:58.5pt;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'>
                                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                                       `+itm_H+`
                                                        </p>
                                                    </td>
                                                    <td width=102 style='width:76.5pt;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'>
                                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                                       `+itm_W+`
                                                        </p>
                                                    </td>
                                                    <td width=66 style='width:49.5pt;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'>
                                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                                        `+quty+`
                                                        </p>
                                                    </td>
                                                    <td width=102 style='width:76.5pt;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'>
                                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                                       `+response.invoice[i].sell_item_comment+`
                                                        </p>
                                                    </td>
                                                    <td style="`+row_bg_color+`" width=72 style='width:.75in;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'>
                                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                                       `+m_code+`
                                                        </p>
                                                    </td>
                                                    <td width=66 style='width:49.5pt;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'>
                                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                                       `+c_code+`
                                                        </p>
                                                    </td>
                                                    <td width=72 style='width:.75in;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'>
                                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                                       `+response.invoice[i].sell_item_notes+`
                                                        </p>
                                                    </td>
                                                    <td width=106 style='width:79.35pt;border-top:none;border-left:none;  border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.5pt;  padding:0in 5.4pt 0in 5.4pt'>
                                                        <!--
                                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                                        `+bar_code_img+`
                                                        </p>
                                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                                        `+bar_code+`
                                                        </p>
                                                        -->
                                                        `+start_stage+`
                                                    </td>
                                                </tr>`;

                          }else{


                            if (is_splited == false){

                            
                                attach_other = attach_other + `

                                              <tr>
                                                  <td width=41 style='width:30.75pt;padding:0in 5.4pt 0in 5.4pt;border-top:solid windowtext 1.5pt'>
                                                      <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>&nbsp;</p>
                                                  </td>
                                                  <td width=78 style='width:58.5pt;padding:0in 5.4pt 0in 5.4pt;border-top:solid windowtext 1.5pt'>
                                                      <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>&nbsp;</p>
                                                  </td>
                                                  <td width=102 style='width:76.5pt;border:none;border-top:solid windowtext 1.5pt;border-bottom:solid windowtext 1.5pt;  padding:0in 5.4pt 0in 5.4pt'>
                                                      <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>&nbsp;</p>
                                                  </td>
                                                  <td width=66 style='width:49.5pt;border:none;border-top:solid windowtext 1.5pt;border-bottom:solid windowtext 1.5pt;  padding:0in 5.4pt 0in 5.4pt'>
                                                      <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>&nbsp;</p>
                                                  </td>
                                                  <td width=102 style='width:76.5pt;padding:0in 5.4pt 0in 5.4pt;border-top:solid windowtext 1.5pt'>
                                                      <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>&nbsp;</p>
                                                  </td>
                                                  <td width=72 style='width:.75in;border:none;border-top:solid windowtext 1.5pt;border-bottom:solid windowtext 1.5pt;  padding:0in 5.4pt 0in 5.4pt'>
                                                      <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>&nbsp;</p>
                                                  </td>
                                                  <td width=66 style='width:49.5pt;border:none;border-top:solid windowtext 1.5pt;border-bottom:solid windowtext 1.5pt;  padding:0in 5.4pt 0in 5.4pt'>
                                                      <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>&nbsp;</p>
                                                  </td>
                                                  <td width=72 style='width:.75in;border:none;border-top:solid windowtext 1.5pt;border-bottom:solid windowtext 1.5pt;  padding:0in 5.4pt 0in 5.4pt'>
                                                      <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>&nbsp;</p>
                                                  </td>
                                                  <td width=106 style='width:79.35pt;border:none;border-top:solid windowtext 1.5pt;border-bottom:solid windowtext 1.5pt;  padding:0in 5.4pt 0in 5.4pt'>
                                                      <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>&nbsp;</p>
                                                  </td>
                                              </tr>

                                `;

                                is_splited = true;

                            }

                            if(response.invoice[i].model_type =="TAC" ){
                                  attach_other = attach_other + `

                                                 <tr>
                                                    <td width=41 style='width:30.75pt;padding:0in 5.4pt 0in 5.4pt'>
                                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>&nbsp;</p>
                                                    </td>
                                                    <td width=78 style='width:58.5pt;border:none;border-right:solid windowtext 1.5pt;  padding:0in 5.4pt 0in 5.4pt'>
                                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>&nbsp;</p>
                                                    </td>
                                                    <td width=102 style='width:76.5pt;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'>
                                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'><b>
                                                        TAC
                                                        </b></p>
                                                    </td>
                                                    <td width=66 style='width:49.5pt;border-top:none;border-left:none;border-bottom:  solid windowtext 1.0pt;border-right:solid windowtext 1.5pt;padding:0in 5.4pt 0in 5.4pt'>
                                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                                        `+parseInt(response.invoice[i].sell_item_quantity)+`
                                                        </p>
                                                    </td>
                                                    <td width=102 style='width:76.5pt;border:none;border-right:solid windowtext 1.5pt;  padding:0in 5.4pt 0in 5.4pt'>
                                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>&nbsp;</p>
                                                    </td>
                                                    <td width=72 style='width:.75in;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'>
                                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                                        `+response.invoice[i].model_code+`
                                                        </p>
                                                    </td>
                                                    <td width=66 style='width:49.5pt;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'>
                                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                                        `+response.invoice[i].product_code_color+`
                                                        </p>
                                                    </td>
                                                    <td width=72 style='width:.75in;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'>
                                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                                        `+response.invoice[i].sell_item_notes+`
                                                        </p>
                                                    </td>
                                                    <td width=106 style='width:79.35pt;border-top:none;border-left:none;  border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.5pt;  padding:0in 5.4pt 0in 5.4pt'>
                                                       <!-- 
                                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                                        `+response.invoice[i].item_barcode+`
                                                        </p>
                                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                                        `+response.invoice[i].sell_item_barcode+`
                                                        </p> -->
                                                        `+start_stage+`
                                                    </td>
                                                </tr>`;
                            }else{

                                  attach_other = attach_other + `

                                                  <tr>
                                                      <td width=41 style='width:30.75pt;padding:0in 5.4pt 0in 5.4pt'>
                                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>&nbsp;</p>
                                                      </td>
                                                      <td width=78 style='width:58.5pt;border:none;border-right:solid windowtext 1.5pt;  padding:0in 5.4pt 0in 5.4pt'>
                                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>&nbsp;</p>
                                                      </td>
                                                      <td width=102 style='width:76.5pt;border-top:none;border-left:none;  border-bottom:solid windowtext 1.5pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt'>
                                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'><b>
                                                          ISIK BANDI
                                                          </b></p>
                                                      </td>
                                                      <td width=66 style='width:49.5pt;border-top:none;border-left:none;border-bottom:  solid windowtext 1.5pt;border-right:solid windowtext 1.5pt;padding:0in 5.4pt 0in 5.4pt'>
                                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                                         `+parseInt(response.invoice[i].sell_item_quantity)+`
                                                          </p>
                                                      </td>
                                                      <td width=102 style='width:76.5pt;border:none;border-right:solid windowtext 1.5pt;  padding:0in 5.4pt 0in 5.4pt'>
                                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>&nbsp;</p>
                                                      </td>
                                                      <td width=72 style='width:.75in;border-top:none;border-left:none;border-bottom:  solid windowtext 1.5pt;border-right:solid windowtext 1.0pt;padding:0in 5.4pt 0in 5.4pt'>
                                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                                          `+response.invoice[i].model_code+`
                                                          </p>
                                                      </td>
                                                      <td width=66 style='width:49.5pt;border-top:none;border-left:none;border-bottom:  solid windowtext 1.5pt;border-right:solid windowtext 1.0pt;padding:0in 5.4pt 0in 5.4pt'>
                                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                                         `+response.invoice[i].product_code_color+`
                                                          </p>
                                                      </td>
                                                      <td width=72 style='width:.75in;border-top:none;border-left:none;border-bottom:  solid windowtext 1.5pt;border-right:solid windowtext 1.0pt;padding:0in 5.4pt 0in 5.4pt'>
                                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                                           `+response.invoice[i].sell_item_notes+`
                                                          </p>
                                                      </td>
                                                      <td width=106 style='width:79.35pt;border-top:none;border-left:none;  border-bottom:solid windowtext 1.5pt;border-right:solid windowtext 1.5pt;  padding:0in 5.4pt 0in 5.4pt'>
                                                          <!--
                                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                                          `+response.invoice[i].item_barcode+`
                                                          </p>
                                                          <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                                          `+response.invoice[i].sell_item_barcode+`
                                                          </p> -->
                                                          `+start_stage+`
                                                      </td>
                                                  </tr>`;

                            }
                          }

                         
                        
                        
                       
                      } // for i

                      if(printing != null){
                        print_attach = `
                                        <script>

                                          setTimeout(function() {
                                            window.print()
                                          }, 2000)
                                          
                                        </script>
                                        `;
                      }else{
                        print_attach = "";
                      }

                     
                      if(total_areas !=''){
                            total_areas = total_areas.toFixed(4);
                      }

                      footers =`

                               <tr>
                                    <td width=41 style='width:30.75pt;padding:0in 5.4pt 0in 5.4pt'>
                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>&nbsp;</p>
                                    </td>
                                    <td width=78 style='width:58.5pt;border:none;border-bottom:solid windowtext 1.5pt;  padding:0in 5.4pt 0in 5.4pt'>
                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>&nbsp;</p>
                                    </td>
                                    <td width=102 style='width:76.5pt;border:none;border-bottom:solid windowtext 1.5pt;  padding:0in 5.4pt 0in 5.4pt'>
                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>&nbsp;</p>
                                    </td>
                                    <td width=66 style='width:49.5pt;border:none;border-bottom:solid windowtext 1.5pt;  padding:0in 5.4pt 0in 5.4pt'>
                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>&nbsp;</p>
                                    </td>
                                    <td width=102 style='width:76.5pt;padding:0in 5.4pt 0in 5.4pt'>
                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>&nbsp;</p>
                                    </td>
                                    <td width=72 style='width:.75in;padding:0in 5.4pt 0in 5.4pt'>
                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>&nbsp;</p>
                                    </td>
                                    <td width=66 style='width:49.5pt;padding:0in 5.4pt 0in 5.4pt'>
                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>&nbsp;</p>
                                    </td>
                                    <td width=72 style='width:.75in;padding:0in 5.4pt 0in 5.4pt'>
                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>&nbsp;</p>
                                    </td>
                                    <td width=106 style='width:79.35pt;padding:0in 5.4pt 0in 5.4pt'>
                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>&nbsp;</p>
                                    </td>
                                </tr>
 
                                <tr>
                                    <td width=41 style='width:30.75pt;border:none;border-right:solid windowtext 1.5pt;  padding:0in 5.4pt 0in 5.4pt'>
                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>&nbsp;</p>
                                    </td>
                                    <td width=180 colspan=2 style='width:135.0pt;border-top:none;border-left:  none;border-bottom:solid windowtext 1.5pt;border-right:solid windowtext 1.0pt;  padding:0in 5.4pt 0in 5.4pt'>
                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'><b>
                                        TOTAL
                                        </b></p>
                                    </td>
                                    <td width=66 style='width:49.5pt;border-top:none;border-left:none;border-bottom:  solid windowtext 1.5pt;border-right:solid windowtext 1.5pt;padding:0in 5.4pt 0in 5.4pt'>
                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                       `+total_qty+`
                                        </p>
                                    </td>
                                    <td width=102 style='width:76.5pt;padding:0in 5.4pt 0in 5.4pt'>
                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>&nbsp;</p>
                                    </td>
                                    <td width=72 style='width:.75in;border:none;border-bottom:solid windowtext 1.5pt;  padding:0in 5.4pt 0in 5.4pt'>
                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'><b>
                                        M<sup>2</sup>
                                        </b></p>
                                    </td>
                                    <td width=244 colspan=3 style='width:182.85pt;border:none;border-bottom:solid windowtext 1.5pt;  padding:0in 5.4pt 0in 5.4pt'>
                                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'>
                                        `+total_areas+`
                                        </p>
                                    </td>
                                </tr>
                            </table>

                        </div>

                        
                    </div>
                    `+print_attach+`

                </body>

                    </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 show_sticker(itm,printing=null,detail_show=null){

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

          $.ajax({
                url : 'models/crul_packaging.php',
                type : 'POST',
                data : {type:'show_stickers', id : itm},
                dataType : 'json',
                success : function(response) {
                    // console.log(response)
                    
                        headers =`

                                  <table class=MsoTableGrid border=0 cellspacing=0 cellpadding=0 width="96%" style='width:96.0%;border-collapse:collapse;border:none'>
                                      <tr style='height:3.5in'>
                                     `;
                        
                        

                      customer_details = ``;



                      attach =  ``;
 
                      var CNT = 1;


                      for(var i=0 ; i < response.invoice.length;i++){                        

                         

                         
                          quty              = (response.invoice[i].packaging);
                         
                          qy                = quty.split(',');
             
                          
                          for(var j=1 ; j <= qy.length;j++){ 

                            qty1          = j +"/"+(qy.length);

                            var cur_qty   = qy[j-1];
                          

                              if(CNT > 2){

                                attach = attach + `</tr><tr style='height:3.5in'>`; // new row of main table
                                CNT =1;

                              }

                              attach = attach + `

                                                  <td width=631 style='width:473.1pt;padding:0in 2.9pt 0in 2.9pt;height:3.5in'>
                                                    <div align=center>
                                                        <table class=MsoTableGrid border=1 cellspacing=0 cellpadding=0 width="98%" style='width:98.0%;border-collapse:collapse;border:none'>
                                                            <tr style='height:.6in'>
                                                                <td width=157 style='width:117.85pt;border:solid windowtext 1.0pt;    border-right:none;padding:0in 5.4pt 0in 5.4pt;height:.6in'>
                                                                    <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;    line-height:normal'>
                                                                    <img width=123 height=82 id="Picture 6" src="image/sys/label_8_4.png">
                                                                    </p>
                                                                </td>
                                                                <td width=327 colspan=2 style='width:245.2pt;border:solid windowtext 1.0pt;    border-left:none;padding:0in 5.4pt 0in 5.4pt;height:.6in'>
                                                                    <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:    .0001pt;text-align:center;line-height:normal'><b><span style='font-size:    24.0pt'>
                                                                    OSCAR MEMBRAN
                                                                    </span></b></p>
                                                                </td>
                                                            </tr>
                                                            <tr style='height:.5in'>
                                                                <td width=291 colspan=2 style='width:217.9pt;border:solid windowtext 1.0pt;    border-top:none;padding:0in 5.4pt 0in 5.4pt;height:.5in'>
                                                                    <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:    .0001pt;text-align:center;line-height:normal'><span style='font-size:18.0pt'>
                                                                   `+response.invoice[0].invoice_number+`
                                                                    </span></p>
                                                                </td>
                                                                <td width=194 style='width:145.15pt;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:.5in'>
                                                                    <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:    .0001pt;text-align:center;line-height:normal'><b><span lang=AR-IQ dir=RTL    style='font-size:24.0pt'>
                                                                    رقم القائمة
                                                                    </span></b></p>
                                                                </td>
                                                            </tr>
                                                            <tr style='height:.5in'>
                                                                <td width=291 colspan=2 style='width:217.9pt;border:solid windowtext 1.0pt;    border-top:none;padding:0in 5.4pt 0in 5.4pt;height:.5in'>
                                                                    <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:    .0001pt;text-align:center;line-height:normal'><span style='font-size:18.0pt'>
                                                                    `+response.invoice[0].customer_company+`
                                                                    </span></p>
                                                                </td>
                                                                <td width=194 style='width:145.15pt;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:.5in'>
                                                                    <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:    .0001pt;text-align:center;line-height:normal'><b><span lang=AR-SA dir=RTL   style='font-size:24.0pt'>
                                                                    اسم الوكيل
                                                                    </span></b></p>
                                                                </td>
                                                            </tr>
                                                            <tr style='height:.5in'>
                                                                <td width=291 colspan=2 style='width:217.9pt;border:solid windowtext 1.0pt;    border-top:none;padding:0in 5.4pt 0in 5.4pt;height:.5in'>
                                                                    <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:    .0001pt;text-align:center;line-height:normal'><span style='font-size:18.0pt'>
                                                                   `+response.invoice[0].customer_full_name+`
                                                                    </span></p>
                                                                </td>
                                                                <td width=194 style='width:145.15pt;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:.5in'>
                                                                    <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:    .0001pt;text-align:center;line-height:normal'><b><span lang=AR-SA dir=RTL    style='font-size:24.0pt'>
                                                                    اسم الزبون
                                                                    </span></b></p>
                                                                </td>
                                                            </tr>
                                                            <tr style='height:.5in'>
                                                                <td width=291 colspan=2 style='width:217.9pt;border:solid windowtext 1.0pt;    border-top:none;padding:0in 5.4pt 0in 5.4pt;height:.5in'>
                                                                    <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:    .0001pt;text-align:center;line-height:normal'><span style='font-size:18.0pt'>
                                                                    `+cur_qty+`
                                                                    </span></p>
                                                                </td>
                                                                <td width=194 style='width:145.15pt;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:.5in'>
                                                                    <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:    .0001pt;text-align:center;line-height:normal'><b><span lang=AR-SA dir=RTL    style='font-size:24.0pt'>
                                                                    عدد الابواب
                                                                    </span></b></p>
                                                                </td>
                                                            </tr>
                                                            <tr style='height:.5in'>
                                                                <td width=291 colspan=2 style='width:217.9pt;border:solid windowtext 1.0pt;    border-top:none;padding:0in 5.4pt 0in 5.4pt;height:.5in'>
                                                                    <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:    .0001pt;text-align:center;line-height:normal'><span style='font-size:18.0pt'>
                                                                    `+qty1+`
                                                                    </span></p>
                                                                </td>
                                                                <td width=194 style='width:145.15pt;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:.5in'>
                                                                    <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:    .0001pt;text-align:center;line-height:normal'><b><span lang=AR-SA dir=RTL    style='font-size:24.0pt'>
                                                                    عدد التغليف
                                                                    </span></b></p>
                                                                </td>
                                                            </tr>
                                                            
                                                        </table>
                                                    </div>
                                                    <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'></p>
                                                </td>`;

                         
                         
                            CNT = +CNT + +1;

                         

                        }  // for j
                        
                       
                      } // for i

                      if(printing != null){
                        print_attach = `
                                        <script>

                                          setTimeout(function() {
                                            window.print()
                                          }, 2000)
                                          
                                        </script>
                                        `;
                      }else{
                        print_attach = "";
                      }

                     
                     

                      footers =`

                              
                                </tr>
 
                                
                            </table>

                        </div>

                       </div> 

                        `+print_attach+`

                     </body>

                    </html>`;

                      

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

          }); // submit ajax


    }

    

   
     function change_delivery_status (id, delivery_status){

       
            $.ajax({
                url: "models/crul_delivery.php",
                type:"POST",
                dataType: "JSON",
                data : {id              :id,
                        delivery_status     :delivery_status,
                        type                :'change_delivery_status'}
            })
            .done(function(res) {
               
                if(res.is_success == true){

                   
                   

                    $(".datatable-column-search-inputs").DataTable().ajax.reload(null, false);
                   
                    
                    noty({
                                    width: 200,
                                    text: Translation(res.data),
                                    type: 'success',
                                    dismissQueue: true,
                                    timeout: 2000,
                                    layout: 'topRight',
                                    callback: {
                                              onShow: function() {},
                                              afterShow: function() {},
                                              onClose: function() {},
                                              afterClose: function() {},
                                              onCloseClick: function() {},
                                            },
                              });

                    // i will reload the page to reset all fields
                    
               
                }else{
                    swal({
                        title: Translation("خطأ"),
                        text: Translation(res.data),
                        confirmButtonColor: "#66BB6A",
                        type: "warning"
                    });
                    //$("#add-form-cont").collapse('hide');
                }

                
               
            })
            .fail(function(err) {
                 swal({
                    title: Translation("خطأ"),
                    text: (err),
                    confirmButtonColor: "#66BB6A",
                    type: "error"
                });
                
                

            })
            .always(function() {
                console.log("complete");
            });
          

        
    }


   

   
  


    function calc_total_invoice_price(){
      
    }

    function calc_payments(){
      
    }
   
 






    


$(document).ready(function() {
  
    $("#recieved_barcode").focus();

    $('#add_form').submit(function(event) {
        event.preventDefault();
        
        var action_typo                   = $("#action_typo").val();  
        var recieved_barcode              = $("#recieved_barcode").val();
        var move_to_shop_barcode          = $("#move_to_shop_barcode").val();
        var delivery_to_customer_barcode  = $("#delivery_to_customer_barcode").val();
        
        
        var Check1 = true;
        
        if(recieved_barcode == '' && move_to_shop_barcode =='' && delivery_to_customer_barcode ==''){
          Check1 = false;
        }
          

        if(Check1 ){
          $("#submit_add_btn").attr('disabled',true);
          
          $.ajax({
                url: "models/crul_delivery.php",
                type:"POST",
                dataType: "JSON",
                data : {move_to_shop_barcode          :move_to_shop_barcode,
                        recieved_barcode              :recieved_barcode,
                        delivery_to_customer_barcode  :delivery_to_customer_barcode,
                        
                        type                          :action_typo}
          })
          .done(function(res) {
             
            if(res.is_success == true){

                $("#add_form")[0].reset();

                if(delivery_to_customer_barcode !=''){
                  $("#delivery_to_customer_barcode").focus();

                }else if(move_to_shop_barcode !=''){
                  $("#move_to_shop_barcode").focus();

                }else{
                  $("#recieved_barcode").focus();

                }


                noty({
                          width: 200,
                          text: Translation(res.data),
                          type: 'success',
                          dismissQueue: true,
                          timeout: 2000,
                          layout: 'topRight',
                          callback: {
                                    onShow: function() {},
                                    afterShow: function() {},
                                    // onClose: function() {location.reload();},
                                    afterClose: function() {},
                                    onCloseClick: function() {},
                                  },
                      });
                $(".datatable-column-search-inputs").DataTable().ajax.reload(null, false);

                // show_invoice(res.invoice_id,curent_stage);

           
            }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) {
              swal({
                  title: Translation("خطأ"),
                  text: (err),
                  confirmButtonColor: "#66BB6A",
                  type: "error"
              });
              $("#submit_add_btn").attr('disabled',false);
          })
          .always(function() {
              console.log("complete");
          });
        }else{
                $("#recieved_barcode").focus();

          noty({
                width: 200,
                text: Translation('الرجاء ادخال BARCODE واحد على الاقل'),
                type: 'error',
                dismissQueue: true,
                timeout: 3000,
                layout: 'topRight',
              });
        }

    });


   
    


});







$(function() {
//var singleSelect = $('.datatable-column-search-inputs').DataTable();
    
  $(".touchspin-basic").TouchSpin({
        min: 1,
        max: 10000000,
        step: 1,
        buttondown_class: "btn btn-xs",
        buttonup_class: "btn btn-xs"
    });

  var start_date = moment().add(5, 'days');

  $('.daterange-single').daterangepicker({ 
        singleDatePicker: true,
        locale: {
            format: 'YYYY-MM-DD'
        }
    });

  $("#delivery_time").daterangepicker({ 
        singleDatePicker: true,
        startDate: start_date,
        locale: {
            format: 'YYYY-MM-DD'
        }
    });

  // Mini
    $('.select-size-xs').select2({
        containerCssClass: 'select-xs'
    });


   // Setting datatable defaults
    $.extend( $.fn.dataTable.defaults, {
        autoWidth: false,
        columnDefs: [{ 
            orderable: false,
            width: '100px',
            targets: [ 5 ]
        }],
        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_ip = getQueryVariable("ip");
   var query_id = getQueryVariable("id");


  

   var table = $('.datatable-column-search-inputs').DataTable({
        
        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 ],
            [  '10', '25', '50', '100' ]
        ],
        "processing": true,
        "serverSide": true,
        "ajax": {
        "url" : "models/crul_delivery.php",
        "data": function(d){
          d.type = "load";
          if(query_id !='not'){
            d.id =query_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": 10,
              "data": null,
              "render": function (data,type,row) {

                      var btns = ``;

                      
                            return  `<ul class='icons-list '>
                                      

                                        
                                        <li class='text-primary-600'>
                                            <a href='#' class='text-orange-400' onclick="show_invoice(`+row[0]+`)" data-popup='tooltip' data-original-title='`+Translation('عرض الطلب')+`'>
                                                <i class='icon-calculator'></i>
                                            </a>
                                        </li>

                                        <li class='text-primary-600'>
                                            <a href='#' class='text-pink-400' onclick="show_invoice(`+row[0]+`,'Print')" data-popup='tooltip' data-original-title='`+Translation('طباعة الوصل')+`'>
                                                <i class='icon-printer4'></i>
                                            </a>
                                        </li>
                                       
                                        <li class='text-primary-600'>
                                            <a  class='text-teal-400' onclick="show_package_sticker_status(`+row[0]+`)" data-popup='tooltip' data-original-title='`+Translation('عرض حالة الحزم')+`'>
                                                <i class='icon-folder-check'></i>
                                            </a>
                                        </li>
                                        
                                        <li class="dropdown">
                                          <a href="#" class="dropdown-toggle" data-toggle="dropdown"  data-original-title='`+Translation('تفاصيل دفوعات الوصل')+` '>
                                            <i class="icon-paperplane"></i>
                                          </a>

                                          <ul class="dropdown-menu dropdown-menu-right">
                                           

                                            

                                            <li>
                                              <a  onclick="change_delivery_status(`+row[0]+`,'9')"  data-original-title='Edit or Remove Invoice Payments'>
                                                <i class='icon-truck text-success'></i>`+Translation('استلمت البضاعة في مخزن المعمل')+` 
                                              </a>
                                            </li>

                                            <li>
                                              <a  onclick="change_delivery_status(`+row[0]+`,'10')"  data-original-title='Edit or Remove Invoice Payments'>
                                                <i class='icon-road text-violet-600'></i>`+Translation('نقل البضاعة الى مخزن الشركة')+` 
                                              </a>
                                            </li>

                                            <li>
                                              <a  onclick="change_delivery_status(`+row[0]+`,'11')"  data-original-title='Edit or Remove Invoice Payments'>
                                                <i class='icon-user-check text-info'></i>`+Translation('سلمت البضاعة الى الزبون  من  المعمل')+` 
                                              </a>
                                            </li>

                                          </ul>
                                        </li>
                                        
                                    </ul>`;
                        }
          },


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


                        // return  `<a onclick="show_invoice(`+row[0]+`)"  data-popup='tooltip' data-original-title='Show Invoice Details'>`+data+`</a>`;
                        return  `<a onclick="show_invoice(`+row[0]+`)"  data-popup='tooltip' data-original-title='`+Translation('عرض الوصل')+`'>`+data+`</a>`;


               },
               "targets": 1
            },

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


                        return  `<a href="index.php?p=orders&id=`+row[12]+`"  data-popup='tooltip' data-original-title='`+Translation('عرض جميع وصولات الزبون')+`'>`+data+`</a>`;


               },
               "targets": 4
            },

            
           

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

            //         return currency_format_display(data);
            //     },
            //     "targets": 5
            // },

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

            //         return currency_format_display(data);
            //     },
            //     "targets": 6
            // },

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

            //         return currency_format_display(data);
            //     },
            //     "targets": 7
            // },
            
            

            {
                "render": function(data, type, row){
                   if(data ==13 ){
                     status=  `<span class="label bg-info btn-block ">`+Translation('سلمت البضاعة الى الزبون من الشركة')+`</span>`;
                   }else if(data ==12 ){
                     status=  `<span class="label bg-info btn-block ">`+Translation('استلمت البضاعة في مخزن الشركة')+`</span>`;
                   }else if(data ==11 ){
                     status=  `<span class="label bg-violet btn-block ">`+Translation('سلمت البضاعة الى الزبون من المصنع')+`</span>`;
                   }else if(data ==10 ){
                     status=  `<span class="label bg-violet btn-block ">`+Translation('نقلت البضاعة الى مخزن الشركة')+`</span>`;
                   }else if(data ==9 ){
                     status=  `<span class="label label-success btn-block ">`+Translation('استلمت البضاعة في مخزن المصنع')+`</span>`;
                   }else if(data ==8){
                     status = '<span class="label bg-teal  btn-block ">'+Translation('Packaging Stage')+'</span>';
                   }else if(data ==7){
                     status = '<span class="label bg-pink  btn-block ">'+Translation('Control Stage')+'</span>';
                   }else if(data ==6){
                     status = '<span class="label bg-purple  btn-block ">'+Translation('PVC Stage')+'</span>';
                   }else if(data ==5){
                     status = '<span class="label bg-orange  btn-block ">'+Translation('Check Point Stage')+'</span>';
                   }else if(data ==4){
                     status = '<span class="label bg-warning  btn-block ">'+Translation('Glue Stage')+'</span>';
                   }else if(data ==3){
                     status = '<span class="label bg-grey  btn-block ">'+Translation('Cleaning Wood Stage')+'</span>';
                   }else if(data ==2){
                     status = '<span class="label bg-info  btn-block ">'+Translation('CNC Stage')+'</span>';
                   }else if(data ==1){
                     status = '<span class="label bg-primary  btn-block ">'+Translation('Reiewed & Editing Stage')+'</span>';
                   }else if(data ==0){
                     status = '<span class="label bg-danger  btn-block ">'+Translation('لم يتم البدء بالانتاج')+'</span>';
                   }

                   // to show if it has original invoice
                   var Typs ='';
                   if(row[13] == 'Return'){
                     Typs = `<a onclick="show_invoice(`+row[14]+`)"  data-popup='tooltip' data-original-title='`+Translation('عرض الوصل')+`'>`+'<span class="label bg-purple-400  ">'+Translation('وصل معاد وتابع للوصل ذو العدد :')+' '+row[14]+'  </span></a>';

                   }
                   return  status + Typs;
                },
                "targets": 8
            }
            

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


            if(   aData[5] == 1 ){ // outcome type
                $(nRow).children().each(function (index, td) {
                    $(this).addClass('alpha-info');
                });
            }
        },
        "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>`);   
         // $("div.datatable-header").append(`<a data-toggle="collapse"
         //                              style="margin-right: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="inv_filter_btn" type="button"
          //                 class="btn bg-teal-400 btn-labeled dropdown-toggle"
          //                 data-toggle="dropdown"><b><i class="icon-filter4">
          //                 </i></b> <span id="inv_filter">`+Translation('فلترة الوصولات')+`</span> <span class="caret"></span></button>
          //                 <ul class="dropdown-menu dropdown-menu-right">
          //                 <li><a href="index.php?p=invoice"><i class="icon-close2 text-teal"></i>`+Translation('ازالة الفلتر')+`  </a></li>
          //                 <li class="divider"></li>
          //                 <li><a href="index.php?p=invoice&ip=2"><i class="icon-coins text-success"></i>`+Translation('الواصل')+` </a></li>
          //                 <li class="divider"></li>
          //                 <li><a href="index.php?p=invoice&ip=1"><i class="icon-bell-check text-info"></i>`+Translation('واصل جزئيا')+`  </a></li>
          //                 <li class="divider"></li>
          //                 <li><a href="index.php?p=invoice&ip=0"><i class="icon-alarm-check text-danger"></i>`+Translation('غير واصل')+` </a></li>
          //                 <li class="divider"></li>
          //                 <li><a href="index.php?p=invoice&ip=4"><i class=" icon-task text-violet"></i>`+Translation('عروض')+`  </a></li>
          //                 <li><a href="index.php?p=invoice&ip=3"><i class="icon-loop text-purple"></i>`+Translation('مسترجع')+`  </a></li>

          //               </ul>
          //             </div>`);
 
          //   invoce_filter_btn_label();

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

            });
            escape_notes();
        }
    });

    
    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

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


});



