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 style="margin:0;">

                                <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 Stage";
                              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="98%" style='width:96.0%;border-collapse:collapse;border:none'>
                                <tr style='height:3.5in'>
                                     `;
                        
                        

                    customer_details = ``;



                      attach =  ``;
 
                      var CNT = 1;

                      var table_per_page = 1;

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

                         

                         
                          Bar              = (response.invoice[i].pack_barcode);
                          Bar_s            = (response.invoice[i].pack_barcode1);
                         
                          // qy                = quty.split(',');
             
                          
                       

                            qty1          = (+i + +1) +"/"+(response.invoice.length);

                            var cur_qty   = response.invoice[i].packaging;
                          
                            var table_height = 'height:10.4cm';

                            if(CNT > 2){

                              if(table_per_page > 4){

                                attach = attach + `</tr></table>
                                                    <table class=MsoTableGrid border=0 cellspacing=0 cellpadding=0 width="98%" style='width:96.0%;page-break-before: always;border-collapse:collapse;border:none'>` ; // new row of main table
                                table_per_page =1;
                                

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

                              }

                              CNT =1;

                            }

                            if(table_per_page > 2){
                              table_height = 'height:10cm';

                            }

                            

                            attach = attach + `

                                                  <td width=631 style='width:473.1pt;padding:0in 2.9pt 0in 2.9pt;height:3.5in'>
                                                    <div align=left>
                                                        <table class=MsoTableGrid border=1 cellspacing=0 cellpadding=0  style='width:14.6cm;${table_height};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:.5in'>
                                                                    <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;    line-height:normal'>
                                                                    <img width=100 height=70 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:.5in'>
                                                                    <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:.35in'>
                                                                <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:.35in'>
                                                                    <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:.35in'>
                                                                    <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'>
                                                                    `+Translation('رقم القائمة')+`
                                                                    </span></b></p>
                                                                </td>
                                                            </tr>
                                                            <tr style='height:.35in'>
                                                                <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:.34in'>
                                                                    <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:.34in'>
                                                                    <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'>
                                                                    `+Translation('اسم الوكيل')+`
                                                                    </span></b></p>
                                                                </td>
                                                            </tr>
                                                            <tr style='height:.35in'>
                                                                <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:.34in'>
                                                                    <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].author+`
                                                                    </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:.34in'>
                                                                    <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'>
                                                                    `+Translation('اسم الزبون')+`
                                                                    </span></b></p>
                                                                </td>
                                                            </tr>
                                                            <tr style='height:.35in'>
                                                                <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:.34in'>
                                                                    <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:.34in'>
                                                                    <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'>
                                                                    `+Translation('عدد الابواب')+`
                                                                    </span></b></p>
                                                                </td>
                                                            </tr>
                                                            <tr style='height:.35in'>
                                                                <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:.34in'>
                                                                    <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:.34in'>
                                                                    <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'>
                                                                    `+Translation('عدد التغليف')+`
                                                                    </span></b></p>
                                                                </td>
                                                            </tr>

                                                            <tr style='height:.35in'>
                                                                <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:.34in'>
                                                                    <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:    .0001pt;text-align:center;line-height:normal'><span style='font-size:18.0pt'>
                                                                    `+Bar+`
                                                                    </span></p>
                                                                    <center> `+Bar_s+` </center>
                                                                </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:.34in'>
                                                                    <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:16.0pt'>
                                                                    `+Translation('Barcode')+`
                                                                    </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;
                            table_per_page  = +table_per_page + +1;

                         

                       
                        
                       
                      } // for i

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

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

                      if((response.invoice.length) % 2 == 1){

                        attach = attach + `<td width=631 style='width:473.1pt;padding:0in 2.9pt 0in 2.9pt;height:3.5in'>
                                                    <div align=left>
                                                        <table class=MsoTableGrid border=1 cellspacing=0 cellpadding=0  style='width:14.6cm;${table_height};border-collapse:collapse;border:none'>
                                                         

                                                        </table>
                                                    </div>
                                                    <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;  text-align:center;line-height:normal'></p>
                                                </td>
                                                `;


                      }
                     
                     

                      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 set_package(itm){

          $('#packaging').tokenfield('destroy');

          $.ajax({
                url : 'models/crul_packaging.php',
                type : 'POST',
                data : {type:'set_package', id : itm},
                dataType : 'json',
                success : function(response) {

                  $("#edit_objid").val(response.invoice[0].invoice_id);
                  $("#packaging").val(response.invoice[0].packaging);
                  $("#Packaging_qty").html(response.invoice[0].sell_item_quantity);
                  
                  $('#packaging').tokenfield();
                     
                },
                complete: function() {
                      $("#edit_form_cont").modal('toggle')
                }

          }); // submit ajax

    }

    function calc_total_invoice_price(){
      
    }

    function calc_payments(){
      
    }
   
 






    


$(document).ready(function() {
  
    $("#packaging").on('change', function(){

      var packaging   = $("#packaging").val();
      var total_qty   = $("#Packaging_qty").html();

      var set_qty     = 0;
      
      var numb        = packaging.split(',');

      for (var i = 0; i < numb.length; i++) {
        set_qty = +set_qty + +numb[i];
      }

      if(set_qty > total_qty){
        swal({
                    title: Translation("خطأ"),
                    text: ("عدد الابواب اصبح اكبر من الكملية الكلية للطلب!!"),
                    confirmButtonColor: "#66BB6A",
                    type: "error"
                });
      }

    });

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

          var catId         = $("#edit_objid").val();

          var packaging     = $("#packaging").val();

          var total_qty     = $("#Packaging_qty").html();

          var set_qty       = 0;
          
          var numb          = packaging.split(',');

          var Check4        = true;
          var Check3        = true;


          for (var i = 0; i < numb.length; i++) {
            set_qty = +set_qty + +numb[i];
          }

          if(set_qty > total_qty){
            Check3            = false;
            swal({
                        title: Translation("خطأ"),
                        text: ("عدد الابواب اصبح اكبر من الكملية الكلية للطلب!!"),
                        confirmButtonColor: "#66BB6A",
                        type: "error"
                    });
          }

          
          var Check4                              = Checks('packaging');
          
        
         
     
         


          if(Check4 && Check3 ){
            $("#submit_edit_btn").attr('disabled',true);
            $.ajax({
                url: "models/crul_packaging.php",
                type:"POST",
                dataType: "JSON",
                data : {
                        invoice_id                :catId,

                       
                        packaging                 :packaging,
                        
                        type                      :'update'}
            })
            .done(function(res) {
               
                  if(res.is_success == true){

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

                    

                    $(".datatable-column-search-inputs").DataTable().ajax.reload(null, false);
                    $("#edit_form_cont").modal('toggle');
                    noty({
                              width: 200,
                              text: Translation(res.data),
                              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');
                }

                $("#submit_edit_btn").attr('disabled',false);
            })
            .fail(function(err) {
                 swal({
                    title: Translation("خطأ"),
                    text: (err),
                    confirmButtonColor: "#66BB6A",
                    type: "error"
                });
                $("#submit_edit_btn").attr('disabled',false);
            })
            .always(function() {
                console.log("complete");
            });
        }else{
          noty({
                    width: 200,
                    text: Translation('الرجاء ادخال عدد التغليف'),
                    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");


    function invoce_filter_btn_label(){

       if(query_ip =='not' ){
         $("#inv_filter").html(Translation('فلترة الوصولات'));
         $("#inv_filter_btn").removeClass();
         $("#inv_filter_btn").addClass('btn bg-teal-400 btn-labeled dropdown-toggle');

       }
       if(query_ip ==2){
         $("#inv_filter").html(Translation('واصل'));
         $("#inv_filter_btn").removeClass();
         $("#inv_filter_btn").addClass('btn bg-success-400 btn-labeled dropdown-toggle');

       }
       if(query_ip ==3){
         $("#inv_filter").html(Translation('مسترجع'));
         $("#inv_filter_btn").removeClass();
         $("#inv_filter_btn").addClass('btn bg-purple-400 btn-labeled dropdown-toggle');

       }
       if(query_ip ==4){
         $("#inv_filter").html(Translation('عروض'));
         $("#inv_filter_btn").removeClass();
         $("#inv_filter_btn").addClass('btn bg-violet-400 btn-labeled dropdown-toggle');

       }
       if(query_ip ==1 ){
         $("#inv_filter").html(Translation('واصل جزئيا'));
         $("#inv_filter_btn").removeClass();
         $("#inv_filter_btn").addClass('btn bg-orange-400 btn-labeled dropdown-toggle');

       }
       

       if(query_ip ==0 ){
         $("#inv_filter").html(Translation('غير واصل'));
         $("#inv_filter_btn").removeClass();
         $("#inv_filter_btn").addClass('btn bg-danger-400 btn-labeled dropdown-toggle');

       }

     }


   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_packaging.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 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-danger-600'>
                                            <a  class='text-danger-400' onclick="set_package(`+row[0]+`)" data-popup='tooltip' data-original-title='`+Translation('Set Packaging Number')+`'>
                                                <i class='icon-pencil'></i>
                                            </a>
                                        </li> 

                                        <li class='text-primary-600'>
                                            <a  class='text-purple-400' onclick="show_sticker(`+row[0]+`)" data-popup='tooltip' data-original-title='`+Translation('طباعة ملصقات التغليف')+`'>
                                                <i class='icon-stack'></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-menu9"></i>
                                          </a>

                                          <ul class="dropdown-menu dropdown-menu-right">
                                            <li>
                                              <a href='#' onclick="change_delivery_status(`+row[0]+`,'0')"  data-original-title='Show Invoice Payments'>
                                                <i class='icon-store2 text-danger-400'></i> `+Translation('لم يتم البدء بالانتاج')+`
                                              </a>
                                            </li>
                                            <li>
                                              <a href='#' onclick="change_delivery_status(`+row[0]+`,'1')"  data-original-title='Add New Payments to this Invoice'>
                                                <i class='icon-hammer-wrench text-primary-600'></i>`+Translation('في مرحلة الانتاج')+` 
                                              </a>
                                            </li>
                                            <li>
                                              <a href='#' onclick="change_delivery_status(`+row[0]+`,'2')"  data-original-title='Edit or Remove Invoice Payments'>
                                                <i class='icon-finish text-orange-600'></i>`+Translation('تم الانتهاء من الانتاج')+` 
                                              </a>
                                            </li>

                                            <li>
                                              <a href='#' onclick="change_delivery_status(`+row[0]+`,'3')"  data-original-title='Edit or Remove Invoice Payments'>
                                                <i class='icon-road text-teal-600'></i>`+Translation('تم تسليم البضاعة في المكتب')+` 
                                              </a>
                                            </li>
                                            <li>
                                              <a href='#' onclick="change_delivery_status(`+row[0]+`,'4')"  data-original-title='Edit or Remove Invoice Payments'>
                                                <i class='icon-truck text-success'></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 ==9 ){
                     status=  `<span class="label label-success btn-block ">`+Translation('Delievry Stage')+`</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'
    });


});



